From 821cf9d885d746c9bd4f2f1881cbb1f60f1e59ee Mon Sep 17 00:00:00 2001 From: Nicholas Szapiro <149816583+NickSzapiro-NOAA@users.noreply.github.com> Date: Thu, 14 Nov 2024 14:20:18 -0500 Subject: [PATCH 1/3] Add restart_fh source to model/src/cmake/src_list.cmake --- model/src/cmake/src_list.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/model/src/cmake/src_list.cmake b/model/src/cmake/src_list.cmake index 825f5d6378..5a0e76f06a 100644 --- a/model/src/cmake/src_list.cmake +++ b/model/src/cmake/src_list.cmake @@ -68,6 +68,8 @@ set(nuopc_mesh_cap_src wav_wrapper_mod.F90 wav_pio_mod.F90 wav_restart_mod.F90 + #restart_fh + ${PROJECT_SOURCE_DIR}/../CDEPS-interface/ufs/cdeps_share/shr_is_restart_fh_mod.F90 ) set(esmf_multi_cap_src From f4d5d479c0d46f13943e4bfe3f6390b13e60060a Mon Sep 17 00:00:00 2001 From: Nicholas Szapiro <149816583+NickSzapiro-NOAA@users.noreply.github.com> Date: Thu, 14 Nov 2024 14:24:13 -0500 Subject: [PATCH 2/3] Implement restart_fh in wav_comp_nuopc.F90 --- model/src/wav_comp_nuopc.F90 | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/model/src/wav_comp_nuopc.F90 b/model/src/wav_comp_nuopc.F90 index 4280b3b141..f6b98f2972 100644 --- a/model/src/wav_comp_nuopc.F90 +++ b/model/src/wav_comp_nuopc.F90 @@ -56,6 +56,7 @@ module wav_comp_nuopc use wmmdatmd , only : nmpscr use w3updtmd , only : w3uini use w3adatmd , only : flcold, fliwnd + use shr_is_restart_fh_mod , only : init_is_restart_fh, is_restart_fh, write_restartfh #endif use constants , only : is_esmf_component @@ -1219,6 +1220,10 @@ subroutine ModelAdvance(gcomp, rc) else rstwr = .false. endif +#ifndef W3_CESMCOUPLED + write_restartfh = is_restart_fh(clock) + if (write_restartfh) rstwr = .true. +#endif ! Determine if time to write ww3 history files call ESMF_ClockGetAlarm(clock, alarmname='alarm_history', alarm=alarm, rc=rc) @@ -1295,7 +1300,7 @@ subroutine ModelSetRunClock(gcomp, rc) integer :: history_ymd ! History date (YYYYMMDD) type(ESMF_ALARM) :: history_alarm character(len=128) :: name - integer :: alarmcount + integer :: alarmcount, dt_cpl character(len=*),parameter :: subname=trim(modName)//':(ModelSetRunClock) ' !------------------------------------------------------------------------------- @@ -1363,6 +1368,12 @@ subroutine ModelSetRunClock(gcomp, rc) call ESMF_AlarmSet(restart_alarm, clock=mclock, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return +#ifndef W3_CESMCOUPLED + call ESMF_TimeIntervalGet( dtimestep, s=dt_cpl, rc=rc ) + if (ChkErr(rc,__LINE__,u_FILE_u)) return + call init_is_restart_fh(mcurrTime, dt_cpl, root_task) +#endif + end if !---------------- From 7352a37666ab0f82dc21f4913cb7d6ec2b2bd722 Mon Sep 17 00:00:00 2001 From: Nick Szapiro Date: Tue, 19 Nov 2024 01:00:39 -0600 Subject: [PATCH 3/3] Use is_restart_fh revised to avoid thread-local storage inter-component conflicts --- model/src/wav_comp_nuopc.F90 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/model/src/wav_comp_nuopc.F90 b/model/src/wav_comp_nuopc.F90 index f6b98f2972..544b40817f 100644 --- a/model/src/wav_comp_nuopc.F90 +++ b/model/src/wav_comp_nuopc.F90 @@ -56,7 +56,7 @@ module wav_comp_nuopc use wmmdatmd , only : nmpscr use w3updtmd , only : w3uini use w3adatmd , only : flcold, fliwnd - use shr_is_restart_fh_mod , only : init_is_restart_fh, is_restart_fh, write_restartfh + use shr_is_restart_fh_mod , only : init_is_restart_fh, is_restart_fh, is_restart_fh_type #endif use constants , only : is_esmf_component @@ -90,6 +90,7 @@ module wav_comp_nuopc logical :: cesmcoupled = .true. !< logical to indicate CESM use case #else logical :: cesmcoupled = .false. !< logical to indicate non-CESM use case + type(is_restart_fh_type) :: restartfh_info ! For flexible restarts in UFS #endif integer, allocatable :: tend(:,:) !< the ending time of ModelAdvance when !! run with multigrid=true @@ -1127,6 +1128,7 @@ subroutine ModelAdvance(gcomp, rc) type(ESMF_Time) :: currTime, nextTime, startTime, stopTime integer :: yy,mm,dd,hh,ss integer :: imod + logical :: write_restartfh !integer :: shrlogunit ! original log unit and level character(ESMF_MAXSTR) :: msgString character(len=*),parameter :: subname = '(wav_comp_nuopc:ModelAdvance) ' @@ -1221,7 +1223,7 @@ subroutine ModelAdvance(gcomp, rc) rstwr = .false. endif #ifndef W3_CESMCOUPLED - write_restartfh = is_restart_fh(clock) + call is_restart_fh(clock, restartfh_info, write_restartfh) if (write_restartfh) rstwr = .true. #endif @@ -1371,7 +1373,7 @@ subroutine ModelSetRunClock(gcomp, rc) #ifndef W3_CESMCOUPLED call ESMF_TimeIntervalGet( dtimestep, s=dt_cpl, rc=rc ) if (ChkErr(rc,__LINE__,u_FILE_u)) return - call init_is_restart_fh(mcurrTime, dt_cpl, root_task) + call init_is_restart_fh(mcurrTime, dt_cpl, root_task, restartfh_info) #endif end if