Checkpoint and restart a multistep run
The leapfrog is a two-step method: its state is
The recipe on a forced 1-D advection, leapfrog-raw: 20 steps, a checkpoint file, a new stepper restarted from it, 20 more steps, against 40 steps uninterrupted.
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%destroycall 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)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$ 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 withq, as they are:qis the singly filtered, the history the doubly filtered . - Save
dtandt.resume_history(dt)declares the history valid for steps ofdt; a leapfrog step of anotherdtstops the program. The residual's time comes from your clock plusstage_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 throughhistory_view(h), thenresume_history(dt):stages()is 1 at once, no start-up. - Without the history the restart is a start-up from
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, 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 ab-11, whose order no start-up scheme of the catalogue reaches.
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%destroycall 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%destroycall 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.