Skip to content

Commit 38f406a

Browse files
whlipscombKatetc
authored andcommitted
Added a hybrid restart option
Until now, the config option 'restart' has had two possible values: * restart = 0 if not a restart (i.e., read in a CF input file and initialize the ice state) * restart = 1 if a restart (i.e., read in a CF restart file that includes the full ice state) This commit adds a new option, restart = 2, called a 'hybrid restart' because of its similarity to a CESM hybrid run. We now refer to option 1 as a 'standard restart'. A hybrid restart works as follows: - The run is initialized from a file in the [CF input] section, as for restart = 0. However, this file has 'restart' or '.r.' in its name and includes the full ice state as needed for exact restart. Typically, it is the final restart time slice from a spin-up. - The initial time (model%numerics%time) is set to 'tstart' as specified in the config file. This differs from a standard restart, which takes its initial time from the restart file. - The initial tstep_count = 0. This differs from a standard restart, which takes tstep_count from the restart file. For glaciers, we can use the hybrid restart option for commitment runs and other forward runs starting from a spun-up state. For instance, say we want to do a 2000-year spin-up followed by a forward run from 2003–2100. The workflow is as follows: - Do the spin-up and write a final restart file. - Set up a directory for the forward run with the required input and forcing files, including the restart file from the spin-up. - In the config file: * Set tstart = 2003, tend = 2100., and restart = 2. * In the [CF input] section, set 'name' to the name of the restart file from the spin-up. This should be different from the name of the [CF restart] file for the forward run. E.g., one file could be spinup.restart.nc, and the other could be forward.restart.nc. * Change other options changes as needed, e.g. change the inversion options. - Launch the forward run. It is no longer necessary to modify the model time or tstep_count by hand in the restart file from the spin-up. Also, it is not necessary to use the same name for (1) the restart file from the spin-up and (2) the restart file for the forward run. If the [CF output] file for the forward run is configured with 'write_init = .true.', then this output file will include the ice state at the start of the forward run. For a standard restart, CISM does not write to the output file at the start of the forward run. Testing the new restart option, I confirmed that a hybrid restart is exact, as expected, apart from the new values of the model time and tstep_count. I also confirmed that the standard restart (restart = 1) works as before.
1 parent 3214b22 commit 38f406a

14 files changed

+106
-77
lines changed

cism_driver/cism_front_end.F90

+3-1
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,10 @@ subroutine cism_init_dycore(model)
229229

230230

231231
! --- Output the initial state -------------
232+
! Note: For a standard restart, the initial state is not output, because this state
233+
! should already have been written to the output file when the previous run ended.
232234

233-
if (model%options%is_restart == RESTART_FALSE .or. model%options%forcewrite_restart) then
235+
if (model%options%is_restart == NO_RESTART .or. model%options%is_restart == HYBRID_RESTART) then
234236
call t_startf('initial_io_writeall')
235237
call glide_io_writeall(model, model, time=time) ! MJH The optional time argument needs to be supplied
236238
! since we have not yet set model%numerics%time

libglide/glide.F90

+2-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,8 @@ subroutine glide_init_state_diagnostic(model, evolve_ice)
463463
l_evolve_ice = .true.
464464
end if
465465

466-
if (model%options%is_restart == RESTART_TRUE) then
466+
if (model%options%is_restart == STANDARD_RESTART .or. &
467+
model%options%is_restart == HYBRID_RESTART) then
467468
! On a restart, just assign the basal velocity from uvel/vvel (which are restart variables)
468469
! to ubas/vbas which are used by the temperature solver to calculate basal heating.
469470
! During time stepping ubas/vbas are calculated by slipvelo during thickness evolution or below on a cold start.

libglide/glide_diagnostics.F90

+1-1
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,7 @@ subroutine glide_write_diag (model, time)
11651165
write(message,'(a35,i14)') 'Diagnostic glacier index (CISM) ', ng
11661166
call write_log(trim(message), type = GM_DIAGNOSTIC)
11671167

1168-
write(message,'(a35,f14.6)') 'Glacier area_init(km^2) ', &
1168+
write(message,'(a35,f14.6)') 'Glacier area_init (km^2) ', &
11691169
model%glacier%area_init(ng) / 1.0d6
11701170
call write_log(trim(message), type = GM_DIAGNOSTIC)
11711171

libglide/glide_lithot.F90

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ subroutine init_lithot(model)
8282
!TODO - Make sure the sign is correct for the geothermal flux.
8383
!NOTE: CISM convention is that geot is positive down, so geot < 0 for upward geothermal flux
8484

85-
if (model%options%is_restart == RESTART_FALSE) then
85+
if (model%options%is_restart == NO_RESTART) then
8686
! set initial temp distribution to thermal gradient
8787
factor = model%paramets%geot / model%lithot%con_r
8888
do k=1,model%lithot%nlayer
@@ -112,7 +112,7 @@ subroutine spinup_lithot(model)
112112

113113
integer t
114114

115-
if (model%options%is_restart == RESTART_FALSE .and. model%lithot%numt > 0) then
115+
if (model%options%is_restart == NO_RESTART .and. model%lithot%numt > 0) then
116116
call write_log('Spinning up GTHF calculations',type=GM_INFO)
117117
call not_parallel(__FILE__,__LINE__)
118118
do t=1,model%lithot%numt

libglide/glide_setup.F90

+6-6
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,6 @@ subroutine handle_options(section, model)
766766
! Going forward, only 'restart' is supported.
767767
call GetValue(section,'restart',model%options%is_restart)
768768
call GetValue(section,'restart_extend_velo',model%options%restart_extend_velo)
769-
call GetValue(section,'forcewrite_restart',model%options%forcewrite_restart)
770769

771770
end subroutine handle_options
772771

@@ -1653,17 +1652,18 @@ subroutine print_options(model)
16531652
call write_log(' Slightly cheated with how temperature is implemented.',GM_WARNING)
16541653
end if
16551654

1656-
if (model%options%is_restart == RESTART_TRUE) then
1655+
if (model%options%is_restart == STANDARD_RESTART) then
16571656
call write_log('Restarting model from a previous run')
16581657
if (model%options%restart_extend_velo == RESTART_EXTEND_VELO_TRUE) then
16591658
call write_log('Using extended velocity fields for restart')
16601659
endif
1660+
elseif (model%options%is_restart == HYBRID_RESTART) then
1661+
call write_log('Hybrid restart from a previous run')
1662+
if (model%options%restart_extend_velo == RESTART_EXTEND_VELO_TRUE) then
1663+
call write_log('Using extended velocity fields for restart')
1664+
endif
16611665
end if
16621666

1663-
if (model%options%forcewrite_restart) then
1664-
call write_log('Will write to output files on restart')
1665-
endif
1666-
16671667
!HO options
16681668

16691669
if (model%options%whichdycore /= DYCORE_GLIDE) then ! glissade higher-order

libglide/glide_temp.F90

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ subroutine glide_init_temp(model)
199199
!TODO - Make sure cells in the Glide temperature halo are initialized to reasonable values
200200
! (not unphys_val), e.g. if reading temps from input or restart file.
201201

202-
if (model%options%is_restart == RESTART_TRUE) then
202+
if (model%options%is_restart == STANDARD_RESTART .or. model%options%is_restart == HYBRID_RESTART) then
203203

204204
! Temperature has already been initialized from a restart file.
205205
! (Temperature is always a restart variable.)
@@ -291,7 +291,7 @@ subroutine glide_init_temp(model)
291291

292292
! ====== Calculate initial value of flwa ==================
293293

294-
if (model%options%is_restart == RESTART_FALSE) then
294+
if (model%options%is_restart == NO_RESTART) then
295295
call write_log("Calculating initial flwa from temp and thk fields")
296296

297297
! Calculate Glen's A --------------------------------------------------------

libglide/glide_types.F90

+4-6
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,9 @@ module glide_types
214214
integer, parameter :: SIGMA_COMPUTE_EVEN = 3
215215
integer, parameter :: SIGMA_COMPUTE_PATTYN = 4
216216

217-
integer, parameter :: RESTART_FALSE = 0
218-
integer, parameter :: RESTART_TRUE = 1
217+
integer, parameter :: NO_RESTART = 0
218+
integer, parameter :: STANDARD_RESTART = 1
219+
integer, parameter :: HYBRID_RESTART = 2
219220

220221
integer, parameter :: RESTART_EXTEND_VELO_FALSE = 0
221222
integer, parameter :: RESTART_EXTEND_VELO_TRUE = 1
@@ -753,12 +754,12 @@ module glide_types
753754
!> \item[4] compute Pattyn sigma coordinates
754755
!> \end{description}
755756

756-
!TODO - Make is_restart a logical variable?
757757
integer :: is_restart = 0
758758
!> if the run is a restart of a previous run
759759
!> \begin{description}
760760
!> \item[0] normal start-up (take init fields from .nc input file OR if absent, use default options)
761761
!> \item[1] restart model from previous run (do not calc. temp, rate factor, or vel)
762+
!> \item[2] hybrid restart; use restart from previous run as the input file, and reset the time
762763
!> \end{description}
763764

764765
integer :: restart_extend_velo = 0
@@ -769,9 +770,6 @@ module glide_types
769770
!> (required if restart velocities are nonzero on global boundaries)
770771
!> \end{description}
771772

772-
logical :: forcewrite_restart = .false.
773-
!> flag that indicates whether to force writing of output on restart
774-
775773
! This is a Glimmer serial option
776774
! The parallel code enforces periodic EW and NS boundary conditions by default
777775
logical :: periodic_ew = .false.

libglimmer/glimmer_ncio.F90

+33-17
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ subroutine openall_out(model,outfiles)
8484

8585
call glimmer_nc_openappend(oc,model)
8686

87-
elseif (model%options%is_restart == RESTART_TRUE) then ! reopen the file if it exists
87+
elseif (model%options%is_restart == STANDARD_RESTART) then ! reopen the file if it exists
8888

8989
status = parallel_open(process_path(oc%nc%filename),NF90_WRITE,oc%nc%id)
9090

@@ -100,6 +100,7 @@ subroutine openall_out(model,outfiles)
100100
endif
101101

102102
else ! assume the file does not exist; create it
103+
! Note: For hybrid restarts, the file is created at initialization
103104

104105
call glimmer_nc_createfile(oc, model)
105106

@@ -714,7 +715,7 @@ subroutine glimmer_nc_checkread(infile,model,time)
714715

715716
implicit none
716717

717-
type(glimmer_nc_input), pointer :: infile !> structure containg output netCDF descriptor
718+
type(glimmer_nc_input), pointer :: infile !> structure containing output netCDF descriptor
718719
type(glide_global_type) :: model !> the model instance
719720
real(dp),optional :: time !> Optional alternative time
720721

@@ -749,21 +750,36 @@ subroutine glimmer_nc_checkread(infile,model,time)
749750

750751
if (pos /= 0 .or. pos_cesm /= 0) then ! get the start time based on the current time slice
751752

752-
restart_time = infile%times(infile%current_time) ! years
753-
model%numerics%tstart = restart_time
754-
model%numerics%time = restart_time
755-
756-
if (infile%tstep_counts_read) then
757-
model%numerics%tstep_count = infile%tstep_counts(infile%current_time)
758-
else
759-
! BACKWARDS_COMPATIBILITY(wjs, 2017-05-17) Older files may not have
760-
! 'tstep_count', so compute it ourselves here. We don't want to use this
761-
! formulation in general because it is prone to roundoff errors.
762-
model%numerics%tstep_count = nint(model%numerics%time/model%numerics%tinc)
763-
end if
764-
765-
write(message,*) 'Restart: New tstart, tstep_count =', model%numerics%tstart, model%numerics%tstep_count
766-
call write_log(message)
753+
if (model%options%is_restart == STANDARD_RESTART) then
754+
755+
restart_time = infile%times(infile%current_time) ! years
756+
model%numerics%tstart = restart_time
757+
model%numerics%time = restart_time
758+
759+
if (infile%tstep_counts_read) then
760+
model%numerics%tstep_count = infile%tstep_counts(infile%current_time)
761+
else
762+
! BACKWARDS_COMPATIBILITY(wjs, 2017-05-17) Older files may not have
763+
! 'tstep_count', so compute it ourselves here. We don't want to use this
764+
! formulation in general because it is prone to roundoff errors.
765+
model%numerics%tstep_count = nint(model%numerics%time/model%numerics%tinc)
766+
end if
767+
768+
write(message,*) 'Standard restart: New tstart, tstep_count =', &
769+
model%numerics%tstart, model%numerics%tstep_count
770+
call write_log(message)
771+
772+
elseif (model%options%is_restart == HYBRID_RESTART) then
773+
774+
! Use tstart from the config file, not the time from the restart file
775+
model%numerics%time = model%numerics%tstart ! years
776+
model%numerics%tstep_count = 0
777+
778+
write(message,*) 'Hybrid restart: New tstart, tstep_count =', &
779+
model%numerics%tstart, model%numerics%tstep_count
780+
call write_log(message)
781+
782+
endif ! is_restart
767783

768784
endif ! pos/=0 or pos_cesm/=0
769785

libglimmer/glimmer_ncparams.F90

+16-8
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,25 @@ subroutine glimmer_nc_readparams(model,config)
7575
character(len=fname_length) :: restart_filename
7676
character(len=256) :: message
7777

78-
! Note on restart files:
78+
! Notes on restart files:
7979
! If a file is listed in the 'CF restart' section, then it is added to the glimmer_nc_output data structure
8080
! and written at the specified frequency.
81-
! If model%options%is_restart = RESTART_TRUE, then the file listed in 'CF restart' (provided it exists)
81+
!
82+
! If model%options%is_restart = STANDARD_RESTART, then the file listed in 'CF restart' (provided it exists)
8283
! is added to the glimmer_nc_input data structure, overriding any file listed in the 'CF input' section.
8384
! The latest time slice will be read in.
84-
! Thus when restarting the model, it is only necessary to set restart = RESTART_TRUE (i.e, restart = 1)
85-
! in the config file; it is not necesssary to change filenames in 'CF input' or 'CF restart'.
86-
! At most one file should be listed in the 'CF restart' section, and it should contain the string 'restart'
87-
! If model%options%is_restart = RESTART_TRUE and there is no 'CF restart' section, then the model will restart
85+
! Thus when restarting the model, it is only necessary to set restart = 1 (i.e., STANDARD_RESTART)
86+
! in the config file; it is not necesssary to change the filenames in 'CF input' or 'CF restart'.
87+
! At most one file should be listed in the 'CF restart' section, and it should contain the string 'restart' or '.r.'
88+
! If model%options%is_restart = STANDARD_RESTART and there is no 'CF restart' section, then the model will restart
8889
! from the file and time slice specified in the 'CF input' section. (This is the old Glimmer behavior.)
90+
!
91+
! If model%options%is_restart = HYBRID_RESTART, then the file listed in 'CF input' is used to initialize the model.
92+
! This file should be a restart file from a previous run (e.g., a long ice-sheet spin-up),
93+
! which provides the initial ice state for the hybrid run.
94+
! The differences from STANDARD_RESTART (besides the config section where the filename is given) are
95+
! (1) tstep_count is set to 0, replacing the value in the CF input file.
96+
! (2) model%numerics%time is set to tstart from the config file, replacing the value in the CF input file.
8997

9098
! get config string
9199
call ConfigAsString(config,configstring)
@@ -135,7 +143,7 @@ subroutine glimmer_nc_readparams(model,config)
135143
end do
136144

137145
! set up restart input
138-
if (model%options%is_restart == RESTART_TRUE) then
146+
if (model%options%is_restart == STANDARD_RESTART) then
139147

140148
! If there is a 'CF restart' section, the model will restart from the file listed there (if it exists).
141149
! Else the model will start from the input file in the 'CF input' section.
@@ -187,7 +195,7 @@ subroutine glimmer_nc_readparams(model,config)
187195

188196
endif ! associated(section)
189197

190-
endif ! model%options%is_restart = RESTART_TRUE
198+
endif ! model%options%is_restart
191199

192200
! setup forcings
193201
call GetSection(config,section,'CF forcing')

0 commit comments

Comments
 (0)