From 12cf89c146db14225bdb9d7965168850021ec5bc Mon Sep 17 00:00:00 2001 From: Nick Szapiro Date: Tue, 15 Oct 2024 18:30:57 +0000 Subject: [PATCH] Shared is_restart_fh module...moving into ufs/cdeps_share --- CDEPS-interface/cdeps_files.cmake | 1 + .../ufs/cdeps_share/shr_is_restart_fh_mod.F90 | 146 ++++++++++++++++++ CICE-interface/cice_files.cmake | 1 + CMEPS-interface/CMakeLists.txt | 8 +- MOM6-interface/CMakeLists.txt | 4 + MOM6-interface/mom6_files.cmake | 4 + 6 files changed, 161 insertions(+), 3 deletions(-) create mode 100644 CDEPS-interface/ufs/cdeps_share/shr_is_restart_fh_mod.F90 diff --git a/CDEPS-interface/cdeps_files.cmake b/CDEPS-interface/cdeps_files.cmake index 321b9d84c5..278435745a 100644 --- a/CDEPS-interface/cdeps_files.cmake +++ b/CDEPS-interface/cdeps_files.cmake @@ -4,6 +4,7 @@ list(APPEND ufs_cdeps_share_files ufs/cdeps_share/shr_assert_mod.F90 ufs/cdeps_share/shr_frz_mod.F90 ufs/cdeps_share/shr_infnan_mod.F90 + ufs/cdeps_share/shr_is_restart_fh_mod.F90 ) list(APPEND cdeps_share_files diff --git a/CDEPS-interface/ufs/cdeps_share/shr_is_restart_fh_mod.F90 b/CDEPS-interface/ufs/cdeps_share/shr_is_restart_fh_mod.F90 new file mode 100644 index 0000000000..684600abc9 --- /dev/null +++ b/CDEPS-interface/ufs/cdeps_share/shr_is_restart_fh_mod.F90 @@ -0,0 +1,146 @@ +module shr_is_restart_fh_mod + + ! Common methods for components to check if it's time to write forecast hour-based restarts + + !use dshr_methods_mod , only : chkerr + use ESMF, only : ESMF_ConfigCreate, ESMF_ConfigDestroy, ESMF_ConfigLoadFile, & + ESMF_ConfigGetLen, ESMF_ConfigGetAttribute, ESMF_TimePrint, & + ESMF_LOGMSG_INFO, ESMF_LogWrite, ESMF_TimeInterval, & + ESMF_Time, ESMF_KIND_R8, ESMF_Config, ESMF_Clock, & + ESMF_TimeIntervalSet, ESMF_TimePrint, operator(+), operator(==), & + ESMF_LogFoundError, ESMF_LOGERR_PASSTHRU + + implicit none + private + save + + public :: init_is_restart_fh, is_restart_fh, finalize_restart_fh + + logical :: write_restartfh = .false. + type(ESMF_Time), allocatable :: restartFhTimes(:) +!$OMP THREADPRIVATE (write_restartfh, restartFhTimes) + +contains + + !----------------------------------------------------------------------- + subroutine init_is_restart_fh(currentTime, dtime, lLog) + ! + ! !DESCRIPTION: + ! Process restart_fh attribute from model_configure in UFS + ! + ! !USES: + ! + ! !ARGUMENTS: + type(ESMF_Time), intent(in) :: currentTime + integer, intent(in) :: dtime ! time step (s) + logical, intent(in) :: lLog ! If true, this task logs restart_fh info + ! + ! !LOCAL VARIABLES: + character(len=256) :: timestr + integer :: n, nfh, fh_s, rc + logical :: isPresent + real(kind=ESMF_KIND_R8), allocatable :: restart_fh(:) + type(ESMF_TimeInterval) :: fhInterval + type(ESMF_Config) :: CF_mc + + character(len=*), parameter :: subname = 'init_restart_fh' + !----------------------------------------------------------------------- + + ! set up Times to write non-interval restarts + inquire(FILE='model_configure', EXIST=isPresent) + if (isPresent) then !model_configure exists. this is ufs run + CF_mc = ESMF_ConfigCreate(rc=rc) + call ESMF_ConfigLoadFile(config=CF_mc,filename='model_configure' ,rc=rc) + !if (ChkErr(rc,__LINE__,__FILE__)) return + if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return + + nfh = ESMF_ConfigGetLen(config=CF_mc, label ='restart_fh:',rc=rc) + if (nfh .gt. 0) then + allocate(restart_fh(1:nfh)) + allocate(restartFhTimes(1:nfh)) !not deallocated here + + call ESMF_ConfigGetAttribute(CF_mc,valueList=restart_fh,label='restart_fh:', rc=rc) + !if (ChkErr(rc,__LINE__,__FILE__)) return + if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return + ! create a list of times at each restart_fh + do n = 1,nfh + fh_s = NINT(3600*restart_fh(n)) + call ESMF_TimeIntervalSet(fhInterval, s=fh_s, rc=rc) + !if (ChkErr(rc,__LINE__,__FILE__)) return + if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return + restartFhTimes(n) = currentTime + fhInterval + call ESMF_TimePrint(restartFhTimes(n), options="string", & + preString="restart_fh at ", unit=timestr, rc=rc) + !if (ChkErr(rc,__LINE__,__FILE__)) return + if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return + if (lLog) then + if (mod(fh_s,dtime) /= 0) then + call ESMF_LogWrite('restart time NOT to be written for '//trim(timestr), ESMF_LOGMSG_INFO) + else + call ESMF_LogWrite('restart time to be written for '//trim(timestr), ESMF_LOGMSG_INFO) + end if + end if + end do + deallocate(restart_fh) + end if !nfh>0 + call ESMF_ConfigDestroy(CF_mc, rc=rc) + !if (ChkErr(rc,__LINE__,__FILE__)) return + if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return + end if !model_configure + + end subroutine init_is_restart_fh + + function is_restart_fh(clock) result(lWrite) + ! + ! !DESCRIPTION: + ! True/false if time to write restart + ! + ! !USES: + use ESMF, only : ESMF_ClockGetNextTime + + ! + ! !ARGUMENTS: + type(ESMF_Clock), intent(in) :: clock + logical :: lWrite ! function result + ! + ! !LOCAL VARIABLES: + integer :: nfh, rc + type(ESMF_Time) :: nextTime + + character(len=*), parameter :: subname = 'is_restart_fh' + !----------------------------------------------------------------------- + + write_restartfh = .false. + if (allocated(restartFhTimes)) then + ! check if next time is == to any restartfhtime + do nfh = 1,size(restartFhTimes) + call ESMF_ClockGetNextTime(clock, nextTime=nexttime, rc=rc) + !if (ChkErr(rc,__LINE__,__FILE__)) return + if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return + if (nextTime == restartFhTimes(nfh)) write_restartfh = .true. + end do + end if + + lWrite = write_restartfh + + end function is_restart_fh + + subroutine finalize_restart_fh() + ! + ! !DESCRIPTION: + ! Clean-up...release allocated memory + ! + ! !USES: + ! + ! !ARGUMENTS: + ! + ! !LOCAL VARIABLES: + + character(len=*), parameter :: subname = 'finalize_restart_fh' + !----------------------------------------------------------------------- + + if (allocated(restartFhTimes)) deallocate(restartFhTimes) + + end subroutine finalize_restart_fh + +end module shr_is_restart_fh_mod diff --git a/CICE-interface/cice_files.cmake b/CICE-interface/cice_files.cmake index 2a62c72e30..4db4cf8c06 100644 --- a/CICE-interface/cice_files.cmake +++ b/CICE-interface/cice_files.cmake @@ -164,6 +164,7 @@ list(APPEND cice_cdeps_inline_files ${PROJECT_SOURCE_DIR}/CDEPS-interface/CDEPS/share/shr_cal_mod.F90 ${PROJECT_SOURCE_DIR}/CDEPS-interface/CDEPS/share/shr_string_mod.F90 ${PROJECT_SOURCE_DIR}/CDEPS-interface/CDEPS/share/shr_timer_mod.F90 + ${PROJECT_SOURCE_DIR}/CDEPS-interface/CDEPS/dshr/dshr_is_restart_fh_mod.F90 ${PROJECT_SOURCE_DIR}/CDEPS-interface/CDEPS/streams/dshr_strdata_mod.F90 ${PROJECT_SOURCE_DIR}/CDEPS-interface/CDEPS/streams/dshr_stream_mod.F90 ${PROJECT_SOURCE_DIR}/CDEPS-interface/CDEPS/streams/dshr_methods_mod.F90 diff --git a/CMEPS-interface/CMakeLists.txt b/CMEPS-interface/CMakeLists.txt index efbd585acc..8faf2af303 100644 --- a/CMEPS-interface/CMakeLists.txt +++ b/CMEPS-interface/CMakeLists.txt @@ -42,7 +42,9 @@ list(APPEND _ufs_util_files ${PROJECT_SOURCE_DIR}/CDEPS-interface/CDEPS/share/shr_sys_mod.F90 ${PROJECT_SOURCE_DIR}/CDEPS-interface/CDEPS/share/shr_kind_mod.F90 ${PROJECT_SOURCE_DIR}/CDEPS-interface/ufs/cdeps_share/shr_assert_mod.F90 - ${PROJECT_SOURCE_DIR}/CDEPS-interface/ufs/cdeps_share/shr_infnan_mod.F90) + ${PROJECT_SOURCE_DIR}/CDEPS-interface/ufs/cdeps_share/shr_infnan_mod.F90 + ${PROJECT_SOURCE_DIR}/CDEPS-interface/CDEPS/streams/dshr_methods_mod.F90 + ${PROJECT_SOURCE_DIR}/CDEPS-interface/CDEPS/dshr/dshr_is_restart_fh_mod.F90) list(APPEND _mediator_files CMEPS/mediator/med_phases_restart_mod.F90 @@ -190,10 +192,10 @@ if(OpenMP_Fortran_FOUND) endif() ### Set dependency for CDEPS if inline capability is requested -if(CDEPS_INLINE) +#if(CDEPS_INLINE) add_dependencies(cmeps cdeps::cdeps) target_link_libraries(cmeps PUBLIC cdeps::cdeps) -endif() +#endif() ############################################################################### ### Install diff --git a/MOM6-interface/CMakeLists.txt b/MOM6-interface/CMakeLists.txt index f3cf811ec2..6ae516f197 100644 --- a/MOM6-interface/CMakeLists.txt +++ b/MOM6-interface/CMakeLists.txt @@ -101,6 +101,10 @@ if(MOM6SOLO) #endif() endif() +add_dependencies(mom6 cdeps::cdeps) +target_compile_definitions(mom6 PUBLIC "DISABLE_FoX") +target_link_libraries(mom6 PUBLIC cdeps::cdeps) + ############################################################################### ### Install ############################################################################### diff --git a/MOM6-interface/mom6_files.cmake b/MOM6-interface/mom6_files.cmake index 98fb78776e..0921e4db44 100644 --- a/MOM6-interface/mom6_files.cmake +++ b/MOM6-interface/mom6_files.cmake @@ -315,6 +315,10 @@ list(APPEND mom6_nuopc_src_files MOM6/config_src/drivers/timing_tests/time_MOM_EOS.F90 ) +list(APPEND mom6_nuopc_src_files + ${PROJECT_SOURCE_DIR}/CDEPS-interface/CDEPS/dshr/dshr_is_restart_fh_mod.F90 +) + list(APPEND mom6_solo_src_files MOM6/config_src/drivers/solo_driver/MESO_surface_forcing.F90 MOM6/config_src/drivers/solo_driver/MOM_driver.F90