Skip to content

Commit

Permalink
add support for restarts at end of run
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards4b committed Aug 5, 2021
1 parent e3200a8 commit fae52e9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 29 deletions.
60 changes: 32 additions & 28 deletions src/cpl/nuopc/lnd_comp_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ module lnd_comp_nuopc
character(len=*) , parameter :: continue_run = 'continue'
character(len=*) , parameter :: branch_run = 'branch'

logical :: write_restart_at_endofrun = .false.

character(len=*) , parameter :: u_FILE_u = &
__FILE__

Expand Down Expand Up @@ -356,7 +358,6 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc)
integer :: nsrest ! ctsm restart type
integer :: lbnum ! input to memory diagnostic
integer :: shrlogunit ! original log unit
type(bounds_type) :: bounds ! bounds
integer :: n, ni, nj ! Indices
character(len=CL) :: cvalue ! config data
character(len=CL) :: meshfile_mask ! filename of mesh file with land mask
Expand All @@ -369,12 +370,14 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc)
integer :: scol_mask ! single-column mask
real(r8) :: scol_spval ! single-column special value to indicate it isn't set
character(len=CL) :: single_column_lnd_domainfile ! domain filename to use for single-column mode (i.e. SCAM)
type(bounds_type) :: bounds ! bounds
type(ESMF_Field) :: lfield ! Land field read in
character(CL) ,pointer :: lfieldnamelist(:) => null() ! Land field namelist item sent with land field
integer :: fieldCount ! Number of fields on export state
integer :: rank ! Rank of field (1D or 2D)
real(r8), pointer :: fldptr1d(:) ! 1D field pointer
real(r8), pointer :: fldptr2d(:,:) ! 2D field pointer
logical :: isPresent, isSet
character(len=CL) :: model_version ! Model version
character(len=CL) :: hostname ! hostname of machine running on
character(len=CL) :: username ! user running the model
Expand Down Expand Up @@ -563,6 +566,12 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc)
! Set model clock in lnd_comp_shr
model_clock = clock

call NUOPC_CompAttributeGet(gcomp, name="write_restart_at_endofrun", value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
if (trim(cvalue) .eq. '.true.') write_restart_at_endofrun = .true.
end if
print *,__FILE__,__LINE__,write_restart_at_endofrun
! ---------------------
! Initialize first phase of ctsm
! ---------------------
Expand Down Expand Up @@ -814,22 +823,6 @@ subroutine ModelAdvance(gcomp, rc)
end if
call update_rad_dtime(doalb)

!--------------------------------
! Determine if time to write restart
!--------------------------------

call ESMF_ClockGetAlarm(clock, alarmname='alarm_restart', alarm=alarm, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

if (ESMF_AlarmIsRinging(alarm, rc=rc)) then
if (ChkErr(rc,__LINE__,u_FILE_u)) return
rstwr = .true.
call ESMF_AlarmRingerOff( alarm, rc=rc )
if (ChkErr(rc,__LINE__,u_FILE_u)) return
else
rstwr = .false.
endif

!--------------------------------
! Determine if time to stop
!--------------------------------
Expand All @@ -846,6 +839,25 @@ subroutine ModelAdvance(gcomp, rc)
nlend = .false.
endif

!--------------------------------
! Determine if time to write restart
!--------------------------------
rstwr = .false.
if (nlend .and. write_restart_at_endofrun) then
rstwr = .true.
else
call ESMF_ClockGetAlarm(clock, alarmname='alarm_restart', alarm=alarm, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (ESMF_AlarmIsCreated(alarm, rc=rc)) then
if (ESMF_AlarmIsRinging(alarm, rc=rc)) then
if (ChkErr(rc,__LINE__,u_FILE_u)) return
rstwr = .true.
call ESMF_AlarmRingerOff( alarm, rc=rc )
if (ChkErr(rc,__LINE__,u_FILE_u)) return
endif
endif
end if

!--------------------------------
! Run CTSM
!--------------------------------
Expand Down Expand Up @@ -966,7 +978,6 @@ subroutine ModelSetRunClock(gcomp, rc)
character(len=256) :: stop_option ! Stop option units
integer :: stop_n ! Number until stop interval
integer :: stop_ymd ! Stop date (YYYYMMDD)
integer :: stop_tod ! Stop time of day (seconds)
type(ESMF_ALARM) :: stop_alarm
character(len=128) :: name
integer :: alarmcount
Expand Down Expand Up @@ -1005,7 +1016,7 @@ subroutine ModelSetRunClock(gcomp, rc)

call ESMF_GridCompGet(gcomp, name=name, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_LogWrite(subname//'setting alarms for ' // trim(name), ESMF_LOGMSG_INFO)
call ESMF_LogWrite(subname//'setting alarms for' // trim(name), ESMF_LOGMSG_INFO)

!----------------
! Restart alarm
Expand Down Expand Up @@ -1045,17 +1056,10 @@ subroutine ModelSetRunClock(gcomp, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) stop_ymd

call NUOPC_CompAttributeGet(gcomp, name="stop_tod", value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) stop_tod

call alarmInit(mclock, &
alarm = stop_alarm, &
option = stop_option, &
call alarmInit(mclock, stop_alarm, stop_option, &
opt_n = stop_n, &
opt_ymd = stop_ymd, &
opt_tod = stop_tod, &
RefTime = mcurrTime, &
RefTime = mcurrTime, &
alarmname = 'alarm_stop', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

Expand Down
5 changes: 4 additions & 1 deletion tools/contrib/neon/neon_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,10 @@ def set_ref_case(self, case):
if not os.path.isdir(os.path.join(rundir, "inputdata")) and os.path.isdir(os.path.join(refrundir,"inputdata")):
symlink_force(os.path.join(refrundir,"inputdata"),os.path.join(rundir,"inputdata"))
case.set_value("RUN_REFDATE", refdate)
case.set_value("RUN_STARTDATE", refdate)
if case_root.endswith(".postad"):
case.set_value("RUN_STARTDATE", refdate)
else:
case.set_value("RUN_STARTDATE", "{yr:04d}-{mo:02d}-01".format(yr=self.start_year, mo=self.start_month))


def modify_user_nl(self, case_root, run_type):
Expand Down

0 comments on commit fae52e9

Please sign in to comment.