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 2 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
51 changes: 26 additions & 25 deletions model/src/wav_comp_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ end subroutine ModelAdvance
!> @author [email protected], [email protected]
!> @date 01-05-2022
subroutine ModelSetRunClock(gcomp, rc)

use wav_shr_mod, only : dtime_drv, get_minimum_timestep
! input/output variables
type(ESMF_GridComp) :: gcomp
integer, intent(out) :: rc
Expand Down Expand Up @@ -1219,6 +1219,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 @@ -1228,6 +1230,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 @@ -1263,30 +1288,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
88 changes: 82 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,7 @@ 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

public :: get_minimum_timestep !< @public used to set nstep based alarms
interface state_getfldptr
module procedure state_getfldptr_1d
module procedure state_getfldptr_2d
Expand Down Expand Up @@ -75,7 +76,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 +103,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 +895,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 +943,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,10 +1001,22 @@ 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.
! call ESMF_ClockGet(clock, TimeStep=AlarmInterval, rc=rc)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why keep the comment?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

! if (chkerr(rc,__LINE__,u_FILE_u)) return
! AlarmInterval = AlarmInterval * opt_n
! update_nextalarm = .true.

case (optNStep)
if (.not.present(opt_n)) then
Expand All @@ -1006,9 +1029,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 Expand Up @@ -1343,6 +1374,51 @@ subroutine ymd2date_long(year,month,day,date)
if (year < 0) date = -date
end subroutine ymd2date_long

integer function get_minimum_timestep(gcomp, rc)
! Get the minimum timestep interval in seconds based on the nuopc.config variables *_cpl_dt,
! if none of these variables are defined this routine will throw an error
type(ESMF_GridComp), intent(in) :: gcomp
integer, intent(out) :: rc

character(len=CS) :: cvalue
integer :: comp_dt ! coupling interval of component
integer, parameter :: ncomps = 8
character(len=3),parameter :: compname(ncomps) = (/"atm", "lnd", "ice", "ocn","glc","rof", "wav", "esp"/)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this routine in wav share code and not in the general share code? I thought there was actually a routine now in share that could deal with this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

character(len=10) :: comp
integer :: i
logical :: is_present, is_set ! determine if these variables are used

!---------------------------------------------------------------------------
! Determine driver clock timestep
!---------------------------------------------------------------------------
get_minimum_timestep = huge(1)

do i=1,ncomps
comp = compname(i)//"_cpl_dt"

call NUOPC_CompAttributeGet(gcomp, name=comp, isPresent=is_present, isSet=is_set, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

if (is_present .and. is_set) then
call NUOPC_CompAttributeGet(gcomp, name=comp, value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) comp_dt
get_minimum_timestep = min(comp_dt, get_minimum_timestep)
endif
enddo

if(get_minimum_timestep == huge(1)) then
call ESMF_LogWrite('minimum_timestep_error: this option is not supported ', ESMF_LOGMSG_ERROR)
rc = ESMF_FAILURE
return
endif
if(get_minimum_timestep <= 0) then
call ESMF_LogWrite('minimum_timestep_error ERROR ', ESMF_LOGMSG_ERROR)
rc = ESMF_FAILURE
return
endif
end function get_minimum_timestep

!===============================================================================
!> Return a logical true if ESMF_LogFoundError detects an error
!!
Expand Down