Stepper
SELAH's L2 layer is the stepper (type(stepper)): one time step that the caller drives one stage at a time. The stepper owns the registers and the coefficients. The caller owns the solution, the time loop, the ghost cells and the residual. The stepper never calls back.
A step
use selah
type(stepper) :: st
call st%initialize(SCHEME_SSP_54, FORM_BUTCHER, lb=lbound(q), ub=ubound(q))
! ... every step:
call st%begin_step(bx, q)
do k=1, st%stages()
call st%begin_stage(k, bx, dt, q)
! the stage state: q itself when st%stage_state_is_q(k), else st%stage_state()
! fill its ghost cells (exchange, seams, boundaries), then write its residual into st%rhs_register()
call st%end_stage(k, bx, dt, q)
enddo
call st%finish_step(bx, dt, q) ! the Butcher form can also return the step residual: dq=...
! ... at the end:
call st%destroyOne step, four calls, two owners
Whatever the scheme or the storage form, a step is the same sequence. You own the solution, its ghosts and the residual; SELAH owns the registers and every update rule.
- begin_step(bx, q): SELAH copies qⁿ where the form needs it.
- For k from 1 to stages(): begin_stage(k, bx, dt, q), where SELAH builds the stage state (Butcher form; the others keep it in q).
- Inside the stage window, you evaluate on q or stage_state(), fill the ghost cells of the stage state, and write the residual into rhs_register().
- end_stage(k, bx, dt, q): SELAH advances q in place in the 2R, 2N, Ketcheson, splitting, leapfrog, linear SSP forms; then the next k.
- finish_step(bx, dt, q): the Butcher update (and dq); the leapfrog keeps its history. You reflux with stage_weight(k).
- Outside the stage window, stage_state() and rhs_register() are null.
Every call takes the box (see Concepts), and all four step calls take an optional mask and mask_comp. Pass the same mask to all four. A splitting also needs its two partitions (partitions=), and for each flow stage_partition(k) says which partition to compute the residual of. The rules the two sides keep are the stage contract.
Procedures
| Procedure | What it does | Preconditions and notes |
|---|---|---|
initialize(scheme, form, lb, ub [, partitions] [, registers] [, stages_on_q] [, components] [, masked_q] [, nu, alpha] [, iterations] [, fsal]) | sets the scheme and form for a field of rank size(lb) (1 to 5); allocates registers_needed(scheme, form) registers with the bounds lb:ub through FUNDAL (device memory in a device build), or takes the caller's | stops if the scheme has no such form, or a splitting comes without partitions. partitions(:,p) = (v1, v2), the components of partition p. components is required below rank 5 (fields of rank 1 to 4). registers (see below), for rank 5 only. masked_q: the mask policy. nu, alpha: the leapfrog's filter, that form only. iterations: an implicit multistep scheme's fixed-point stages, that family only. fsal: residuals already in their register, a first-same-as-last scheme in the Butcher form only. Calls destroy first, so a stepper can be re-initialised |
begin_step(bx, q [, mask, mask_comp]) | opens a step: the two-register and Ketcheson forms keep a copy of | |
begin_stage(k, bx, dt, q [, mask, mask_comp] [, decay]) | opens stage k: the Butcher form builds its state into its register (unless stage_state_is_q(k)) | k from 1 to stages(), in order; decay: a decay integrated exactly |
stage_state() | pointer to the stage state, with the field's bounds | Butcher form only; null on a stage evaluated on q, and always null in the other forms (their state is q). Null outside a stage window (before begin_stage, after end_stage) |
rhs_register() | pointer to the register the caller writes the residual of the active stage into, with the field's bounds | write the cells of the box; for a splitting, the components of stage_partition(k). Null outside a stage window (before begin_stage, after end_stage) |
stage_state_view(u), rhs_register_view(r) | the same two pointers at the field's rank: u and r are pointers of rank 1 to 5 | null exactly when stage_state() and rhs_register() are; the rank must be the field's |
end_stage(k, bx, dt, q [, mask, mask_comp]) | closes stage k: the two-register, 2N, Ketcheson and splitting forms advance q here | |
step_error(bx, dt, q, atol, rtol, emax, esum, ncells [, mask, mask_comp] [, second]) | after the last end_stage and before finish_step, for an embedded pair (with second=.true., its second estimate, dopri-853 and bs-54): the scaled error $\Delta t \sum_k (b_k - \hat b_k) R_k / (\mathrm{atol} + \mathrm{rtol}\max( | q^n |
dense_output(theta, bx, dt, q, u [, mask, mask_comp]) | after finish_step, the solution at begin_step; | Butcher form, a scheme with b_dense (dopri-54), not after decay=; the multistep form of ab-k: its interpolant of order k from the residual history; Dense output |
hermite_output(theta, bx, dt, q, u [, r_end] [, mask, mask_comp]) | after finish_step, Hermite's cubic through | Butcher form, any scheme; r_end = |
reject_step(bx, q [, mask, mask_comp]) | after step_error rejects a step, before it starts again: puts q in the two-register form, which advanced q in place (from its copy of q | the forms step_error takes; a loop that calls it on every rejection runs either form unchanged |
step_constraint(bx, dt, q, constraints, ratio) | after the last end_stage, before finish_step: the smallest ratio of the step keeping each constrained component of constraints(v) is CONSTRAINT_NONE, CONSTRAINT_NONNEGATIVE, CONSTRAINT_POSITIVE, CONSTRAINT_NONPOSITIVE or CONSTRAINT_NEGATIVE | Butcher form; reduce ratio (a minimum) over the boxes and ranks; An adaptive step |
finish_step(bx, dt, q [, dq] [, mask, mask_comp] [, decay]) | closes the step: the Butcher form computes dq | dq with any form other than Butcher stops the program; dq is 0 where the mask is inactive |
stage_state_is_q(k) | the state of stage k is q itself: evaluate its residual on q | true for every stage of the forms other than Butcher; for the zero rows of A with stages_on_q |
stage_needs_residual(k) | the residual of stage k must be evaluated: false when it is already in its register | stage 1 of the Butcher form only: a step begun again, and with fsal the step after an accepted one (residuals already in their register); writing it anyway gives the same step |
first_same_as_last() | the scheme's last stage is the next step's first: explicit, | dopri-54, calvo-65 |
invalidate_residuals() | forget the residuals kept for the next step | after changing q between steps, or abandoning a step |
initial_step_norms(bx, q, atol, rtol, parts, ncells [, mask, mask_comp]), initial_step_probe(bx, h0, q [, mask, mask_comp]), initial_step_difference(bx, h0, q, atol, rtol, dmax, dsum, ncells [, mask, mask_comp]) | the starting step's norms of rhs_register()), the norm of | Butcher form, two stages or more, after stage 1 of the first step: Step control: the starting step |
stages() | the stages of a step (the flows of a splitting) | |
stage_time(k) | the fraction of the step at which the residual of stage k is evaluated: the abscissa | for a splitting, the fractions of the other partition's flows before flow k: see Time-dependent residuals |
stage_weight(k) | the effective Butcher weight k | in every Runge–Kutta form, the low-storage ones included |
stage_partition(k) | the partition flow k advances (1 or 2) | 0 for a Runge–Kutta form |
stage_euler_fraction(k) | the forward-Euler step stage k's residual takes, as a fraction of dt: | the step a limiter must make admissible: see Limiters. 0 when the scheme is not SSP; a splitting's flow: |
imag_axis_bound(), real_axis_bound() | the largest imag_axis_bound(), a decay of rate real_axis_bound() | from the stability polynomial of the tableau; 0 for a splitting. euler and ssp-22 have no imaginary-axis interval (0) |
ssp_coefficient() | the SSP coefficient | 0 when the scheme is not SSP, and for a splitting; |
state_aliases_q() | the form keeps the stage state in q (every form but Butcher) | the per-stage stage_state_is_q(k) generalises it |
lookahead(k, bx, dt, q, u) | in the window of stage k, after its residual: k+1 (the step's result at the last stage) | Butcher form, any rank; see Charge-conserving stage currents |
stage_current(k, bx, h, jr, jk), stage_current_admissible() | jr, the caller's registers) is h; whether every | Butcher form, rank 5; stops on an inadmissible scheme |
initialize_companion(field, lb, ub [, partitions] [, registers] [, components]) | a stepper of the scheme, form and stages on q of the stepper field, for another state that advances with the field | see Companion states |
history([level]), history_view(h [, level]) | a level of the history, with the field's bounds (rank 5, rank k); level 1 by default (the leapfrog's filtered | null outside the history forms and past history_levels() |
history_levels() | the levels of the history: | 0 outside the history forms |
history_is_ready(), restart_history(), resume_history(dt), resume_history(dts) | whether the next step is the scheme's own (not a start-up step); forget the history (the next steps are start-up steps); declare the history written back valid for steps of dt (or made with the steps dts, the newest first) | history forms (leapfrog, multistep) |
history_step(j) | 0 outside the multistep form | |
stage_gamma(k) | the coefficient of the implicit term of stage k, as a fraction of dt: a fixed-point stage's state approximates the solution of stage_gamma(k) | 0 for every explicit stage (every stage of the explicit schemes, stage 1, a start-up step) |
explicit_part(), explicit_part_view(e) | the explicit part | made at begin_stage(2) (at finish_step for a one-stage step), valid until finish_step; null for the explicit schemes |
destroy() | frees what the stepper owns | no finalizer: call it |
Fields of rank 1 to 4
initialize takes the bounds of a field of any rank from 1 to 5. Below rank 5 it also takes components: whether the field's first dimension holds its components. The field is then viewed as rank 5 with singleton dimensions (the box). The four step procedures are generic over the rank of q, and dq and mask have q's rank. The box must be built at the field's rank:
real(R_P), pointer :: q(:), u(:), r(:) ! a scalar 1-D field q(0:n+1), one ghost cell each side
type(box) :: bx
bx = box_interior(lb=[0], ub=[n+1], ngc=1, components=.false.)
call st%initialize(SCHEME_SSP_33, FORM_SHU_OSHER_2R, lb=[0], ub=[n+1], components=.false.)
call st%begin_step(bx, q)
do k=1, st%stages()
call st%begin_stage(k, bx, dt, q)
if (st%stage_state_is_q(k)) then ; u => q ; else ; call st%stage_state_view(u) ; endif
call st%rhs_register_view(r)
call residual(u, r) ! yours
call st%end_stage(k, bx, dt, q)
enddo
call st%finish_step(bx, dt, q)- No copy. A lower-rank
qreaches the rank-5 procedures as the rank-5 array it is in memory, through an explicit-shape dummy, with no copy when it is contiguous. In a device build it must be contiguous. - Checked at every call: the box and the stepper have
q's rank, andqhas the bounds given toinitialize. - The views.
stage_state()andrhs_register()keep their rank-5 result. A function cannot be generic on the rank of its result, so the rank-k pointers are the subroutinesstage_state_view(u)andrhs_register_view(r), with the field's bounds. - The stage contract is unchanged at every rank. Its clauses apply to the cells of the box, whatever the rank.
- Caller registers (
registers=) are for rank-5 fields only.
The caller's registers
initialize(..., registers=pool) takes the registers from the caller instead of allocating them. The stepper checks two things and stops on a mismatch:
- the array is rank 6 and contiguous, with the field's bounds
lb:ubon dimensions 1–5; - its slots are numbered from 1 on dimension 6, and there are at least
registers_needed(scheme, form)of them.
It cannot check the rest:
- the actual must be a pointer or a target;
- in a device build it must be device memory;
- two steppers in use at the same time need two pools.
The stepper never frees a caller's pool, and does not need it zeroed: no form reads a register before writing it (C3).
Stages on q
The state of a stage whose row of A is zero is q itself: the first stage of every explicit scheme (in SELAH's catalogue, the only one). By default the Butcher form still copies it into its stage-state register. With stages_on_q=.true. it does not:
call st%initialize(SCHEME_SSP_54, FORM_BUTCHER, lb=lbound(q), ub=ubound(q), stages_on_q=.true.)
! ...
do k=1, st%stages()
call st%begin_stage(k, bx, dt, q)
if (st%stage_state_is_q(k)) then
u => q ! stage 1: fill the ghost cells of q, evaluate the residual on q
else
u => st%stage_state()
endif
! ... ghost fill and residual of u into st%rhs_register()
call st%end_stage(k, bx, dt, q)
enddoDuring such a stage stage_state() is null, so a caller that does not ask stage_state_is_q(k) fails at once instead of reading a stale register. The caller then writes the ghost cells of q at stage 1 (contract clause 3), which the plain Butcher form leaves alone. The solution is bitwise that of the plain Butcher form. On the A30 the option takes 6% off the integrator's SSP(5,4) step (Performance).
Residuals already in their register
Two of the Butcher form's stage-1 residuals are known before their stage, and stage_needs_residual(k) says so:
- A step begun again. After a rejected step (its stages and
step_errordone, nofinish_step),begin_stepopens the step again on the sameq. Stage 1, whose row of A is zero, has the same state and time whatever the newdt: its residual is still in its register. Every scheme, no option. - First same as last (
fsal=.true.,first_same_as_last()schemes:dopri-54,calvo-65). The last stage's state isand its time : its residual is the next step's first, and begin_stepcopies it into stage 1's register. Without the option the stepper keeps nothing across steps.
call st%initialize(SCHEME_DOPRI_54, FORM_BUTCHER, lb=lbound(q), ub=ubound(q), fsal=.true.)
! ...
do k=1, st%stages()
call st%begin_stage(k, bx, dt, q)
if (st%stage_needs_residual(k)) then
! ... ghost fill and residual of the stage state into st%rhs_register()
endif
call st%end_stage(k, bx, dt, q)
enddoThe stepper cannot see q change between steps. A caller that changes it (a limiter after the step, a regrid, another flow of a splitting, a step abandoned) calls invalidate_residuals() first, and stage 1 is evaluated again. A caller that does not ask stage_needs_residual writes the residual anyway and gets the same step: bitwise for a step begun again, and to rounding for the first-same-as-last stage, whose state and decay=. selah_test_fsal: 6 and 8 evaluations per step for dopri-54 and calvo-65 instead of 7 and 9, the solution after 100 steps bitwise that of the run evaluating every stage;
Companion states
A state that advances with the field in the same step, its residual built inside the field's at each stage (particles pushed by the fields of each stage, the auxiliary fields of a perfectly matched layer), is the same scheme applied to another state. A companion is a second stepper with the field stepper's scheme, form and stages on q, driven by the same calls in the same stage window:
call st%initialize(SCHEME_SSP_54, FORM_BUTCHER, lb, ub) ! the field
call sp%initialize_companion(st, lb=[1, 1], ub=[8, np_max], components=.true.) ! the particles, (8, np_max)
! each step, n particles active, components 1:6 evolving
bp = box_range(lb=[1, 1], lo=[1, 1], hi=[6, n], components=.true.)
call st%begin_step(bx, q) ; call sp%begin_step(bp, p)
do k=1, st%stages()
call st%begin_stage(k, bx, dt, q) ; call sp%begin_stage(k, bp, dt, p)
! the residuals of both: the particles' from the stage fields, the field's from the stage particles
call st%end_stage(k, bx, dt, q) ; call sp%end_stage(k, bp, dt, p)
enddo
call st%finish_step(bx, dt, q) ; call sp%finish_step(bp, dt, p)
! then what the caller does on the final state: particle wrap and migrationThe companion's bounds are a capacity; the box of each call is the active part: the particles 1..n of a pool whose n changes between steps, the components that evolve (charge and mass, components 7:8, stay as they are). The kernels never touch the rest. A layout with the particles first, (np, 8) (the device's), is a rank-2 field with components=.false. whose box ranges over 1:n and 1:6. Re-initialise the companion when its shape changes (a regrid): between steps its registers are scratch. Stepped together, field and companion are bitwise the two stepped as one state (selah_test_companion, every form). The stage window of the two must coincide: a companion's stage state and residual register are, like the field's, null outside it.
A decay integrated exactly
For a state decay (an array of the state's shape) at every begin_stage and at finish_step, and write the source
call sp%begin_stage(k, bp, dt, psi, decay=lambda) ! psi: a companion of the field stepper
! ... the residual: g = (sigma/kappa^2) d_n F only, without -lambda psi
call sp%finish_step(bp, dt, psi, decay=lambda)With dq.
The source is stiff too (notes/companions-pushers-pml.md §5 has the coupled limits of the catalogue).
Masks
With mask present the kernels update the active cells only: a cell is active where mask(..., mask_comp) < 0 (ADAM's immersed-boundary distance, negative in the fluid; mask_comp defaults to the last component). The masked cells of q keep their values through the step, in every form.
The stage state is another matter. The forms other than Butcher keep it in q, so its masked cells hold
call st%initialize(scheme, FORM_BUTCHER, lb, ub, masked_q=.true.)and the masked cells of every stage state then hold begin_stage (ADAM's adapter did so before szaghi/adam#134; selah_test_stepper_options). Default .false.: the register's masked cells are left untouched. A caller whose masked cells must evolve within the step (ghost values of an immersed boundary rebuilt from the fluid at every stage) still writes them itself, between begin_stage and its residual.
Time-dependent residuals
A residual that depends on time (boundary conditions, sources, forcing) is evaluated at t + st%stage_time(k)*dt:
do k=1, st%stages()
call st%begin_stage(k, bx, dt, q)
! ... the residual of the stage state at time t + st%stage_time(k)*dt into st%rhs_register()
call st%end_stage(k, bx, dt, q)
enddo
call st%finish_step(bx, dt, q)
t = t + dtIn a Runge–Kutta form stage_time(k) is the abscissa stage_time(k) is therefore the sum of the fractions of the other partition's flows before flow stage_time is selah_test_nonautonomous).
When both partitions' residuals depend on time, no sub-flow is exact and no stage time gives the composition's order: split the problem so that one partition's residual is autonomous.
Limiters and forward-Euler steps
A strong-stability-preserving (SSP) scheme is a convex combination of forward-Euler steps. In its Shu–Osher form, stage
so the residual of stage stage_euler_fraction(k)
do k=1, st%stages()
call st%begin_stage(k, bx, dt, q)
! ... the residual of the stage state into st%rhs_register()
tau = st%stage_euler_fraction(k) * dt
! ... the limiter: the state of stage k plus tau times its residual admissible (a source term time-centred within
! that forward-Euler step at tau/2)
call st%end_stage(k, bx, dt, q)
enddo| Scheme | ||
|---|---|---|
euler, ssp-22, ssp-33 | 1 every stage | 1 |
ssp-54 | 0.3918, 0.6631, 0.6631, 0.6631, 0.5844 | 1.508 |
ssp-104 | 1/6 every stage | 6 |
rk4, lsrk-33, lsrk-54 | 0 (not SSP: no positivity guarantee) | 0 |
Taking selah_test_stage_euler: the decay ssp_coefficient() times the forward-Euler limit of the residual.
Leapfrog
FORM_LEAPFROG (schemes) is the one form whose registers are not scratch after finish_step: its history, the filtered
- Start-up. The first step after
initializeorrestart_history()has no. It is one ssp-22step in the two-register form:stages()is 2 for that step (stage_time0 and 1) and 1 afterwards, so askstages()at every step, as the loop above does. The start-up keeps the global order 2 and excites the computational mode aton an oscillation. - A constant step. A leapfrog step with a
dtother than the start-up's stops the program. Whendtchanges (a CFL limit), callrestart_history(): the next step is a start-up with the newdt. - What
qholds. Afterfinish_step,qis the singly filtered, offset from the solution by (schemes); the history is the doubly filtered . Both are the state: a checkpoint saves both, as they are. - Checkpoints. Save
qandhistory()(history_view(h)below rank 5) afterfinish_step; to restart, write both back and callresume_history(dt). The run continues bitwise. - Regrids. Prolong the history with
qand callresume_history(dt), or callrestart_history(). - Queries.
stage_time0;stage_weight0 (the filtered step is not a weighted sum of residuals, so a flux register cannot telescope it);stage_euler_fraction0 (1 on the start-up's stages);ssp_coefficient0;imag_axis_boundandreal_axis_boundthose of the filter. - Not with the leapfrog.
decay=,dq,lookaheadandstage_currentare the Butcher form's. A mask works as in the other forms; a masked cell's history is left untouched. A companion (initialize_companion) takes the field's filter.
The history
FORM_MULTISTEP runs the linear multistep schemes (schemes): ab-<k>. A step of a lmm_history). The stepper keeps them in two rings of registers, which survive finish_step and are part of the solution's state, as the leapfrog's history is.
- One stage, one residual. Stage 1 is evaluated on
q(, at stage_time0); its residual, written intorhs_register(), isat the head of the residual ring. A multistep-multistage scheme ( msrk-ssp-*) has more stages: stageis built at begin_stagein the stage-state register (stage_state_is_q(k)false) from the levels and the stage residuals of this step, its residual written into its own register.finish_stepformsin one pass over the box, writing into the solution ring as it goes, and the rings turn by one index. Nothing is copied, and no residual is evaluated twice (FOODIE's Adams–Bashforth evaluated all of them at every step). - The order of the sums is the order of the levels, newest first, whatever slot the ring puts each level in: the slots of every phase of the rings are tabulated at
initialize(on the device in a device build), and the kernelselah_historyreads them. So a run restarted from a checkpoint, whose rings start at another phase, is bitwise the uninterrupted run. - The levels.
history_levels()is; level is , level is , with the state qholds (afterfinish_step, the history of the next step).history_view(h, level)gives each at the field's rank and bounds.ab-<k>:residual levels, no solution level. - Start-up. The first steps after
initializeorrestart_history()have no history. Until the history holds every level, each step is a step of the built-in start-up scheme,multistep_starter(scheme): the catalogue's explicit Runge–Kutta scheme of fewest stages with order( starter_for_order:euler,ssp-22,ssp-33,rk4orssp-54when SSP,cash-karp-54,calvo-65,feagin-108up to order 10), which keeps the global order. stages()is the starter's for those steps (ask it at every step),stage_timeits abscissae,stage_euler_fractionits fractions; its stages past the first have their state in the stage-state register (stage_state_is_q(k)false,state_aliases_q()false for this form). The residual of each starting state, its stage 1, enters the residual ring as it is evaluated: no residual is evaluated twice.ab-<k>takessuch steps, with the starter's stage registers on top of the rings in registers_needed(ab-5:rk4, 5 + 4 registers). Past order 11 (ab-12toab-16) no starter has the order: the caller writes the history, each level throughhistory_view, thenresume_history(dt)(Checkpoint shows twossp-33steps doing it by hand), and a step before that stops the program. Either way the start-up steps keep onedt. - A constant step. A step with a
dtother than the history's stops the program (D7 of #10: the coefficients are those of a constant step). Whendtchanges,restart_history(), and a new history. The variable-step SSP schemes (lmm-ssp-vss-*) are the exception: they keep the steps that made their levels and recompute their coefficients from the step ratios at every step (one small device copy when they change, none at a constant step);ssp_coefficient()andstage_euler_fraction(1)follow. - Checkpoints. Save
qand every level afterfinish_step; to restart, write them back into a new stepper and callresume_history(dt). The run continues bitwise. A variable-step scheme also saves its steps,history_step(j)for( , the newest first), and resumes with resume_history(dts). - Regrids. Prolong
qand every level, thenresume_history(dt)(AMR); orrestart_history(). - Queries.
stage_weight0 (the step is not a weighted sum of this step's residuals: no flux telescoping);stage_euler_fraction0 andssp_coefficient0 forab-<k>,and for the SSP schemes; imag_axis_boundandreal_axis_boundfrom the root condition (lmm_imag_axis_bound,lmm_real_axis_bound). - Not in this form.
decay=,dq,lookaheadandstage_currentare the Butcher form's. A mask works as in the other forms: a masked cell's levels are left untouched. The leapfrog's own form,FORM_LEAPFROG, keeps its history with the same calls (one solution level, rings of length 1) and its own filtered step.
Fixed-point stages
The implicit multistep schemes (schemes: am-<k>, abm-<k>, bdf-<k>) advance
by
- The stages. Stage 1 is on
q(, at stage_time0); its residualis the residual ring's head and also the first iteration's residual, as the iterations start from . begin_stage(2)makesonce, one pass over the levels into its register, and the first iterate . Every later stage's state is , made in place over that residual by selah_lincomb(two registers, by turns state and residual: 3 streams per iteration).finish_stepwrites, into the solution ring. So stages()and residuals per step; no residual of the history is evaluated again (FOODIE's defect F4). Every iterate is at ( stage_time1). A predictor-corrector (abm-<k>) has one more stage: stage 2's state is the predictor's step (multistep_predictor), the iterations start from it,stages(). - The iterations,
initialize(..., iterations=m): by defaultmultistep_iterations(scheme), the fewest that keep the scheme's order. Fromeach iteration gains one order, so am-<k>(order) takes and bdf-<k>(order) ; abm-<k>starts from a prediction of its order and takes 1. FOODIE's default is 1, a first-order step for everyam-<k>;iterations=1reproduces it. - Where they converge. The iterations contract where
for the eigenvalues of the residual's Jacobian; a stiff problem diverges, as FOODIE's does. imag_axis_bound()andreal_axis_bound()are those of the step theiterations make ( fixed_point_imag_axis_boundandfixed_point_real_axis_boundof Schemes), not the converged scheme's:am-1(the trapezoid rule, A-stable) iterated twice is Heun's method, real-axis bound 2, imaginary 0. - A solver of your own (D9 of #10).
stage_gamma(k)isfor the fixed-point stages ( stage_gamma(k); 0 for stage 1 and every explicit stage),explicit_part()(explicit_part_view(e)) isfrom begin_stage(2)tofinish_step. A caller who solvesby its own Newton iteration writes the solution into stage_state()of a fixed-point stage before evaluating the residual there; withiterations=2, stage 2 is the last one, and the updatereturns to its rounding. The solver stays the caller's (P2): A step of your own. - Solvers for that stage (#11, D1: objects the caller drives inside the stage, the stage contract unchanged):
newton_solver(Newton cell by cell, for terms that couple the components of one cell),anderson_mixing(Anderson's acceleration of the iterations: no Jacobian, one residual and one reduction per iteration, converging where they diverge), newton_krylov(Newton–GMRES, matrix-free, for terms that couple the cells far beyond the explicit bound) (Stiff terms). - Registers. Two stage registers and
on top of the rings: am-1, 4 (registers_needed). The start-up, the history, checkpoints and a change ofdtare those of the history.
Forms
| Form | Registers | Schemes |
|---|---|---|
FORM_BUTCHER | s + 1 | every Runge–Kutta scheme |
FORM_SHU_OSHER_2R | 2 (3) | euler, ssp-22, ssp-33; ssp-43 with its error accumulator |
FORM_WILLIAMSON_2N | 2 | lsrk-33 to lsrk-144 |
FORM_KETCHESON_2R | 2 | ssp-104 |
FORM_SPLITTING | 1 | every splitting |
FORM_LEAPFROG | 2 | leapfrog, leapfrog-raw |
FORM_LINEAR_SSP_2R | 2 | lssp-<s>, lssp-<s>-1 |
FORM_MULTISTEP | ab-<k>, lmm-ssp-*, lmm-ssp-vss-*, msrk-ssp-*, am-<k>, abm-<k>, bdf-<k> |
What each register holds, and where each form does its work: Concepts.
The Nordsieck form, variable-step Adams and BDF, is an object of its own, nordsieck_stepper, with the same stage contract and nystrom_stepper,
Exponential stages: the Magnus form
A linear non-autonomous system
with the magnus_stepper (selah_magnus), driven by its caller through requests, as newton_krylov is (Stiff terms). The library never sums over boxes or ranks: what needs a global sum is asked of the caller.
| Procedure | What it does |
|---|---|
initialize(scheme, lb, ub, action [, ncomp] [, m] [, tol] [, skew]) | the scheme (MAGNUS_SCHEMES), the field's bounds (rank 5), the action of the exponentials: MAGNUS_DENSE, MAGNUS_KRYLOV or MAGNUS_CALLER; ncomp, the block size of the dense action (MAGNUS_MAX_BLOCK = 16); m, the largest Krylov space (MAGNUS_MAX_KRYLOV = 16, default 16); tol, the Krylov action's error per unit step, relative to skew, the operator is skew-symmetric (the Lanczos structure imposed) |
nodes(), exponentials(), node_time(k), weight(j, k) | |
begin_step(bx, h, q) | a step of h on the caller's state q (a pointer with the field's bounds, updated in place); the first request |
request() | the pending request (below), MAGNUS_DONE when q is |
advance(bx) | the request answered: on to the next |
node(), block_register() | MAGNUS_NODE: the node blk(cell, v, w) = newton_solver's blocks) |
exponential(), apply_in(), apply_out() | MAGNUS_APPLY: apply_out() apply_in(), exponential(); MAGNUS_ACTION: q q by the caller |
sums(1:nsums) | MAGNUS_REDUCE: the partial sums to add over the boxes and ranks |
krylov, reductions, reorthogonalisations, applications, substeps | the Krylov action's counts in the step: iterations, MAGNUS_REDUCE requests (iterations + reorthogonalisations + 1), second Gram–Schmidt passes, MAGNUS_APPLY requests, sub-steps ( |
destroy() | frees the registers |
The requests.
MAGNUS_NODE,times at the step's start, = node(): whateverneeds (the dense action: the blocks into block_register(); the other actions: the caller's own data at that time, or nothing).MAGNUS_APPLY(Krylov): the operator of exponentialapplied to a vector. One per Krylov iteration. MAGNUS_REDUCE(Krylov): a sum over the boxes and ranks. One per Krylov iteration (the inner products with the basis and the new vector's own, fused), one more when the new vector is reorthogonalised, one per step for. MAGNUS_ACTION(the caller's action): exponential= exponential()applied toqin place,times in order.
The registers. Dense: ncomp
The Krylov action. Exponential MAGNUS_APPLY and one MAGNUS_REDUCE per iteration (classical Gram–Schmidt: the tol skew=.true. the skew-tridiagonal (Lanczos) structure is imposed on selah_test_magnus: a 1-D advection of 64 cells, cf4-2, 100 steps, within notes/magnus-reference.py, 30 digits), the norm within
The three loops this contract serves
A rotation at a varying rate, per cell (MAGNUS_DENSE, ncomp = 2, the components first):
call mg%initialize('cf4-2', lb, ub, MAGNUS_DENSE, ncomp=2)
call mg%begin_step(bx, h, q)
do while (mg%request() /= MAGNUS_DONE)
select case (mg%request())
case (MAGNUS_NODE) ! A = omega(t) [[0, -1], [1, 0]] in every cell
blk => mg%block_register() ; t = time + mg%node_time(mg%node()) * h
blk(1,:,:,:,:,1) = 0._R_P ; blk(1,:,:,:,:,2) = -omega(t)
blk(2,:,:,:,:,1) = omega(t) ; blk(2,:,:,:,:,2) = 0._R_P
endselect
call mg%advance(bx)
enddoA driven two-level system in real form, per cell (MAGNUS_DENSE, ncomp = 4): the same loop, the block
A coupled operator by Krylov (MAGNUS_KRYLOV, skew=.true.): a 1-D advection
call mg%initialize('cf4-2', lb, ub, MAGNUS_KRYLOV, skew=.true.)
call mg%begin_step(bx, h, q)
do while (mg%request() /= MAGNUS_DONE)
select case (mg%request())
case (MAGNUS_APPLY) ! out = sum_k a_jk A(t_k) in = -(sum_k a_jk c(t_k)) D in
w = 0._R_P
do k=1, mg%nodes()
w = w + mg%weight(mg%exponential(), k) * speed(time + mg%node_time(k) * h)
enddo
x => mg%apply_in() ; y => mg%apply_out()
call exchange_ghosts(x) ! the caller's halo exchange
call centred_derivative(bx, -w, x, y)
case (MAGNUS_REDUCE)
call mpi_allreduce(MPI_IN_PLACE, mg%sums, mg%nsums, MPI_DOUBLE_PRECISION, MPI_SUM, comm, ierr)
endselect ! MAGNUS_NODE: nothing to prepare
call mg%advance(bx)
enddoEach loop uses only the procedures above; the global sum is the caller's mpi_allreduce (nothing to do with one box on one rank), and scripts/check_separation.py keeps MPI out of the library.
Verification
| What | Case |
|---|---|
| every scheme reaches its order in every form, through the stepper | A3 |
| the stage contract, stages on q, masks, caller registers, the error stops | C3 |
| the forms agree with the Butcher form to round-off | C2 |
stage_weight telescopes the stage fluxes to the mass change | P4 |
stage_euler_fraction and ssp_coefficient against the literature; a limiter with them keeps positivity | P2 |
| a companion stepped with the field is the coupled Runge–Kutta step, bitwise, in every form | C8 |
decay=: exact for a frozen source and for static equilibria, stable at any | P5 |
lookahead and stage_current: Gauss's law at every stage and step | C9 |
FORM_LEAPFROG with its start-up, every filter: orders and stability bounds; the filter's damping and the data it leaves alone | A9, P6 |
FORM_MULTISTEP: checkpoint and restart bitwise for ab-1 to ab-6, a regrid by injection, the ghost cells; the built-in start-up (its table of orders; within each scheme's own error of an exact history) | selah_test_history |
the fixed-point stages: am-1 converged to the closed-form trapezoid step (1e-14), the contraction bdf-1 to bdf-6 at | selah_test_fixed_point |
| the stepper on an A30 | C5 |
| the stepper's own cost: none (0.999 of the same kernels called directly) | Performance |