Skip to content

Checkpoint and restart a multistep run ​

The leapfrog is a two-step method: its state is q and the history the stepper keeps, the filtered Un−1. A checkpoint saves both; a restart writes both back and declares the history valid for the step. The run then continues bitwise. Tutorial 15 is the long form (the start-up, the computational mode, a change of step); the rules: Stepper.

The recipe on a forced 1-D advection, qt=−qx+0.1cos⁡2πt, leapfrog-raw: 20 steps, a checkpoint file, a new stepper restarted from it, 20 more steps, against 40 steps uninterrupted.

fortran
call st%initialize(SCHEME_LEAPFROG_RAW, FORM_LEAPFROG, lb=[0], ub=[NC+1], components=.false.)
call initial(q, t)
call advance(st, q, t, NSTEPS/2)
call st%history_view(h)                                          ! the filtered U^{n-1}, with the field's bounds
open(newunit=unit, file='leapfrog.chk', access='stream', form='unformatted', status='replace')
write(unit) t, DT, q, h                                          ! the state of a leapfrog run is q AND its history
close(unit)
call st%destroy
fortran
call st%initialize(SCHEME_LEAPFROG_RAW, FORM_LEAPFROG, lb=[0], ub=[NC+1], components=.false.)  ! a new run
call st%history_view(h)
open(newunit=unit, file='leapfrog.chk', access='stream', form='unformatted', status='old')
read(unit) t, dts, q, h                                          ! the history written back into the stepper
close(unit)
call st%resume_history(dts)                                      ! valid for steps of dts: no start-up
call advance(st, q, t, NSTEPS/2)
fortran
call st%begin_step(bx, q)
do k=1, st%stages()                                        ! 2 at the start-up (ssp-22), 1 after
   call st%begin_stage(k, bx, DT, q)                       ! the stage state is q in this form
   call st%rhs_register_view(r)
   call residual(q, t + st%stage_time(k) * DT, r)
   call st%end_stage(k, bx, DT, q)
enddo
call st%finish_step(bx, DT, q)
t = t + DT
text
$ cookbook_checkpoint
restarted at step 20, run to step 40: bitwise the uninterrupted run: T
restarted without the history: max |q - q_uninterrupted| =  1.93E-04
ab-3: restarted at step 20, run to step 40: bitwise the uninterrupted run: T
[exit status 0]
  • Save after finish_step. history_view(h) gives the history at the field's rank and bounds (history() is the rank-5 pointer). Save it with q, as they are: q is the singly filtered Un, the history the doubly filtered Un−1.
  • Save dt and t. resume_history(dt) declares the history valid for steps of dt; a leapfrog step of another dt stops the program. The residual's time comes from your clock plus stage_time(k) * dt: 0 for a leapfrog stage, 0 and 1 for the start-up's two stages.
  • Restart into a new stepper. initialize, write the history through history_view(h), then resume_history(dt): stages() is 1 at once, no start-up.
  • Without the history the restart is a start-up from q alone: a different run, the last line of the output.
  • A new dt (a CFL limit, a regrid that does not prolong the history): restart_history() and a start-up.

Every level of a multistep scheme ​

ab-3 keeps two residual levels, Rn−1 and Rn−2 (Stepper: the history): the checkpoint saves q and each level, history_levels() of them, and the restart writes each back before resume_history(dt). Here the history at the start is the caller's: two ssp-33 steps from U0, the residual of each state they start from written into the level it will be. Without it the stepper starts the run itself with its built-in start-up (Stepper: the history); writing it by hand is the way past ab-11, whose order no start-up scheme of the catalogue reaches.

fortran
call rk%initialize(SCHEME_SSP_33, FORM_SHU_OSHER_2R, lb=[0], ub=[NC+1], components=.false.)
do j=st%history_levels(), 1, -1
   call st%history_view(h, j)
   call residual(q, t, h)                                     ! R(t^m, U^m) into the level it will be
   call advance(rk, q, t, 1)
enddo
call st%resume_history(DT)
call rk%destroy
fortran
call st%initialize('ab-3', FORM_MULTISTEP, lb=[0], ub=[NC+1], components=.false.)
call initial(q, t)
call start_up(q, t)                                              ! two ssp-33 steps; the history written by hand
call advance(st, q, t, NSTEPS/2 - 2)
open(newunit=unit, file='ab3.chk', access='stream', form='unformatted', status='replace')
write(unit) t, DT, q
do j=1, st%history_levels()                                      ! ab-3: R^{n-1} and R^{n-2}
   call st%history_view(h, j)
   write(unit) h
enddo
close(unit)
call st%destroy
fortran
call st%initialize('ab-3', FORM_MULTISTEP, lb=[0], ub=[NC+1], components=.false.)
open(newunit=unit, file='ab3.chk', access='stream', form='unformatted', status='old')
read(unit) t, dts, q
do j=1, st%history_levels()
   call st%history_view(h, j)
   read(unit) h
enddo
close(unit)
call st%resume_history(dts)
call advance(st, q, t, NSTEPS/2)

The last line of the output above is this run: bitwise. The loop over the levels is the same for every multistep scheme; only history_levels() changes.