Skip to content

Commit a728cea

Browse files
committed
allow restarts to be set on non-interval hours
- add restart_fh config variable and define restartfhtimes to enable restarts on non-interval hours - write info to stdout for documenting when additional restarts will or will not be written
1 parent a36cb73 commit a728cea

File tree

1 file changed

+71
-6
lines changed

1 file changed

+71
-6
lines changed

config_src/drivers/nuopc_cap/mom_cap.F90

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ module MOM_cap_mod
153153
character(len=16) :: inst_suffix = ''
154154
real(8) :: timere
155155

156+
type(ESMF_Time), allocatable :: restartFhTimes(:)
157+
156158
contains
157159

158160
!> NUOPC SetService method is the only public entry point.
@@ -378,6 +380,7 @@ subroutine InitializeP0(gcomp, importState, exportState, clock, rc)
378380
geomtype = ESMF_GEOMTYPE_GRID
379381
endif
380382

383+
381384
end subroutine
382385

383386
!> Called by NUOPC to advertise import and export fields. "Advertise"
@@ -613,7 +616,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
613616
open(newunit=readunit, file=rpointer_filename, form='formatted', status='old', iostat=iostat)
614617
if (iostat /= 0) then
615618
call ESMF_LogSetError(ESMF_RC_FILE_OPEN, msg=subname//' ERROR opening '//rpointer_filename, &
616-
line=__LINE__, file=u_FILE_u, rcToReturn=rc)
619+
line=__LINE__, file=u_FILE_u, rcToReturn=rc)
617620
return
618621
endif
619622
do
@@ -1534,6 +1537,8 @@ subroutine ModelAdvance(gcomp, rc)
15341537
character(len=:), allocatable :: rpointer_filename
15351538
integer :: num_rest_files
15361539
real(8) :: MPI_Wtime, timers
1540+
logical :: write_restart
1541+
logical :: write_restartfh
15371542

15381543
rc = ESMF_SUCCESS
15391544
if(profile_memory) call ESMF_VMLogMemInfo("Entering MOM Model_ADVANCE: ")
@@ -1685,13 +1690,26 @@ subroutine ModelAdvance(gcomp, rc)
16851690
call ESMF_ClockGetAlarm(clock, alarmname='restart_alarm', alarm=restart_alarm, rc=rc)
16861691
if (ChkErr(rc,__LINE__,u_FILE_u)) return
16871692

1693+
write_restartfh = .false.
1694+
! check if next time is == to any restartfhtime
1695+
if (allocated(RestartFhTimes)) then
1696+
do n = 1,size(RestartFhTimes)
1697+
call ESMF_ClockGetNextTime(clock, MyTime, rc=rc)
1698+
if (ChkErr(rc,__LINE__,u_FILE_u)) return
1699+
if (MyTime == RestartFhTimes(n)) write_restartfh = .true.
1700+
end do
1701+
end if
1702+
1703+
write_restart = .false.
16881704
if (ESMF_AlarmIsRinging(restart_alarm, rc=rc)) then
16891705
if (ChkErr(rc,__LINE__,u_FILE_u)) return
1690-
1706+
write_restart = .true.
16911707
! turn off the alarm
16921708
call ESMF_AlarmRingerOff(restart_alarm, rc=rc )
16931709
if (ChkErr(rc,__LINE__,u_FILE_u)) return
1710+
end if
16941711

1712+
if (write_restart .or. write_restartfh) then
16951713
! determine restart filename
16961714
call ESMF_ClockGetNextTime(clock, MyTime, rc=rc)
16971715
if (ChkErr(rc,__LINE__,u_FILE_u)) return
@@ -1714,7 +1732,7 @@ subroutine ModelAdvance(gcomp, rc)
17141732
! write restart file(s)
17151733
call ocean_model_restart(ocean_state, restartname=restartname, num_rest_files=num_rest_files)
17161734
if (localPet == 0) then
1717-
! Write name of restart file in the rpointer file - this is currently hard-coded for the ocean
1735+
! Write name of restart file in the rpointer file - this is currently hard-coded for the ocean
17181736
open(newunit=writeunit, file=rpointer_filename, form='formatted', status='unknown', iostat=iostat)
17191737
if (iostat /= 0) then
17201738
call ESMF_LogSetError(ESMF_RC_FILE_OPEN, &
@@ -1791,25 +1809,34 @@ end subroutine ModelAdvance
17911809

17921810

17931811
subroutine ModelSetRunClock(gcomp, rc)
1812+
1813+
use ESMF, only : ESMF_TimeIntervalSet
1814+
17941815
type(ESMF_GridComp) :: gcomp
17951816
integer, intent(out) :: rc
17961817

17971818
! local variables
1819+
type(ESMF_VM) :: vm
17981820
type(ESMF_Clock) :: mclock, dclock
17991821
type(ESMF_Time) :: mcurrtime, dcurrtime
18001822
type(ESMF_Time) :: mstoptime, dstoptime
18011823
type(ESMF_TimeInterval) :: mtimestep, dtimestep
1824+
type(ESMF_TimeInterval) :: fhInterval
18021825
character(len=128) :: mtimestring, dtimestring
1826+
character(len=256) :: timestr
18031827
character(len=256) :: cvalue
18041828
character(len=256) :: restart_option ! Restart option units
18051829
integer :: restart_n ! Number until restart interval
18061830
integer :: restart_ymd ! Restart date (YYYYMMDD)
1831+
integer :: dt_cpl ! coupling timestep
18071832
type(ESMF_Alarm) :: restart_alarm
18081833
type(ESMF_Alarm) :: stop_alarm
18091834
logical :: isPresent, isSet
18101835
logical :: first_time = .true.
1811-
character(len=*),parameter :: subname='MOM_cap:(ModelSetRunClock) '
1812-
character(len=256) :: timestr
1836+
integer :: localPet
1837+
integer :: n, nfh
1838+
integer, allocatable :: restart_fh(:)
1839+
character(len=*),parameter :: subname='(MOM_cap:ModelSetRunClock) '
18131840
!--------------------------------
18141841

18151842
rc = ESMF_SUCCESS
@@ -1825,6 +1852,11 @@ subroutine ModelSetRunClock(gcomp, rc)
18251852
call ESMF_ClockGet(mclock, currTime=mcurrtime, timeStep=mtimestep, rc=rc)
18261853
if (ChkErr(rc,__LINE__,u_FILE_u)) return
18271854

1855+
call ESMF_GridCompGet(gcomp, vm=vm, rc=rc)
1856+
if (ChkErr(rc,__LINE__,u_FILE_u)) return
1857+
call ESMF_VMGet(vm, localPet=localPet, rc=rc)
1858+
if (ChkErr(rc,__LINE__,u_FILE_u)) return
1859+
18281860
!--------------------------------
18291861
! check that the current time in the model and driver are the same
18301862
!--------------------------------
@@ -1948,8 +1980,41 @@ subroutine ModelSetRunClock(gcomp, rc)
19481980
call ESMF_TimeGet(dstoptime, timestring=timestr, rc=rc)
19491981
call ESMF_LogWrite("Stop Alarm will ring at : "//trim(timestr), ESMF_LOGMSG_INFO)
19501982

1951-
first_time = .false.
1983+
! set up Times to write non-interval restarts
1984+
call NUOPC_CompAttributeGet(gcomp, name='restart_fh', isPresent=isPresent, isSet=isSet, rc=rc)
1985+
if (ChkErr(rc,__LINE__,u_FILE_u)) return
1986+
if (isPresent .and. isSet) then
19521987

1988+
call ESMF_TimeIntervalGet(dtimestep, s=dt_cpl, rc=rc)
1989+
if (ChkErr(rc,__LINE__,u_FILE_u)) return
1990+
call NUOPC_CompAttributeGet(gcomp, name='restart_fh', value=cvalue, rc=rc)
1991+
if (ChkErr(rc,__LINE__,u_FILE_u)) return
1992+
1993+
! convert string to a list of integer restart_fh values
1994+
nfh = 1 + count(transfer(trim(cvalue), 'a', len(cvalue)) == ",")
1995+
allocate(restart_fh(1:nfh))
1996+
allocate(restartFhTimes(1:nfh))
1997+
read(cvalue,*)restart_fh(1:nfh)
1998+
1999+
! create a list of times at each restart_fh
2000+
do n = 1,nfh
2001+
call ESMF_TimeIntervalSet(fhInterval, h=restart_fh(n), rc=rc)
2002+
if (ChkErr(rc,__LINE__,u_FILE_u)) return
2003+
restartFhTimes(n) = mcurrtime + fhInterval
2004+
call ESMF_TimePrint(restartFhTimes(n), options="string", preString="Restart_Fh at ", unit=timestr, rc=rc)
2005+
if (ChkErr(rc,__LINE__,u_FILE_u)) return
2006+
if (localPet == 0) then
2007+
if (mod(3600*restart_fh(n),dt_cpl) /= 0) then
2008+
write(stdout,'(A)')trim(subname)//trim(timestr)//' will not be written'
2009+
else
2010+
write(stdout,'(A)')trim(subname)//trim(timestr)//' will be written'
2011+
end if
2012+
end if
2013+
end do
2014+
deallocate(restart_fh)
2015+
end if
2016+
2017+
first_time = .false.
19532018
endif
19542019

19552020
!--------------------------------

0 commit comments

Comments
 (0)