Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restart at eor #31

Open
wants to merge 6 commits into
base: dev/unified
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions model/src/wav_comp_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc)
!--------------------------------------------------------------------
! IO set-up
!--------------------------------------------------------------------
if (.not. multigrid) call set_shel_io(stdout,mds,ntrace)

if (cesmcoupled) then
shrlogunit = 6
Expand All @@ -562,8 +563,6 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc)
stdout = 6
end if

if (.not. multigrid) call set_shel_io(stdout,mds,ntrace)

if ( root_task ) then
write(stdout,'(a)')' *** WAVEWATCH III Program shell *** '
write(stdout,'(a)')'==============================================='
Expand Down Expand Up @@ -1026,7 +1025,8 @@ subroutine ModelAdvance(gcomp, rc)
type(ESMF_Time) :: currTime, nextTime, startTime, stopTime
integer :: yy,mm,dd,hh,ss
integer :: imod
integer :: shrlogunit ! original log unit and level
integer :: ymd ! current year-month-day
integer :: tod ! current time of day (sec)
character(ESMF_MAXSTR) :: msgString
character(len=*),parameter :: subname = '(wav_comp_nuopc:ModelAdvance) '
!-------------------------------------------------------
Expand Down Expand Up @@ -1178,7 +1178,7 @@ end subroutine ModelAdvance
!> @author [email protected], [email protected]
!> @date 01-05-2022
subroutine ModelSetRunClock(gcomp, rc)

use nuopc_shr_methods, only : dtime_drv, get_minimum_timestep
! input/output variables
type(ESMF_GridComp) :: gcomp
integer, intent(out) :: rc
Expand Down Expand Up @@ -1237,6 +1237,8 @@ subroutine ModelSetRunClock(gcomp, rc)

call ESMF_ClockGetAlarmList(mclock, alarmlistflag=ESMF_ALARMLIST_ALL, alarmCount=alarmCount, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
dtime_drv = get_minimum_timestep(gcomp, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

if (alarmCount == 0) then

Expand All @@ -1246,6 +1248,29 @@ subroutine ModelSetRunClock(gcomp, rc)
call ESMF_GridCompGet(gcomp, name=name, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_LogWrite(trim(subname)//'setting alarms for ' // trim(name), ESMF_LOGMSG_INFO)
!----------------
! Stop alarm
!----------------
call NUOPC_CompAttributeGet(gcomp, name="stop_option", value=stop_option, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

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

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

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

call ESMF_AlarmSet(stop_alarm, clock=mclock, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

!----------------
! Restart alarm
Expand Down Expand Up @@ -1281,30 +1306,6 @@ subroutine ModelSetRunClock(gcomp, rc)
user_restalarm = .false.
end if

!----------------
! Stop alarm
!----------------
call NUOPC_CompAttributeGet(gcomp, name="stop_option", value=stop_option, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

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

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

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

call ESMF_AlarmSet(stop_alarm, clock=mclock, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

!----------------
! History alarm
!----------------
Expand Down Expand Up @@ -1428,7 +1429,6 @@ subroutine waveinit_cesm(gcomp, ntrace, mpi_comm, mds, rc)
! local variables
integer :: ierr
integer :: unitn ! namelist unit number
integer :: shrlogunit
logical :: isPresent, isSet
real(r8) :: dtmax_in ! Maximum overall time step.
real(r8) :: dtmin_in ! Minimum dynamic time step for source
Expand Down
38 changes: 32 additions & 6 deletions model/src/wav_shr_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module wav_shr_mod
use ESMF , only : ESMF_Time, ESMF_TimeGet, ESMF_TimeSet
use ESMF , only : ESMF_TimeInterval, ESMF_TimeIntervalSet, ESMF_TimeIntervalGet
use ESMF , only : ESMF_VM, ESMF_VMGet, ESMF_VMBroadcast, ESMF_VMGetCurrent
use ESMF , only : ESMF_ClockGetAlarm, ESMF_AlarmGet, MOD
use NUOPC , only : NUOPC_CompAttributeGet
use NUOPC_Model , only : NUOPC_ModelGet
use wav_kind_mod , only : r8 => shr_kind_r8, i8 => shr_kind_i8, cl=>shr_kind_cl, cs=>shr_kind_cs
Expand All @@ -47,7 +48,6 @@ module wav_shr_mod
private :: field_getfldptr !< @private obtain a pointer to a field
public :: diagnose_mesh !< @public write out info about mesh
public :: write_meshdecomp !< @public write the mesh decomposition to a file

interface state_getfldptr
module procedure state_getfldptr_1d
module procedure state_getfldptr_2d
Expand Down Expand Up @@ -75,7 +75,7 @@ module wav_shr_mod
!! be merged with a field provided from a file
logical , public :: multigrid = .false. !< @public logical to control whether wave model is run
!! as multigrid

integer , public :: dtime_drv !! used for nstep(s) alarm option setting
interface ymd2date
module procedure ymd2date_int
module procedure ymd2date_long
Expand All @@ -102,6 +102,7 @@ module wav_shr_mod
optMonthly = "monthly" , & !< alarm option monthly
optYearly = "yearly" , & !< alarm option yearly
optDate = "date" , & !< alarm option date
optEnd = "end" , & !< alarm option end
optIfdays0 = "ifdays0" !< alarm option for number of days 0

! Module data
Expand Down Expand Up @@ -893,6 +894,7 @@ subroutine alarmInit( clock, alarm, option, &
type(ESMF_Time) :: CurrTime ! Current Time
type(ESMF_Time) :: NextAlarm ! Next restart alarm time
type(ESMF_TimeInterval) :: AlarmInterval ! Alarm interval
type(ESMF_TimeInterval) :: TimeStepInterval ! Timestep interval
integer :: sec

character(len=*), parameter :: subname = ' (wav_shr_mod:set_alarmInit) '
Expand Down Expand Up @@ -940,6 +942,14 @@ subroutine alarmInit( clock, alarm, option, &
if (chkerr(rc,__LINE__,u_FILE_u)) return
update_nextalarm = .false.

case (optEnd)
call ESMF_TimeIntervalSet(AlarmInterval, yy=9999, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call ESMF_ClockGetAlarm(clock, alarmname="alarm_stop", alarm=alarm, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_AlarmGet(alarm, ringTime=NextAlarm, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

case (optDate)
if (.not. present(opt_ymd)) then
call ESMF_LogWrite(trim(subname)//trim(option)//' requires opt_ymd', &
Expand Down Expand Up @@ -990,9 +1000,17 @@ subroutine alarmInit( clock, alarm, option, &
ESMF_LOGMSG_INFO, rc=rc)
rc = ESMF_FAILURE
end if
call ESMF_ClockGet(clock, TimeStep=AlarmInterval, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call ESMF_ClockGet(clock, TimeStep=TimestepInterval, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_TimeIntervalSet(AlarmInterval, s=dtime_drv, rc=rc )
if (ChkErr(rc,__LINE__,u_FILE_u)) return
AlarmInterval = AlarmInterval * opt_n
! timestepinterval*0 is 0 of kind ESMF_TimeStepInterval
if (mod(AlarmInterval, TimestepInterval) /= (timestepinterval*0)) then
call ESMF_LogWrite(subname//'illegal Alarm setting for '//trim(alarmname), ESMF_LOGMSG_ERROR)
rc = ESMF_FAILURE
return
endif
update_nextalarm = .true.

case (optNStep)
Expand All @@ -1006,9 +1024,17 @@ subroutine alarmInit( clock, alarm, option, &
ESMF_LOGMSG_INFO, rc=rc)
rc = ESMF_FAILURE
end if
call ESMF_ClockGet(clock, TimeStep=AlarmInterval, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call ESMF_ClockGet(clock, TimeStep=TimestepInterval, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_TimeIntervalSet(AlarmInterval, s=dtime_drv, rc=rc )
if (ChkErr(rc,__LINE__,u_FILE_u)) return
AlarmInterval = AlarmInterval * opt_n
! timestepinterval*0 is 0 of kind ESMF_TimeStepInterval
if (mod(AlarmInterval, TimestepInterval) /= (timestepinterval*0)) then
call ESMF_LogWrite(subname//'illegal Alarm setting for '//trim(alarmname), ESMF_LOGMSG_ERROR)
rc = ESMF_FAILURE
return
endif
update_nextalarm = .true.

case (optNSeconds)
Expand Down