Skip to content

selah_stepper ​

SELAH, L2: the stepper, a time step the caller drives one stage at a time.

The stepper owns the registers and the coefficients; the caller owns the solution q, the time loop, the ghost cells and the residual. One step of any scheme is the same sequence of calls:

fortran
 call st%begin_step(bx, q)
 do k=1, st%stages()
    call st%begin_stage(k, bx, dt, q)                  ! builds the state of stage k
    ! fill the ghost cells of the stage state (q itself when st%stage_state_is_q(k), else st%stage_state())
    ! write its residual into st%rhs_register() (the components of st%stage_partition(k) for a splitting)
    call st%end_stage(k, bx, dt, q)
 enddo
 call st%finish_step(bx, dt, q)

The stage contract.

  1. Between begin_stage(k) and end_stage(k) the stage state holds the state of stage k in the cells of the box: q itself when stage_state_is_q(k) (every stage of every form but the Butcher one, where state_aliases_q() is true; in the Butcher form the stages whose row of A is zero, when the stepper was initialised with stages_on_q=.true.), else stage_state().
  2. The stepper never writes a ghost cell, of any register or of q.
  3. The caller may write the ghost cells of the stage state during that window (ghost exchange, seam fill, physical boundaries).
  4. rhs_register() is written by the caller only, in the cells of the box, and is distinct from the stage state. Both rhs_register() and stage_state() are null outside that window (before begin_stage(k), after end_stage(k)): a caller that keeps them across stages fails at once instead of writing a register that is no longer the one of the active stage.
  5. After finish_step the registers are scratch.

stage_weight(k) is the effective Butcher weight b_k of stage k in every Runge–Kutta form (the weight a flux register needs to accumulate the step's boundary fluxes); for a splitting it is the fraction of the step of flow k.

Stage time. stage_time(k) is the fraction of the step at which the residual of stage k is evaluated: the abscissa c_k in every Runge–Kutta form. For a splitting, time is a variable with t' = 1, and a sub-flow is exact only when its partition's residual does not depend on its own variables; so time advances with the flows of the partition whose residual does not depend on t, and stays frozen through the other's. stage_time(k) is then the sum of the fractions of the flows of the other partition before flow k: the time flow k needs when its own residual is the one that depends on t, whichever partition that is (the composition keeps its order). When both residuals depend on t no sub-flow is exact, and the composition gives no order guarantee for the time dependence.

Forward-Euler steps. ssp_coefficient() is the SSP coefficient C of the scheme, from its Shu–Osher form (0 for a scheme that is not SSP, and for a splitting). stage_euler_fraction(k) is the largest forward-Euler step, as a fraction of dt, that the residual of stage k enters in the Shu–Osher form: f_k = max_i beta_ik / alpha_ik (selah_tableaux euler_step_fractions; max_k f_k = 1/C). A limiter that makes the state of stage k plus f_k dt times its residual admissible (positive, bounded) keeps every later stage and the step admissible. For a splitting, flow k is a forward-Euler step of fraction c_k on its partition (0 for a backward flow).

Mask policy. With mask present, the kernels update the active cells only. With masked_q=.true. at initialisation, the masked cells of every stage state hold q^n: the Butcher form writes q^n into them as it builds the stage state (in the same pass); the other forms keep the stage state in q, whose masked cells no update touches. A caller whose residual reads masked cells (an immersed boundary extrapolating from the solid side) then sees q^n there at every stage. Default .false.: the Butcher register's masked cells are left untouched (v0.1.0 behaviour).

Companion states. A state that advances with the field in the same step, its residual built inside the field's (particles pushed by the fields of each stage, a perfectly matched layer's auxiliary fields), is the same scheme applied to another state: a companion is a second stepper, initialize_companion(field, lb, ub, ...), with the field stepper's scheme, form and stages on q, driven through the same calls in the same stage window (begin_stage of both, the residuals of both, end_stage of both). Its bounds are a capacity: the box of each call is the active part (particles 1..n of a pool, the components that evolve), and the kernels never touch the rest. Re-initialise it when its shape changes (a regrid). Stepped together, field and companion are bitwise the two stepped as one state.

A decay integrated exactly. For a state psi' = g - lambda psi (lambda >= 0 per element, constant in time: the auxiliary fields of a perfectly matched layer), decay=lambda at every begin_stage and at finish_step makes the caller's residual the source g alone and integrates the decay exactly (selah_kernels_exp: exponential Euler on the Runge–Kutta-averaged source): exact for a frozen source and for static equilibria at any lambda dt, stable for any lambda dt, second order with a varying source; bitwise the explicit step where lambda = 0. Butcher form, no mask, no dq. The stiff source coupling still lowers the stable step inside a stiff layer (notes/companions-pushers-pml.md §5): the caller's step limit is the coupled one.

Charge-conserving stage currents. A field whose divergence must track a charge (Maxwell's Gauss law in a particle-in-cell solver) stays consistent at every stage if the weighted sum of the stage currents, sum_{r<=k} a_{k+1,r} J_r, is the current that moves the charge from q^n to the state of stage k+1. Within the window of stage k, after the particles' residual, lookahead(k, bx, dt, q, u) (a companion's) gives that state, u = q^n + dt sum_{r<=k} a_{k+1,r} R_r (b at the last stage: the step's result); the caller deposits the charge-conserving current H of the displacement q^n -> u; stage_current(k, bx, h, jr, jk) (the field's) gives J_k = (H - sum_{r<k} a_{k+1,r} J_r) / a_{k+1,k}, the current of the field's residual at stage k. Then sum_{r<=k} a_{k+1,r} J_r = H at every stage and sum_k b_k J_k = H(q^n -> q^{n+1}) at the step. It needs a_{k+1,k} /= 0 and b_s /= 0 (stage_current_admissible()); the individual J_k are amplified (up to 25 times for ssp-104), only their weighted sums are physical. Butcher form.

Stages on q. The state of a stage whose row of A is zero (the first stage of every explicit scheme) is q itself. With stages_on_q=.true. the Butcher form does not copy q into its stage-state register for such a stage: the caller evaluates the residual on q, and stage_state() is null during that stage, so that a caller that does not ask stage_state_is_q(k) fails at once instead of reading a stale register. Default .false.: every stage of the Butcher form has its register (v0.1.0 behaviour).

Storage. registers_needed(scheme, form) field-sized buffers, allocated through FUNDAL (device memory in a device build) or passed by the caller (registers, a contiguous rank-6 array with the field's bounds and enough slots; rank-5 fields only).

Fields of rank 1 to 4. initialize takes the bounds of a field of rank k = size(lb) and, below rank 5, the components flag (selah_box: the field viewed as rank 5 with singleton dimensions). begin_step, begin_stage, end_stage and finish_step are generic over the rank of q (dq and mask have q's rank); the box must have the field's rank (box_interior(lb, ub, ngc, components)). The field reaches the one rank-5 implementation through an explicit-shape dummy, with no copy when it is contiguous; it must be contiguous in a device build. The stage state and the residual register of a rank-k field are stage_state_view(u) and rhs_register_view(r): rank-k pointers with the field's bounds, null when stage_state() and rhs_register() are (the functions keep their rank-5 result).

Source: src/lib/selah_stepper.F90

Dependencies

Contents ​

Derived Types ​

stepper ​

A time step driven stage by stage.

Components

NameTypeAttributesDescription
schemecharacter(len=:)allocatableScheme name.
formcharacter(len=:)allocatableStorage form.
nstagesinteger(kind=I4P)Stages (flows for a splitting).
k_activeinteger(kind=I4P)Stage between begin_stage and end_stage, else 0.
lbinteger(kind=I4P)Lower bounds of the field, as rank 5.
ubinteger(kind=I4P)Upper bounds of the field, as rank 5.
rankinteger(kind=I4P)Rank of the field.
componentslogicalThe field's first dimension holds its components.
lbkinteger(kind=I4P)Lower bounds of the field, rank k (the first rank values).
ubkinteger(kind=I4P)Upper bounds of the field, rank k (the first rank values).
partinteger(kind=I4P)Component ranges of the two partitions (splitting).
bttype(butcher_tableau)Butcher tableau (every RK form).
r2type(shu_osher_2r_form)Two-register form.
w2ntype(williamson_2n_form)2N form.
sctype(splitting_composition)Splitting.
regsreal(kind=R_P)pointer, contiguousRegisters (contiguous: the rank-k views remap them).
at_dreal(kind=R_P)pointerTransposed A (column k = row k), device resident.
b_dreal(kind=R_P)pointerWeights b, device resident.
ownedlogicalThe registers are the stepper's.
on_qlogicalallocatableStage k's state is q itself.
efreal(kind=R_P)allocatableForward-Euler fraction of each stage (Shu–Osher form).
csspreal(kind=R_P)SSP coefficient of the Shu–Osher form, 0 if none.
masked_qlogicalThe masked cells of every stage state are q^n.

Type-Bound Procedures

NameAttributesDescription
initializepass(self)Set the scheme and its storage form for a field of rank size(lb); allocate the registers (or take the caller's).
initialize_companionpass(self)A companion of the stepper field: a stepper of the same scheme, form and stages on q, for another state that advances with the field in the same step (see "Companion states" above).
destroypass(self)Free what the stepper owns.
begin_stepGeneric: begin_step_r1, begin_step_r2, begin_step_r3, begin_step_r4, begin_step_r5
begin_stageGeneric: begin_stage_r1, begin_stage_r2, begin_stage_r3, begin_stage_r4, begin_stage_r5
end_stageGeneric: end_stage_r1, end_stage_r2, end_stage_r3, end_stage_r4, end_stage_r5
finish_stepGeneric: finish_step_r1, finish_step_r2, finish_step_r3, finish_step_r4, finish_step_r5
stage_state_viewGeneric: stage_state_view_r1, stage_state_view_r2, stage_state_view_r3, stage_state_view_r4, stage_state_view_r5
rhs_register_viewGeneric: rhs_register_view_r1, rhs_register_view_r2, rhs_register_view_r3, rhs_register_view_r4, rhs_register_view_r5
lookaheadGeneric: lookahead_r1, lookahead_r2, lookahead_r3, lookahead_r4, lookahead_r5
stage_currentpass(self)The stage current of stage k whose weighted sum with the earlier ones is h (see "Charge-conserving stage currents" above): jk = (h - sum_{r<k} a_{k+1,r} jr(r)) / a_{k+1,k} (b at the last stage). jr holds the stage currents of stages 1..k-1 (the caller's registers, rank 5 plus the stage); Butcher form; stops on a scheme for which stage_current_admissible() is false.
stage_current_admissiblepass(self)Every a(k+1,k), k < s, and b(s) is non-zero: the stage currents exist (every Runge–Kutta scheme of the catalogue); false for a splitting.
stage_statepass(self)The state of the active stage, with the field's bounds: the Butcher form's register; null when the stage's state is q itself (stage_state_is_q), so in every other form, and outside a stage window.
rhs_registerpass(self)Where the caller writes the residual of the active stage, with the field's bounds; null outside a stage window (in the Butcher form, slot k_active + 1 would otherwise be the stage-state register).
stagespass(self)Stages of a step (flows of a splitting).
stage_timepass(self)Fraction of the step at which the residual of stage k is evaluated: the abscissa c_k; for a splitting, the fractions of the other partition's flows before flow k (see "Stage time" above).
stage_weightpass(self)Effective Butcher weight b_k of stage k; for a splitting, the fraction of the step of flow k.
stage_partitionpass(self)Partition advanced by flow k of a splitting (1 or 2); 0 for a Runge–Kutta form.
stage_euler_fractionpass(self)The forward-Euler step stage k's residual takes, as a fraction of the step (see "Forward-Euler steps" above): the step a limiter makes admissible on the state of stage k; 0 when the scheme has no such decomposition.
ssp_coefficientpass(self)The SSP coefficient C of the scheme (its Shu–Osher form): the scheme keeps every convex property of forward Euler for dt <= C dt_FE; 0 when the scheme is not SSP, and for a splitting.
imag_axis_boundpass(self)The scheme's imaginary-axis stability bound (selah_tableaux imag_axis_bound): an oscillatory mode of frequency omega (a gyration, a wave) is stable for omega dt <= beta; 0 for euler, ssp-22 and a splitting.
real_axis_boundpass(self)The scheme's real-axis stability bound (selah_tableaux real_axis_bound): a decay of rate lambda is stable for lambda dt <= beta; 0 for a splitting.
state_aliases_qpass(self)The stage state is q itself (every form but the Butcher one).
stage_state_is_qpass(self)The state of stage k is q itself: the caller evaluates the residual of stage k on q. True for every stage of every form but the Butcher one; in the Butcher form, for the stages whose row of A is zero when the stepper was initialised with stages_on_q=.true.

stepper%initialize ​

Set the scheme and its storage form for a field of rank size(lb); allocate the registers (or take the caller's).

fortran
subroutine initialize(self, scheme, form, lb, ub, partitions, registers, stages_on_q, components, masked_q)

Arguments

NameTypeIntentAttributesDescription
selfclass(stepper)inoutStepper.
schemecharacter(len=*)inScheme name (selah_schemes, selah_splittings).
formcharacter(len=*)inStorage form (selah_storage).
lbinteger(kind=I4P)inBounds of the field, ghosts included (rank k).
ubinteger(kind=I4P)inBounds of the field, ghosts included (rank k).
partitionsinteger(kind=I4P)inoptionalSplitting: (v1, v2) of partitions 1, 2.
registersreal(kind=R_P)inpointer, optionalThe caller's registers.
stages_on_qlogicalinoptionalButcher form: the stages whose row of A is zero are evaluated on q (default .false.).
componentslogicalinoptionalRank below 5: the field's first dimension holds its components (selah_box).
masked_qlogicalinoptionalThe masked cells of every stage state are q^n (default .false.: left untouched).

Call graph

stepper%initialize_companion ​

A companion of the stepper field: a stepper of the same scheme, form and stages on q, for another state that advances with the field in the same step (see "Companion states" above).

fortran
subroutine initialize_companion(self, field, lb, ub, partitions, registers, components)

Arguments

NameTypeIntentAttributesDescription
selfclass(stepper)inoutCompanion.
fieldclass(stepper)inThe field's stepper, initialised.
lbinteger(kind=I4P)inBounds of the companion's state (rank k).
ubinteger(kind=I4P)inBounds of the companion's state (rank k).
partitionsinteger(kind=I4P)inoptionalSplitting: the companion's partitions.
registersreal(kind=R_P)inpointer, optionalThe caller's registers (rank 5).
componentslogicalinoptionalRank below 5: the first dimension holds components.

Call graph

stepper%destroy ​

Free what the stepper owns.

fortran
subroutine destroy(self)

Arguments

NameTypeIntentAttributesDescription
selfclass(stepper)inoutStepper.

stepper%stage_current ​

The stage current of stage k whose weighted sum with the earlier ones is h (see "Charge-conserving stage currents" above): jk = (h - sum_{r<k} a_{k+1,r} jr(r)) / a_{k+1,k} (b at the last stage). jr holds the stage currents of stages 1..k-1 (the caller's registers, rank 5 plus the stage); Butcher form; stops on a scheme for which stage_current_admissible() is false.

fortran
subroutine stage_current(self, k, bx, h, jr, jk)

Arguments

NameTypeIntentAttributesDescription
selfclass(stepper)inStepper.
kinteger(kind=I4P)inStage.
bxtype(box)inBox (of the grid arrays, rank 5).
hreal(kind=R_P)inThe weighted sum wanted.
jrreal(kind=R_P)inStage currents 1..k-1.
jkreal(kind=R_P)inoutStage current k.

Call graph

stepper%stage_current_admissible ​

Every a(k+1,k), k < s, and b(s) is non-zero: the stage currents exist (every Runge–Kutta scheme of the catalogue); false for a splitting.

Attributes: pure

Returns: logical

fortran
function stage_current_admissible(self) result(yes)

Arguments

NameTypeIntentAttributesDescription
selfclass(stepper)inStepper.

stepper%stage_state ​

The state of the active stage, with the field's bounds: the Butcher form's register; null when the stage's state is q itself (stage_state_is_q), so in every other form, and outside a stage window.

Returns: real(kind=R_P)

fortran
function stage_state(self) result(u)

Arguments

NameTypeIntentAttributesDescription
selfclass(stepper)inStepper.

Call graph

stepper%rhs_register ​

Where the caller writes the residual of the active stage, with the field's bounds; null outside a stage window (in the Butcher form, slot k_active + 1 would otherwise be the stage-state register).

Returns: real(kind=R_P)

fortran
function rhs_register(self) result(r)

Arguments

NameTypeIntentAttributesDescription
selfclass(stepper)inStepper.

Call graph

stepper%stages ​

Stages of a step (flows of a splitting).

Attributes: pure

Returns: integer(kind=I4P)

fortran
function stages(self) result(n)

Arguments

NameTypeIntentAttributesDescription
selfclass(stepper)inStepper.

stepper%stage_time ​

Fraction of the step at which the residual of stage k is evaluated: the abscissa c_k; for a splitting, the fractions of the other partition's flows before flow k (see "Stage time" above).

Attributes: pure

Returns: real(kind=R_P)

fortran
function stage_time(self, k) result(c)

Arguments

NameTypeIntentAttributesDescription
selfclass(stepper)inStepper.
kinteger(kind=I4P)inStage.

stepper%stage_weight ​

Effective Butcher weight b_k of stage k; for a splitting, the fraction of the step of flow k.

Attributes: pure

Returns: real(kind=R_P)

fortran
function stage_weight(self, k) result(w)

Arguments

NameTypeIntentAttributesDescription
selfclass(stepper)inStepper.
kinteger(kind=I4P)inStage.

stepper%stage_partition ​

Partition advanced by flow k of a splitting (1 or 2); 0 for a Runge–Kutta form.

Attributes: pure

Returns: integer(kind=I4P)

fortran
function stage_partition(self, k) result(p)

Arguments

NameTypeIntentAttributesDescription
selfclass(stepper)inStepper.
kinteger(kind=I4P)inStage.

stepper%stage_euler_fraction ​

The forward-Euler step stage k's residual takes, as a fraction of the step (see "Forward-Euler steps" above): the step a limiter makes admissible on the state of stage k; 0 when the scheme has no such decomposition.

Attributes: pure

Returns: real(kind=R_P)

fortran
function stage_euler_fraction(self, k) result(f)

Arguments

NameTypeIntentAttributesDescription
selfclass(stepper)inStepper.
kinteger(kind=I4P)inStage.

stepper%ssp_coefficient ​

The SSP coefficient C of the scheme (its Shu–Osher form): the scheme keeps every convex property of forward Euler for dt <= C dt_FE; 0 when the scheme is not SSP, and for a splitting.

Attributes: pure

Returns: real(kind=R_P)

fortran
function stepper_ssp_coefficient(self) result(c)

Arguments

NameTypeIntentAttributesDescription
selfclass(stepper)inStepper.

stepper%imag_axis_bound ​

The scheme's imaginary-axis stability bound (selah_tableaux imag_axis_bound): an oscillatory mode of frequency omega (a gyration, a wave) is stable for omega dt <= beta; 0 for euler, ssp-22 and a splitting.

Attributes: pure

Returns: real(kind=R_P)

fortran
function stepper_imag_axis_bound(self) result(beta)

Arguments

NameTypeIntentAttributesDescription
selfclass(stepper)inStepper.

Call graph

stepper%real_axis_bound ​

The scheme's real-axis stability bound (selah_tableaux real_axis_bound): a decay of rate lambda is stable for lambda dt <= beta; 0 for a splitting.

Attributes: pure

Returns: real(kind=R_P)

fortran
function stepper_real_axis_bound(self) result(beta)

Arguments

NameTypeIntentAttributesDescription
selfclass(stepper)inStepper.

Call graph

stepper%state_aliases_q ​

The stage state is q itself (every form but the Butcher one).

Attributes: pure

Returns: logical

fortran
function state_aliases_q(self) result(yes)

Arguments

NameTypeIntentAttributesDescription
selfclass(stepper)inStepper.

stepper%stage_state_is_q ​

The state of stage k is q itself: the caller evaluates the residual of stage k on q. True for every stage of every form but the Butcher one; in the Butcher form, for the stages whose row of A is zero when the stepper was initialised with stages_on_q=.true.

Attributes: pure

Returns: logical

fortran
function stage_state_is_q(self, k) result(yes)

Arguments

NameTypeIntentAttributesDescription
selfclass(stepper)inStepper.
kinteger(kind=I4P)inStage.

GPL-3.0-or-later, BSD-2-Clause, BSD-3-Clause or MIT, at your choice