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:
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.
- Between
begin_stage(k)andend_stage(k)the stage state holds the state of stage k in the cells of the box:qitself whenstage_state_is_q(k)(every stage of every form but the Butcher one, wherestate_aliases_q()is true; in the Butcher form the stages whose row of A is zero, when the stepper was initialised withstages_on_q=.true.), elsestage_state(). - The stepper never writes a ghost cell, of any register or of
q. - The caller may write the ghost cells of the stage state during that window (ghost exchange, seam fill, physical boundaries).
rhs_register()is written by the caller only, in the cells of the box, and is distinct from the stage state. Bothrhs_register()andstage_state()are null outside that window (beforebegin_stage(k), afterend_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.- After
finish_stepthe 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
| Name | Type | Attributes | Description |
|---|---|---|---|
scheme | character(len=:) | allocatable | Scheme name. |
form | character(len=:) | allocatable | Storage form. |
nstages | integer(kind=I4P) | Stages (flows for a splitting). | |
k_active | integer(kind=I4P) | Stage between begin_stage and end_stage, else 0. | |
lb | integer(kind=I4P) | Lower bounds of the field, as rank 5. | |
ub | integer(kind=I4P) | Upper bounds of the field, as rank 5. | |
rank | integer(kind=I4P) | Rank of the field. | |
components | logical | The field's first dimension holds its components. | |
lbk | integer(kind=I4P) | Lower bounds of the field, rank k (the first rank values). | |
ubk | integer(kind=I4P) | Upper bounds of the field, rank k (the first rank values). | |
part | integer(kind=I4P) | Component ranges of the two partitions (splitting). | |
bt | type(butcher_tableau) | Butcher tableau (every RK form). | |
r2 | type(shu_osher_2r_form) | Two-register form. | |
w2n | type(williamson_2n_form) | 2N form. | |
sc | type(splitting_composition) | Splitting. | |
regs | real(kind=R_P) | pointer, contiguous | Registers (contiguous: the rank-k views remap them). |
at_d | real(kind=R_P) | pointer | Transposed A (column k = row k), device resident. |
b_d | real(kind=R_P) | pointer | Weights b, device resident. |
owned | logical | The registers are the stepper's. | |
on_q | logical | allocatable | Stage k's state is q itself. |
ef | real(kind=R_P) | allocatable | Forward-Euler fraction of each stage (Shu–Osher form). |
cssp | real(kind=R_P) | SSP coefficient of the Shu–Osher form, 0 if none. | |
masked_q | logical | The masked cells of every stage state are q^n. |
Type-Bound Procedures
| Name | Attributes | Description |
|---|---|---|
initialize | pass(self) | Set the scheme and its storage form for a field of rank size(lb); allocate the registers (or take the caller's). |
initialize_companion | pass(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). |
destroy | pass(self) | Free what the stepper owns. |
begin_step | Generic: begin_step_r1, begin_step_r2, begin_step_r3, begin_step_r4, begin_step_r5 | |
begin_stage | Generic: begin_stage_r1, begin_stage_r2, begin_stage_r3, begin_stage_r4, begin_stage_r5 | |
end_stage | Generic: end_stage_r1, end_stage_r2, end_stage_r3, end_stage_r4, end_stage_r5 | |
finish_step | Generic: finish_step_r1, finish_step_r2, finish_step_r3, finish_step_r4, finish_step_r5 | |
stage_state_view | Generic: stage_state_view_r1, stage_state_view_r2, stage_state_view_r3, stage_state_view_r4, stage_state_view_r5 | |
rhs_register_view | Generic: rhs_register_view_r1, rhs_register_view_r2, rhs_register_view_r3, rhs_register_view_r4, rhs_register_view_r5 | |
lookahead | Generic: lookahead_r1, lookahead_r2, lookahead_r3, lookahead_r4, lookahead_r5 | |
stage_current | pass(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_admissible | pass(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_state | pass(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_register | pass(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). |
stages | pass(self) | Stages of a step (flows of a splitting). |
stage_time | pass(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_weight | pass(self) | Effective Butcher weight b_k of stage k; for a splitting, the fraction of the step of flow k. |
stage_partition | pass(self) | Partition advanced by flow k of a splitting (1 or 2); 0 for a Runge–Kutta form. |
stage_euler_fraction | pass(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_coefficient | pass(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_bound | pass(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_bound | pass(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_q | pass(self) | The stage state is q itself (every form but the Butcher one). |
stage_state_is_q | pass(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).
subroutine initialize(self, scheme, form, lb, ub, partitions, registers, stages_on_q, components, masked_q)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stepper) | inout | Stepper. | |
scheme | character(len=*) | in | Scheme name (selah_schemes, selah_splittings). | |
form | character(len=*) | in | Storage form (selah_storage). | |
lb | integer(kind=I4P) | in | Bounds of the field, ghosts included (rank k). | |
ub | integer(kind=I4P) | in | Bounds of the field, ghosts included (rank k). | |
partitions | integer(kind=I4P) | in | optional | Splitting: (v1, v2) of partitions 1, 2. |
registers | real(kind=R_P) | in | pointer, optional | The caller's registers. |
stages_on_q | logical | in | optional | Butcher form: the stages whose row of A is zero are evaluated on q (default .false.). |
components | logical | in | optional | Rank below 5: the field's first dimension holds its components (selah_box). |
masked_q | logical | in | optional | The 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).
subroutine initialize_companion(self, field, lb, ub, partitions, registers, components)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stepper) | inout | Companion. | |
field | class(stepper) | in | The field's stepper, initialised. | |
lb | integer(kind=I4P) | in | Bounds of the companion's state (rank k). | |
ub | integer(kind=I4P) | in | Bounds of the companion's state (rank k). | |
partitions | integer(kind=I4P) | in | optional | Splitting: the companion's partitions. |
registers | real(kind=R_P) | in | pointer, optional | The caller's registers (rank 5). |
components | logical | in | optional | Rank below 5: the first dimension holds components. |
Call graph
stepper%destroy
Free what the stepper owns.
subroutine destroy(self)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stepper) | inout | Stepper. |
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.
subroutine stage_current(self, k, bx, h, jr, jk)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stepper) | in | Stepper. | |
k | integer(kind=I4P) | in | Stage. | |
bx | type(box) | in | Box (of the grid arrays, rank 5). | |
h | real(kind=R_P) | in | The weighted sum wanted. | |
jr | real(kind=R_P) | in | Stage currents 1..k-1. | |
jk | real(kind=R_P) | inout | Stage 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
function stage_current_admissible(self) result(yes)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stepper) | in | Stepper. |
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)
function stage_state(self) result(u)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stepper) | in | Stepper. |
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)
function rhs_register(self) result(r)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stepper) | in | Stepper. |
Call graph
stepper%stages
Stages of a step (flows of a splitting).
Attributes: pure
Returns: integer(kind=I4P)
function stages(self) result(n)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stepper) | in | Stepper. |
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)
function stage_time(self, k) result(c)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stepper) | in | Stepper. | |
k | integer(kind=I4P) | in | Stage. |
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)
function stage_weight(self, k) result(w)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stepper) | in | Stepper. | |
k | integer(kind=I4P) | in | Stage. |
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)
function stage_partition(self, k) result(p)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stepper) | in | Stepper. | |
k | integer(kind=I4P) | in | Stage. |
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)
function stage_euler_fraction(self, k) result(f)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stepper) | in | Stepper. | |
k | integer(kind=I4P) | in | Stage. |
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)
function stepper_ssp_coefficient(self) result(c)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stepper) | in | Stepper. |
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)
function stepper_imag_axis_bound(self) result(beta)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stepper) | in | Stepper. |
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)
function stepper_real_axis_bound(self) result(beta)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stepper) | in | Stepper. |
Call graph
stepper%state_aliases_q
The stage state is q itself (every form but the Butcher one).
Attributes: pure
Returns: logical
function state_aliases_q(self) result(yes)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stepper) | in | Stepper. |
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
function stage_state_is_q(self, k) result(yes)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stepper) | in | Stepper. | |
k | integer(kind=I4P) | in | Stage. |