LCOV - code coverage report
Current view: | top level - dynamics/se/dycore - se_dyn_time_mod.F90 (source / functions) |  |  | Hit | Total | Coverage
Test: | coverage.info |  | Lines: | 23 | 50 | 46.0 %
Date: | 2024-12-17 22:39:59 |  | Functions: | 4 | 7 | 57.1 %

              Line data    Source code
           1             : module se_dyn_time_mod
           2             :   !------------------
           3             :   use shr_kind_mod,   only: r8=>shr_kind_r8
           4             :   !------------------
           5             :   implicit none
           6             :   integer,public                :: nsplit=1
           7             :   integer,public                :: nsplit_baseline=-1
           8             :   integer,public                :: rsplit_baseline=-1
           9             :   integer,public                :: nmax          ! Max number of timesteps
          10             :   integer,public                :: nEndStep      ! Number of End Step
          11             :   integer,public                :: ndays         ! Max number of days
          12             :
          13             :   real (kind=r8)           , public :: tstep         ! Dynamics timestep
          14             :   real (kind=r8)           , public :: tevolve       ! time evolved since start of dynamics (end of physics)
          15             :   real (kind=r8)           , public :: phys_tscale=0 ! Physics time scale
          16             :   real (kind=r8)           , public :: dt_phys = -900! physics time-step (only used in standalone HOMME)
          17             :                                                  ! if negative no forcing (see prim_main)
          18             :
          19             :   ! smooth now in namelist
          20             :   integer, parameter :: ptimelevels = 3                           ! number of time levels in the dycore
          21             :
          22             :   type, public :: TimeLevel_t
          23             :      integer nm1      ! relative time level n-1
          24             :      integer n0       ! relative time level n
          25             :      integer np1      ! relative time level n+1
          26             :      integer nstep    ! time level since simulation start
          27             :      integer nstep0   ! timelevel of first complete leapfrog timestep
          28             :   end type TimeLevel_t
          29             :
          30             :   ! Methods
          31             :   public :: Time_at
          32             :   public :: TimeLevel_update
          33             :   public :: TimeLevel_init
          34             :   public :: TimeLevel_Qdp
          35             :
          36             :   interface TimeLevel_init
          37             :      module procedure TimeLevel_init_default
          38             :      module procedure TimeLevel_init_specific
          39             :      module procedure TimeLevel_init_copy
          40             :   end interface
          41             :
          42             : contains
          43             :
          44           4 :   function Time_at(nstep) result(tat)
          45             :     integer, intent(in) :: nstep
          46             :     real (kind=r8) :: tat
          47           4 :     tat = nstep*tstep
          48           4 :   end function Time_at
          49             :
          50        1536 :   subroutine TimeLevel_init_default(tl)
          51             :     type (TimeLevel_t), intent(out) :: tl
          52        1536 :     tl%nm1   = 1
          53        1536 :     tl%n0    = 2
          54        1536 :     tl%np1   = 3
          55        1536 :     tl%nstep = 0
          56        1536 :     tl%nstep0 = 2
          57        1536 :   end subroutine TimeLevel_init_default
          58             :
          59           0 :   subroutine TimeLevel_init_copy(tl, tin)
          60             :     type (TimeLevel_t), intent(in) :: tin
          61             :     type (TimeLevel_t), intent(out) :: tl
          62           0 :     tl%nm1   = tin%nm1
          63           0 :     tl%n0    = tin%n0
          64           0 :     tl%np1   = tin%np1
          65           0 :     tl%nstep = tin%nstep
          66           0 :     tl%nstep0= tin%nstep0
          67           0 :   end subroutine TimeLevel_init_copy
          68             :
          69           0 :   subroutine TimeLevel_init_specific(tl,n0,n1,n2,nstep)
          70             :     type (TimeLevel_t) :: tl
          71             :     integer, intent(in) :: n0,n1,n2,nstep
          72           0 :     tl%nm1= n0
          73           0 :     tl%n0 = n1
          74           0 :     tl%np1= n2
          75           0 :     tl%nstep= nstep
          76           0 :   end subroutine TimeLevel_init_specific
          77             :
          78             :
          79             :   !this subroutine returns the proper
          80             :   !locations for nm1 and n0 for Qdp - because
          81             :   !it only has 2 levels for storage
          82     6659328 :   subroutine TimeLevel_Qdp(tl, qsplit, n0, np1)
          83             :     use dimensions_mod, only: use_cslam
          84             :     type (TimeLevel_t) :: tl
          85             :     integer, intent(in) :: qsplit
          86             :     integer, intent(inout) :: n0
          87             :     integer, intent(inout), optional :: np1
          88             :
          89             :     integer :: i_temp
          90             :
          91     6659328 :     if (use_cslam) then
          92     6659328 :        n0 = 1
          93     6659328 :        if (present(np1)) np1 = 1
          94             :     else
          95             :
          96           0 :        i_temp = tl%nstep/qsplit
          97             :
          98           0 :        if (mod(i_temp,2)  ==0) then
          99           0 :           n0 = 1
         100           0 :           if (present(np1)) then
         101           0 :              np1 = 2
         102             :           endif
         103             :        else
         104           0 :           n0 = 2
         105           0 :           if (present(np1)) then
         106           0 :              np1 = 1
         107             :           end if
         108             :        endif
         109             :     !print * ,'nstep = ', tl%nstep, 'qsplit= ', qsplit, 'i_temp = ', i_temp, 'n0 = ', n0
         110             :     endif
         111     6659328 :   end subroutine TimeLevel_Qdp
         112             :
         113     2216448 :   subroutine TimeLevel_update(tl,uptype)
         114             :     type (TimeLevel_t) :: tl
         115             :     character(len=*)   :: uptype
         116             :
         117             :     ! Local Variable
         118             :
         119             :     integer :: ntmp
         120             : !$OMP BARRIER
         121             : !$OMP MASTER
         122     2216448 :     if (uptype == "leapfrog") then
         123     2216448 :        ntmp    = tl%np1
         124     2216448 :        tl%np1  = tl%nm1
         125     2216448 :        tl%nm1  = tl%n0
         126     2216448 :        tl%n0   = ntmp
         127           0 :     else if (uptype == "forward") then
         128           0 :        ntmp    = tl%np1
         129           0 :        tl%np1  = tl%n0
         130           0 :        tl%n0   = ntmp
         131             :     else
         132           0 :        print *,'WARNING: TimeLevel_update called wint invalid uptype=',uptype
         133             :     end if
         134             :
         135     2216448 :     tl%nstep = tl%nstep+1
         136             : !$OMP END MASTER
         137             : !$OMP BARRIER
         138     2216448 :   end subroutine TimeLevel_update
         139             :
         140           0 : end module se_dyn_time_mod

Generated by: LCOV version 1.14