Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 5 additions & 14 deletions datm/atm_comp_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module cdeps_datm_comp
use dshr_strdata_mod , only : shr_strdata_get_stream_pointer, shr_strdata_setOrbs
use dshr_mod , only : dshr_model_initphase, dshr_init
use dshr_mod , only : dshr_state_setscalar, dshr_set_runclock, dshr_log_clock_advance
use dshr_mod , only : dshr_restart_read, dshr_restart_write, dshr_mesh_init
use dshr_mod , only : dshr_mesh_init, dshr_check_restart_alarm
use dshr_mod , only : dshr_orbital_init, dshr_orbital_update
use dshr_dfield_mod , only : dfield_type, dshr_dfield_add, dshr_dfield_copy
use dshr_fldlist_mod , only : fldlist_type, dshr_fldlist_add, dshr_fldlist_realize
Expand Down Expand Up @@ -448,7 +448,7 @@ subroutine ModelAdvance(gcomp, rc)
type(ESMF_Time) :: nextTime
type(ESMF_TimeInterval) :: timeStep
real(r8) :: nextsw_cday
logical :: restart_write ! restart alarm is ringing
logical :: rstwr ! restart alarm is ringing

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why change the name to a shorter name? What was wrong with restart_write?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

nothing, it was a cut and paste change. I've updated to restart_write.

integer :: next_ymd ! model date
integer :: next_tod ! model sec into model date
integer :: yr, mon, day ! year, month, day
Expand Down Expand Up @@ -485,22 +485,13 @@ subroutine ModelAdvance(gcomp, rc)
orbEccen, orbObliqr, orbLambm0, orbMvelpp, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

! determine if will write restart
call ESMF_ClockGetAlarm(clock, alarmname='alarm_restart', alarm=alarm, rc=rc)
rstwr = dshr_check_restart_alarm(clock, rc=rc)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Great idea for code reuse! I'm sorry I did not think of this!

if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (ESMF_AlarmIsRinging(alarm, rc=rc)) then
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_AlarmRingerOff( alarm, rc=rc )
if (ChkErr(rc,__LINE__,u_FILE_u)) return
restart_write = .true.
else
restart_write = .false.
endif


! Run datm
call ESMF_TraceRegionEnter('datm_run')
call datm_comp_run(importstate, exportstate, next_ymd, next_tod, mon, &
orbEccen, orbMvelpp, orbLambm0, orbObliqr, restart_write, rc)
orbEccen, orbMvelpp, orbLambm0, orbObliqr, rstwr, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_TraceRegionExit('datm_run')

Expand Down
12 changes: 2 additions & 10 deletions dice/ice_comp_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module cdeps_dice_comp
use shr_sys_mod , only : shr_sys_abort
use shr_cal_mod , only : shr_cal_ymd2date, shr_cal_ymd2julian
use shr_mpi_mod , only : shr_mpi_bcast
use dshr_mod , only : dshr_model_initphase, dshr_init, dshr_mesh_init
use dshr_mod , only : dshr_model_initphase, dshr_init, dshr_mesh_init, dshr_check_restart_alarm
use dshr_mod , only : dshr_state_setscalar, dshr_set_runclock, dshr_log_clock_advance
use dshr_methods_mod , only : dshr_state_diagnose, chkerr, memcheck
use dshr_strdata_mod , only : shr_strdata_type, shr_strdata_init_from_config, shr_strdata_advance
Expand Down Expand Up @@ -415,16 +415,8 @@ subroutine ModelAdvance(gcomp, rc)
cosArg = 2.0_R8*shr_const_pi*(jday - jday0)/365.0_R8

! Determine if will write restarts
call ESMF_ClockGetAlarm(clock, alarmname='alarm_restart', alarm=alarm, rc=rc)
restart_write = dshr_check_restart_alarm(clock, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (ESMF_AlarmIsRinging(alarm, rc=rc)) then
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_AlarmRingerOff( alarm, rc=rc )
if (ChkErr(rc,__LINE__,u_FILE_u)) return
restart_write = .true.
else
restart_write = .false.
endif

! Run dice
call dice_comp_run(importState, exportState, next_ymd, next_tod, cosarg, restart_write, rc)
Expand Down
12 changes: 5 additions & 7 deletions dlnd/lnd_comp_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module cdeps_dlnd_comp
use dshr_methods_mod , only : dshr_state_getfldptr, dshr_state_diagnose, chkerr, memcheck
use dshr_strdata_mod , only : shr_strdata_type, shr_strdata_advance, shr_strdata_get_stream_domain
use dshr_strdata_mod , only : shr_strdata_init_from_config
use dshr_mod , only : dshr_model_initphase, dshr_init
use dshr_mod , only : dshr_model_initphase, dshr_init, dshr_check_restart_alarm
use dshr_mod , only : dshr_state_setscalar, dshr_set_runclock, dshr_log_clock_advance
use dshr_mod , only : dshr_restart_read, dshr_restart_write, dshr_mesh_init
use dshr_dfield_mod , only : dfield_type, dshr_dfield_add, dshr_dfield_copy
Expand Down Expand Up @@ -325,6 +325,7 @@ subroutine ModelAdvance(gcomp, rc)
integer :: yr ! year
integer :: mon ! month
integer :: day ! day in month
logical :: write_restart
character(len=*),parameter :: subname=trim(modName)//':(ModelAdvance) '
!-------------------------------------------------------------------------------

Expand All @@ -351,19 +352,16 @@ subroutine ModelAdvance(gcomp, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

! write_restart if alarm is ringing
call ESMF_ClockGetAlarm(clock, alarmname='alarm_restart', alarm=alarm, rc=rc)
write_restart = dshr_check_restart_alarm(clock, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (ESMF_AlarmIsRinging(alarm, rc=rc)) then
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_AlarmRingerOff( alarm, rc=rc )
if (ChkErr(rc,__LINE__,u_FILE_u)) return

if (write_restart) then
call ESMF_TraceRegionEnter('dlnd_restart')
call dshr_restart_write(rpfile, case_name, 'dlnd', inst_suffix, next_ymd, next_tod, &
logunit, my_task, sdat)
call ESMF_TraceRegionExit('dlnd_restart')
endif


! write diagnostics
if (diagnose_data) then
call dshr_state_diagnose(exportState, flds_scalar_name, subname//':ES',rc=rc)
Expand Down
13 changes: 2 additions & 11 deletions docn/ocn_comp_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module cdeps_docn_comp
use dshr_methods_mod , only : dshr_state_diagnose, chkerr, memcheck
use dshr_strdata_mod , only : shr_strdata_type, shr_strdata_advance, shr_strdata_init_from_config
use dshr_mod , only : dshr_model_initphase, dshr_init, dshr_mesh_init
use dshr_mod , only : dshr_state_setscalar, dshr_set_runclock
use dshr_mod , only : dshr_state_setscalar, dshr_set_runclock, dshr_check_restart_alarm
use dshr_dfield_mod , only : dfield_type, dshr_dfield_add, dshr_dfield_copy
use dshr_fldlist_mod , only : fldlist_type, dshr_fldlist_realize

Expand Down Expand Up @@ -422,16 +422,7 @@ subroutine ModelAdvance(gcomp, rc)
call shr_cal_ymd2date(yr, mon, day, next_ymd)

! determine if will write restart
call ESMF_ClockGetAlarm(clock, alarmname='alarm_restart', alarm=alarm, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (ESMF_AlarmIsRinging(alarm, rc=rc)) then
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_AlarmRingerOff( alarm, rc=rc )
if (ChkErr(rc,__LINE__,u_FILE_u)) return
restart_write = .true.
else
restart_write = .false.
end if
restart_write = dshr_check_restart_alarm(clock, rc=rc)

! run docn
call docn_comp_run(importState, exportState, clock, next_ymd, next_tod, restart_write, rc=rc)
Expand Down
14 changes: 3 additions & 11 deletions drof/rof_comp_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module cdeps_drof_comp
use dshr_strdata_mod , only : shr_strdata_type, shr_strdata_advance, shr_strdata_get_stream_domain
use dshr_strdata_mod , only : shr_strdata_init_from_config
use dshr_mod , only : dshr_model_initphase, dshr_init
use dshr_mod , only : dshr_state_setscalar, dshr_set_runclock
use dshr_mod , only : dshr_state_setscalar, dshr_set_runclock, dshr_check_restart_alarm
use dshr_mod , only : dshr_restart_read, dshr_restart_write, dshr_mesh_init
use dshr_dfield_mod , only : dfield_type, dshr_dfield_add, dshr_dfield_copy
use dshr_fldlist_mod , only : fldlist_type, dshr_fldlist_add, dshr_fldlist_realize
Expand Down Expand Up @@ -339,17 +339,9 @@ subroutine ModelAdvance(gcomp, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call shr_cal_ymd2date(yr, mon, day, next_ymd)

! write_restart if alarm is ringing
call ESMF_ClockGetAlarm(clock, alarmname='alarm_restart', alarm=alarm, rc=rc)
! write restart if alarm is ringing
restart_write = dshr_check_restart_alarm(clock, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (ESMF_AlarmIsRinging(alarm, rc=rc)) then
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_AlarmRingerOff( alarm, rc=rc )
if (ChkErr(rc,__LINE__,u_FILE_u)) return
restart_write = .true.
else
restart_write = .false.
endif

! run drof
call drof_comp_run(exportState, next_ymd, next_tod, restart_write, rc=rc)
Expand Down
93 changes: 93 additions & 0 deletions dshr/dshr_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ module dshr_mod
character(len=*) , parameter :: orb_fixed_year = 'fixed_year'
character(len=*) , parameter :: orb_variable_year = 'variable_year'
character(len=*) , parameter :: orb_fixed_parameters = 'fixed_parameters'
logical :: write_restart_at_endofrun

integer , parameter :: master_task = 0
character(*), parameter :: u_FILE_u = &
Expand Down Expand Up @@ -213,6 +214,14 @@ subroutine dshr_init(gcomp, compname, sdat, mpicom, my_task, inst_index, inst_su
inst_index=1
endif

call NUOPC_CompAttributeGet(gcomp, name="write_restart_at_endofrun", value=cvalue, rc=rc)
Comment thread
jedwards4b marked this conversation as resolved.
Outdated
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
read(cvalue,*) write_restart_at_endofrun
else
write_restart_at_endofrun = .false.
end if

#ifdef CESMCOUPLED
sdat%pio_subsystem => shr_pio_getiosys(trim(compname))
sdat%io_type = shr_pio_getiotype(trim(compname))
Expand Down Expand Up @@ -457,6 +466,10 @@ subroutine dshr_set_runclock(gcomp, rc)
integer :: restart_n ! Number until restart interval
integer :: restart_ymd ! Restart date (YYYYMMDD)
type(ESMF_ALARM) :: restart_alarm
character(len=256) :: stop_option ! Stop option units
integer :: stop_n ! Number until stop interval
integer :: stop_ymd ! Stop date (YYYYMMDD)
type(ESMF_ALARM) :: stop_alarm
character(len=128) :: name
integer :: alarmcount
character(len=*),parameter :: subname='dshr_mod:(ModelSetRunClock) '
Expand Down Expand Up @@ -510,6 +523,30 @@ subroutine dshr_set_runclock(gcomp, rc)
call ESMF_AlarmSet(restart_alarm, clock=mclock, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

!----------------
Comment thread
uturuncoglu marked this conversation as resolved.
! 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 dshr_alarm_init(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

end if

! Advance model clock to trigger alarms then reset model clock back to currtime
Expand Down Expand Up @@ -577,6 +614,7 @@ subroutine dshr_alarm_init( clock, alarm, option, &
optMonthly = "monthly" , &
optYearly = "yearly" , &
optDate = "date" , &
optEnd = "end" , &
optIfdays0 = "ifdays0"
character(len=*), parameter :: subname = '(dshr_alarm_init): '
!-------------------------------------------------------------------------------
Expand Down Expand Up @@ -623,6 +661,13 @@ subroutine dshr_alarm_init( 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_TimeSet( NextAlarm, yy=9999, mm=12, dd=1, s=0, calendar=cal, rc=rc )
if (chkerr(rc,__LINE__,u_FILE_u)) return
update_nextalarm = .false.

case (optDate)
if (.not. present(opt_ymd)) then
call shr_sys_abort(subname//trim(option)//' requires opt_ymd')
Expand Down Expand Up @@ -1845,4 +1890,52 @@ subroutine dshr_pio_init(gcomp, sdat, logunit, rc)

end subroutine dshr_pio_init

logical function dshr_check_restart_alarm(clock, rc)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could you please add a line or two of comments about our logic here. I think this would be helpful for future reference.

use ESMF, only : ESMF_ClockGetAlarm, ESMF_AlarmIsRinging, ESMF_AlarmRingerOff
integer, intent(out) :: rc
type(ESMF_CLOCK), intent(in) :: clock

type(ESMF_ALARM) :: alarm
logical :: nlend, rstwr
!--------------------------------
! Determine if time to stop
!--------------------------------

rc = ESMF_SUCCESS

call ESMF_ClockGetAlarm(clock, alarmname='alarm_stop', alarm=alarm, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

if (ESMF_AlarmIsRinging(alarm, rc=rc)) then
if (ChkErr(rc,__LINE__,u_FILE_u)) return
nlend = .true.
call ESMF_AlarmRingerOff( alarm, rc=rc )
if (ChkErr(rc,__LINE__,u_FILE_u)) return
else
nlend = .false.
endif

!--------------------------------
! Determine if time to write restart
!--------------------------------

if (nlend .and. write_restart_at_endofrun) then
rstwr = .true.
else
call ESMF_ClockGetAlarm(clock, alarmname='alarm_restart', alarm=alarm, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

if (ESMF_AlarmIsRinging(alarm, rc=rc)) then
if (ChkErr(rc,__LINE__,u_FILE_u)) return
rstwr = .true.
call ESMF_AlarmRingerOff( alarm, rc=rc )
if (ChkErr(rc,__LINE__,u_FILE_u)) return
else
rstwr = .false.
endif
end if
dshr_check_restart_alarm = rstwr
end function dshr_check_restart_alarm


end module dshr_mod
11 changes: 4 additions & 7 deletions dwav/wav_comp_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module cdeps_dwav_comp
use dshr_methods_mod , only : dshr_state_getfldptr, chkerr, memcheck, dshr_state_diagnose
use dshr_strdata_mod , only : shr_strdata_type, shr_strdata_advance
use dshr_strdata_mod , only : shr_strdata_init_from_config
use dshr_mod , only : dshr_model_initphase, dshr_init
use dshr_mod , only : dshr_model_initphase, dshr_init, dshr_check_restart_alarm
use dshr_mod , only : dshr_state_setscalar, dshr_set_runclock, dshr_log_clock_advance
use dshr_mod , only : dshr_restart_read, dshr_restart_write, dshr_mesh_init
use dshr_dfield_mod , only : dfield_type, dshr_dfield_add, dshr_dfield_copy
Expand Down Expand Up @@ -307,6 +307,7 @@ subroutine ModelAdvance(gcomp, rc)
integer :: day ! day in month
integer :: next_ymd ! model date
integer :: next_tod ! model sec into model date
logical :: write_restart
character(len=*),parameter :: subname=trim(modName)//':(ModelAdvance) '
!-------------------------------------------------------------------------------

Expand Down Expand Up @@ -334,13 +335,9 @@ subroutine ModelAdvance(gcomp, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

! write_restart if alarm is ringing
call ESMF_ClockGetAlarm(clock, alarmname='alarm_restart', alarm=alarm, rc=rc)
write_restart = dshr_check_restart_alarm(clock, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (ESMF_AlarmIsRinging(alarm, rc=rc)) then
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_AlarmRingerOff( alarm, rc=rc )
if (ChkErr(rc,__LINE__,u_FILE_u)) return

if (write_restart) then
call ESMF_TraceRegionEnter('dwav_restart')
call NUOPC_CompAttributeGet(gcomp, name='case_name', value=case_name, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
Expand Down