Skip to content

Commit 369d5d6

Browse files
Merge pull request #21 from alperaltuntas/dev/ncar
Fixed clock and timing
2 parents 1bca79b + 06a30ab commit 369d5d6

1 file changed

Lines changed: 39 additions & 23 deletions

File tree

config_src/mct_driver/ocn_comp_mct.F90

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module ocn_comp_mct
44
! This file is part of MOM6. See LICENSE.md for the license.
55

66
! mct modules
7-
use ESMF, only: ESMF_clock, ESMF_time, ESMF_timeInterval
7+
use ESMF, only: ESMF_clock, ESMF_time, ESMF_timeInterval, ESMF_TimeInc
88
use ESMF, only: ESMF_ClockGet, ESMF_TimeGet, ESMF_TimeIntervalGet
99
use seq_cdata_mod, only: seq_cdata
1010
use seq_cdata_mod, only: seq_cdata_setptrs
@@ -73,9 +73,10 @@ subroutine ocn_init_mct( EClock, cdata_o, x2o_o, o2x_o, NLFilename )
7373

7474
! local variables
7575
type(time_type) :: time_init !< Start time of coupled model's calendar
76-
type(time_type) :: time_in !< Start time for ocean model at initialization
76+
type(time_type) :: time_in !< Time at the beginning of the first ocn coupling interval
7777
type(ESMF_time) :: current_time !< Current time
78-
type(ESMF_timeInterval) :: time_interval !< Time interval
78+
type(ESMF_time) :: time_in_ESMF !< Time after first ocean coupling interval (of type ESMF_time)
79+
type(ESMF_timeInterval) :: ocn_cpl_interval !< Ocean coupling interval
7980
integer :: year, month, day, hour, minute, seconds, seconds_n, seconds_d, rc
8081
character(len=384) :: runid !< Run ID
8182
character(len=384) :: runtype !< Run type
@@ -95,8 +96,8 @@ subroutine ocn_init_mct( EClock, cdata_o, x2o_o, o2x_o, NLFilename )
9596
type(mct_gGrid) :: MOM_MCT_dom3d !< for 3d streams, local
9697

9798
! time management
98-
integer :: ocn_cpl_dt
99-
real (kind=8) :: mom_cpl_dt
99+
integer :: ocn_cpl_dt !< one ocn coupling interval in seconds. (to be received from cesm)
100+
real (kind=8) :: mom_cpl_dt !< one ocn coupling interval in seconds. (internal)
100101
real (kind=8), parameter :: &
101102
seconds_in_minute = 60.0d0, &
102103
seconds_in_hour = 3600.0d0, &
@@ -113,7 +114,7 @@ subroutine ocn_init_mct( EClock, cdata_o, x2o_o, o2x_o, NLFilename )
113114
integer :: km=1 !< Number of vertical levels
114115
integer :: nx_block=0, ny_block=0 !< Size of block domain in x,y dir including ghost cells
115116
integer :: max_blocks_clinic=0 !< Max. number of blocks per processor in each distribution
116-
integer :: ncouple_per_day = 48
117+
integer :: ncouple_per_day
117118
logical :: lsend_precip_fact !< If T,send precip_fact to cpl for use in fw balance
118119
!! (partially-coupled option)
119120
character(len=128) :: err_msg !< Error message
@@ -145,14 +146,26 @@ subroutine ocn_init_mct( EClock, cdata_o, x2o_o, o2x_o, NLFilename )
145146
inst_index = seq_comm_inst(MOM_MCT_ID)
146147
inst_suffix = seq_comm_suffix(MOM_MCT_ID)
147148

148-
! Initialize MOM6
149149
call t_startf('MOM_init')
150+
151+
! Initialize MOM6 comm
150152
call MOM_infra_init(mpicom_ocn)
151-
call ESMF_ClockGet(EClock, currTime=current_time, rc=rc)
152-
call ESMF_TimeGet(current_time, yy=year, mm=month, dd=day, h=hour, m=minute, s=seconds, rc=rc)
153+
153154
call set_calendar_type(NOLEAP) !TODO: confirm this
154155

156+
! Get the ESMF clock instance (assigned by CESM for MOM6)
157+
call ESMF_ClockGet(EClock, currTime=current_time, rc=rc)
158+
159+
! Get the initial CESM time
160+
call ESMF_TimeGet(current_time, yy=year, mm=month, dd=day, h=hour, m=minute, s=seconds, rc=rc)
155161
time_init = set_date(year, month, day, hour, minute, seconds, err_msg=err_msg)
162+
163+
! Compute time_in: time at the beginning of the first ocn coupling interval
164+
! (In CESM, ocean component is lagged by one ocean coupling interval, so:
165+
! time_in = time_init + ocn_cpl_interval )
166+
call ESMF_ClockGet(EClock, TimeStep=ocn_cpl_interval, rc=rc)
167+
time_in_ESMF = ESMF_TimeInc(current_time, ocn_cpl_interval)
168+
call ESMF_TimeGet(time_in_ESMF, yy=year, mm=month, dd=day, h=hour, m=minute, s=seconds, rc=rc)
156169
time_in = set_date(year, month, day, hour, minute, seconds, err_msg=err_msg)
157170

158171
! Debugging clocks
@@ -167,8 +180,8 @@ subroutine ocn_init_mct( EClock, cdata_o, x2o_o, o2x_o, NLFilename )
167180
call ESMF_ClockGet(EClock, PrevTime=current_time, rc=rc)
168181
call ESMF_TimeGet(current_time, yy=year, mm=month, dd=day, h=hour, m=minute, s=seconds, rc=rc)
169182
write(6,*) 'ocn_init_mct, previous time: y,m,d-',year,month,day,'h,m,s=',hour,minute,seconds
170-
call ESMF_ClockGet(EClock, TimeStep=time_interval, rc=rc)
171-
call ESMF_TimeIntervalGet(time_interval, yy=year, mm=month, d=day, s=seconds, sn=seconds_n, sd=seconds_d, rc=rc)
183+
call ESMF_ClockGet(EClock, TimeStep=ocn_cpl_interval, rc=rc)
184+
call ESMF_TimeIntervalGet(ocn_cpl_interval, yy=year, mm=month, d=day, s=seconds, sn=seconds_n, sd=seconds_d, rc=rc)
172185
write(6,*) 'ocn_init_mct, time step: y,m,d-',year,month,day,'s,sn,sd=',seconds,seconds_n,seconds_d
173186
endif
174187

@@ -235,8 +248,9 @@ subroutine ocn_init_mct( EClock, cdata_o, x2o_o, o2x_o, NLFilename )
235248
call seq_timemgr_EClockGetData(EClock, dtime=ocn_cpl_dt)
236249

237250
! \todo Need interface to get dt from MOM6
251+
ncouple_per_day = seconds_in_day / ocn_cpl_dt
238252
mom_cpl_dt = seconds_in_day / ncouple_per_day
239-
if (mom_cpl_dt /= ocn_cpl_dt) then
253+
if (mom_cpl_dt /= ocn_cpl_dt) then ! \todo this check is trivial for now.
240254
write(*,*) 'ERROR pop_cpl_dt and ocn_cpl_dt must be identical'
241255
call exit(0)
242256
end if
@@ -303,21 +317,24 @@ subroutine ocn_run_mct( EClock, cdata_o, x2o_o, o2x_o)
303317
type(mct_aVect), intent(inout) :: x2o_o !< Fluxes from coupler to ocean, computed by ocean
304318
type(mct_aVect), intent(inout) :: o2x_o !< Fluxes from ocean to coupler, computed by ocean
305319
! Local variables
306-
type(ESMF_time) :: current_time
307-
type(ESMF_timeInterval) :: time_interval
320+
type(ESMF_time) :: current_time !< Time to be reached at the end of ocean cpl interval
321+
type(ESMF_time) :: time_start_ESMF !< Time at the start of the coupling interval
322+
type(ESMF_timeInterval) :: ocn_cpl_interval !< The length of one ocean coupling interval
308323
integer :: year, month, day, hour, minute, seconds, seconds_n, seconds_d, rc
309324
logical :: write_restart_at_eod
310325
type(time_type) :: time_start !< Start of coupled time interval to pass to MOM6
311326
type(time_type) :: coupling_timestep !< Coupled time interval to pass to MOM6
312327
character(len=128) :: err_msg
313328

314-
! Translate the current time (start of coupling interval)
315-
call ESMF_ClockGet(EClock, currTime=current_time, rc=rc)
316-
call ESMF_TimeGet(current_time, yy=year, mm=month, dd=day, h=hour, m=minute, s=seconds, rc=rc)
329+
! Compute the time at the start of this coupling interval
330+
call ESMF_ClockGet(EClock, PrevTime=time_start_ESMF, rc=rc)
331+
call ESMF_TimeGet(time_start_ESMF, yy=year, mm=month, dd=day, h=hour, m=minute, s=seconds, rc=rc)
317332
time_start = set_date(year, month, day, hour, minute, seconds, err_msg=err_msg)
318333

319334
! Debugging clocks
320335
if (debug .and. is_root_pe()) then
336+
call ESMF_ClockGet(EClock, CurrTime=current_time, rc=rc)
337+
call ESMF_TimeGet(current_time, yy=year, mm=month, dd=day, h=hour, m=minute, s=seconds, rc=rc)
321338
write(6,*) 'ocn_run_mct, current time: y,m,d-',year,month,day,'h,m,s=',hour,minute,seconds
322339
call ESMF_ClockGet(EClock, StartTime=current_time, rc=rc)
323340
call ESMF_TimeGet(current_time, yy=year, mm=month, dd=day, h=hour, m=minute, s=seconds, rc=rc)
@@ -328,15 +345,14 @@ subroutine ocn_run_mct( EClock, cdata_o, x2o_o, o2x_o)
328345
call ESMF_ClockGet(EClock, PrevTime=current_time, rc=rc)
329346
call ESMF_TimeGet(current_time, yy=year, mm=month, dd=day, h=hour, m=minute, s=seconds, rc=rc)
330347
write(6,*) 'ocn_run_mct, previous time: y,m,d-',year,month,day,'h,m,s=',hour,minute,seconds
348+
call ESMF_ClockGet(EClock, TimeStep=ocn_cpl_interval, rc=rc)
349+
call ESMF_TimeIntervalGet(ocn_cpl_interval, yy=year, mm=month, d=day, s=seconds, sn=seconds_n, sd=seconds_d, rc=rc)
350+
write(6,*) 'ocn_init_mct, time step: y,m,d-',year,month,day,'s,sn,sd=',seconds,seconds_n,seconds_d
331351
endif
332352

333353
! Translate the coupling time interval
334-
call ESMF_ClockGet(EClock, TimeStep=time_interval, rc=rc)
335-
call ESMF_TimeIntervalGet(time_interval, yy=year, mm=month, d=day, s=seconds, sn=seconds_n, sd=seconds_d, rc=rc)
336-
time_start = set_date(year, month, day, 0, 0, seconds, err_msg=err_msg)
337-
if (debug .and. is_root_pe()) then
338-
write(6,*) 'ocn_run_mct, time step: y,m,d-',year,month,day,'s,sn,sd=',seconds,seconds_n,seconds_d
339-
endif
354+
call ESMF_ClockGet(EClock, TimeStep=ocn_cpl_interval, rc=rc)
355+
call ESMF_TimeIntervalGet(ocn_cpl_interval, yy=year, mm=month, d=day, s=seconds, sn=seconds_n, sd=seconds_d, rc=rc)
340356
coupling_timestep = set_time(seconds, days=day, err_msg=err_msg)
341357

342358
! set (actually, get from mct) the cdata pointers:

0 commit comments

Comments
 (0)