Skip to content

Commit 409bc85

Browse files
Flexible restart write times (restart_fh) for med, ocn, ice, wav (#2419)
* UFSWM - Flexible restart write times (restart_fh) for med, ocn, ice, wav * CICE - Flexible restart write times (restart_fh) * CMEPS - Flexible restart write times (restart_fh) * MOM6 - Flexible restart write times (restart_fh) * WW3 - Flexible restart write times (restart_fh)
1 parent 63ace62 commit 409bc85

24 files changed

+2824
-2535
lines changed

CDEPS-interface/cdeps_files.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ list(APPEND ufs_cdeps_share_files
44
ufs/cdeps_share/shr_assert_mod.F90
55
ufs/cdeps_share/shr_frz_mod.F90
66
ufs/cdeps_share/shr_infnan_mod.F90
7+
ufs/cdeps_share/shr_is_restart_fh_mod.F90
78
)
89

910
list(APPEND cdeps_share_files
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
module shr_is_restart_fh_mod
2+
3+
! Common methods for components to check if it's time to write forecast hour-based restarts
4+
5+
!use dshr_methods_mod , only : chkerr
6+
use ESMF, only : ESMF_ConfigCreate, ESMF_ConfigDestroy, ESMF_ConfigLoadFile, &
7+
ESMF_ConfigGetLen, ESMF_ConfigGetAttribute, ESMF_TimePrint, &
8+
ESMF_LOGMSG_INFO, ESMF_LogWrite, ESMF_TimeInterval, &
9+
ESMF_Time, ESMF_KIND_R8, ESMF_Config, ESMF_Clock, &
10+
ESMF_TimeIntervalSet, ESMF_TimePrint, operator(+), operator(==), &
11+
ESMF_LogFoundError, ESMF_LOGERR_PASSTHRU
12+
13+
implicit none
14+
private
15+
16+
type :: is_restart_fh_type
17+
logical :: write_restartfh = .false.
18+
type(ESMF_Time), allocatable :: restartFhTimes(:)
19+
end type is_restart_fh_type
20+
21+
public :: init_is_restart_fh, is_restart_fh, finalize_restart_fh, is_restart_fh_type
22+
23+
contains
24+
25+
!-----------------------------------------------------------------------
26+
subroutine init_is_restart_fh(currentTime, dtime, lLog, restartfh_info)
27+
!
28+
! !DESCRIPTION:
29+
! Process restart_fh attribute from model_configure in UFS
30+
!
31+
! !USES:
32+
!
33+
! !ARGUMENTS:
34+
type(ESMF_Time), intent(in) :: currentTime
35+
integer, intent(in) :: dtime ! time step (s)
36+
logical, intent(in) :: lLog ! If true, this task logs restart_fh info
37+
type(is_restart_fh_type), intent(out) :: restartfh_info !restart_fh info for each task
38+
!
39+
! !LOCAL VARIABLES:
40+
character(len=256) :: timestr
41+
integer :: n, nfh, fh_s, rc
42+
logical :: isPresent
43+
real(kind=ESMF_KIND_R8), allocatable :: restart_fh(:)
44+
type(ESMF_TimeInterval) :: fhInterval
45+
type(ESMF_Config) :: CF_mc
46+
!-----------------------------------------------------------------------
47+
48+
! set up Times to write non-interval restarts
49+
inquire(FILE='model_configure', EXIST=isPresent)
50+
if (isPresent) then !model_configure exists. this is ufs run
51+
CF_mc = ESMF_ConfigCreate(rc=rc)
52+
call ESMF_ConfigLoadFile(config=CF_mc,filename='model_configure' ,rc=rc)
53+
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
54+
55+
nfh = ESMF_ConfigGetLen(config=CF_mc, label ='restart_fh:',rc=rc)
56+
if (nfh .gt. 0) then
57+
allocate(restart_fh(1:nfh))
58+
allocate(restartfh_info%restartFhTimes(1:nfh)) !not deallocated here
59+
60+
call ESMF_ConfigGetAttribute(CF_mc,valueList=restart_fh,label='restart_fh:', rc=rc)
61+
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
62+
! create a list of times at each restart_fh
63+
do n = 1,nfh
64+
fh_s = NINT(3600*restart_fh(n))
65+
call ESMF_TimeIntervalSet(fhInterval, s=fh_s, rc=rc)
66+
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
67+
restartfh_info%restartFhTimes(n) = currentTime + fhInterval
68+
call ESMF_TimePrint(restartfh_info%restartFhTimes(n), options="string", &
69+
preString="restart_fh at ", unit=timestr, rc=rc)
70+
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
71+
if (lLog) then
72+
if (mod(fh_s,dtime) /= 0) then
73+
call ESMF_LogWrite('restart time NOT to be written for '//trim(timestr), ESMF_LOGMSG_INFO)
74+
else
75+
call ESMF_LogWrite('restart time to be written for '//trim(timestr), ESMF_LOGMSG_INFO)
76+
end if
77+
end if
78+
end do
79+
deallocate(restart_fh)
80+
end if !nfh>0
81+
call ESMF_ConfigDestroy(CF_mc, rc=rc)
82+
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
83+
end if !model_configure
84+
85+
end subroutine init_is_restart_fh
86+
87+
subroutine is_restart_fh(clock, restartfh_info, lWrite)
88+
!
89+
! !DESCRIPTION:
90+
! True/false if time to write restart
91+
!
92+
! !USES:
93+
use ESMF, only : ESMF_ClockGetNextTime
94+
95+
!
96+
! !ARGUMENTS:
97+
type(ESMF_Clock), intent(in) :: clock
98+
type(is_restart_fh_type), intent(inout) :: restartfh_info
99+
logical, intent(out) :: lWrite ! time to write?
100+
!
101+
! !LOCAL VARIABLES:
102+
integer :: nfh, rc
103+
type(ESMF_Time) :: nextTime
104+
!-----------------------------------------------------------------------
105+
106+
restartfh_info%write_restartfh = .false.
107+
if (allocated(restartfh_info%restartFhTimes)) then
108+
! check if next time is == to any restartfhtime
109+
do nfh = 1,size(restartfh_info%restartFhTimes)
110+
call ESMF_ClockGetNextTime(clock, nextTime=nexttime, rc=rc)
111+
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
112+
if (nextTime == restartfh_info%restartFhTimes(nfh)) restartfh_info%write_restartfh = .true.
113+
end do
114+
end if
115+
116+
lWrite = restartfh_info%write_restartfh
117+
118+
end subroutine is_restart_fh
119+
120+
subroutine finalize_restart_fh(restartfh_info)
121+
!
122+
! !DESCRIPTION:
123+
! Clean-up...release allocated memory
124+
!
125+
! !USES:
126+
!
127+
! !ARGUMENTS:
128+
type(is_restart_fh_type), intent(inout) :: restartfh_info
129+
!
130+
! !LOCAL VARIABLES:
131+
!-----------------------------------------------------------------------
132+
133+
if (allocated(restartfh_info%restartFhTimes)) deallocate(restartfh_info%restartFhTimes)
134+
135+
end subroutine finalize_restart_fh
136+
137+
end module shr_is_restart_fh_mod

CICE-interface/CICE

CICE-interface/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ list(APPEND lib_src_files
6363
${icepack_files}
6464
${cice_mpi_comm_files}
6565
${cice_nuopc_cmeps_driver_files}
66-
${cice_cdeps_inline_files})
66+
${cice_cdeps_share_files})
6767

6868
list(APPEND _cice_defs FORTRANUNDERSCORE
6969
coupled)

CICE-interface/cice_files.cmake

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ list(APPEND cice_nuopc_cmeps_driver_files
151151
CICE/cicecore/drivers/nuopc/cmeps/ice_mesh_mod.F90
152152
)
153153

154-
#-- Using ice prescribed ifndef cesmcoupled
155-
list(APPEND cice_cdeps_inline_files
154+
list(APPEND cice_cdeps_share_files
155+
#-- Using ice prescribed ifndef cesmcoupled
156156
${PROJECT_SOURCE_DIR}/CDEPS-interface/CDEPS/share/shr_orb_mod.F90
157157
${PROJECT_SOURCE_DIR}/CDEPS-interface/CDEPS/share/shr_const_mod.F90
158158
${PROJECT_SOURCE_DIR}/CDEPS-interface/CDEPS/share/shr_abort_mod.F90
@@ -168,4 +168,7 @@ list(APPEND cice_cdeps_inline_files
168168
${PROJECT_SOURCE_DIR}/CDEPS-interface/CDEPS/streams/dshr_stream_mod.F90
169169
${PROJECT_SOURCE_DIR}/CDEPS-interface/CDEPS/streams/dshr_methods_mod.F90
170170
${PROJECT_SOURCE_DIR}/CDEPS-interface/CDEPS/dshr/dshr_mod.F90
171+
172+
#restart_fh
173+
${PROJECT_SOURCE_DIR}/CDEPS-interface/ufs/cdeps_share/shr_is_restart_fh_mod.F90
171174
)

CMEPS-interface/CMEPS

CMEPS-interface/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ list(APPEND _ufs_util_files
4242
${PROJECT_SOURCE_DIR}/CDEPS-interface/CDEPS/share/shr_sys_mod.F90
4343
${PROJECT_SOURCE_DIR}/CDEPS-interface/CDEPS/share/shr_kind_mod.F90
4444
${PROJECT_SOURCE_DIR}/CDEPS-interface/ufs/cdeps_share/shr_assert_mod.F90
45-
${PROJECT_SOURCE_DIR}/CDEPS-interface/ufs/cdeps_share/shr_infnan_mod.F90)
45+
${PROJECT_SOURCE_DIR}/CDEPS-interface/ufs/cdeps_share/shr_infnan_mod.F90
46+
${PROJECT_SOURCE_DIR}/CDEPS-interface/ufs/cdeps_share/shr_is_restart_fh_mod.F90)
4647

4748
list(APPEND _mediator_files
4849
CMEPS/mediator/med_phases_restart_mod.F90

MOM6-interface/MOM6

MOM6-interface/mom6_files.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@ list(APPEND mom6_nuopc_src_files
315315
MOM6/config_src/drivers/timing_tests/time_MOM_EOS.F90
316316
)
317317

318+
list(APPEND mom6_nuopc_src_files
319+
${PROJECT_SOURCE_DIR}/CDEPS-interface/ufs/cdeps_share/shr_is_restart_fh_mod.F90
320+
)
321+
318322
list(APPEND mom6_solo_src_files
319323
MOM6/config_src/drivers/solo_driver/MESO_surface_forcing.F90
320324
MOM6/config_src/drivers/solo_driver/MOM_driver.F90

WW3

0 commit comments

Comments
 (0)