-
Notifications
You must be signed in to change notification settings - Fork 68
add support for REST_OPTION end and always write a restart at end of … #111
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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 | ||
| integer :: next_ymd ! model date | ||
| integer :: next_tod ! model sec into model date | ||
| integer :: yr, mon, day ! year, month, day | ||
|
|
@@ -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) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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') | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 = & | ||
|
|
@@ -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) | ||
|
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)) | ||
|
|
@@ -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) ' | ||
|
|
@@ -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 | ||
|
|
||
| !---------------- | ||
|
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 | ||
|
|
@@ -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): ' | ||
| !------------------------------------------------------------------------------- | ||
|
|
@@ -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') | ||
|
|
@@ -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) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.