Concepts
What a solver needs to know to use SELAH correctly: the shape of a field, what a kernel touches, how the work of a step is split between the stepper and the caller, and what each storage form keeps.
The field
SELAH works on the fields of block-structured solvers. A field is an array of rank 1 to 5. Internally SELAH views every field as rank 5: components, the three cell indices with their ghost cells, and the blocks of a pool; a field of lower rank is that view with singleton dimensions (fields of rank 1 to 4). The rank-5 view has one of two layouts:

| Layout | Index order | Contiguous in memory | Used by |
|---|---|---|---|
LAYOUT_V_FIRST | (v, i, j, k, b) | the components of a cell | CPU fields (ADAM's CPU backend) |
LAYOUT_V_LAST | (b, i, j, k, v) | the same cell of every block | device fields (ADAM's FNL backend): consecutive GPU threads read consecutive blocks |
The cell indices run from 1-ngc to n+ngc, ghost cells included. Components and blocks start at 1. The pool may hold more blocks than are active.
The box
A kernel updates a box: the interior cells of the active blocks, every component or a range of them. It writes nothing else.

box_interior(layout, nv, ni, nj, nk, ngc, blocks_number)builds the box of the firstblocks_numberblocks.bx%lbholds the array's lower bounds, which the kernels need to address it (ghosts included).bx%lo:bx%hiis the loop range.box_components(bx, v1, v2)narrows a box to componentsv1..v2: a partition of a splitting, or the passive scalars of a solver.- A box is passed at every call and never stored, because the active blocks change at every regrid.
Arrays reach the kernels with their own lower bounds: every dummy is declared q(bx%lb(1):, …, bx%lb(5):). An assumed-shape dummy without bounds would renumber a field with ghost cells from 1 and shift the interior.
Masks
Every box kernel and every stepper call takes an optional mask: an array with the field's bounds and one or more components. A cell is active where the mask is negative, as with a level-set distance that is negative in the fluid. mask_comp picks the component; the default is the last (ADAM's "all solids" summary). Inactive cells are left untouched, except the step residual dq, which is 0 there.
The stage contract
The stepper and the caller share the work of a step, in the same sequence of calls whatever the scheme or the storage form:
One 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.
The stage contract is the agreement that makes this safe:
- Between
begin_stage(k)andend_stage(k), the stage state holds the state of stagein the cells of the box: qitself whenstage_state_is_q(k), 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, AMR seam fill, physical boundaries.
rhs_register()is written by the caller only, in the cells of the box, and is never the stage state. Outside the window,rhs_register()andstage_state()are null: fetch them again at every stage.- After
finish_stepthe registers are scratch.
stage_weight(k) is the effective Butcher weight
Storage forms
A scheme can run in several storage forms, which keep different registers and do the work at different calls:

| Form | Registers | Schemes | The stage state | Where the work happens |
|---|---|---|---|---|
FORM_BUTCHER | s + 1 | every Runge–Kutta scheme | its own register (or q, with stages_on_q, for the zero rows of A) | begin_stage: the state from q and the earlier residuals; finish_step: the update (and dq) |
FORM_SHU_OSHER_2R | 2 | euler, ssp-22, ssp-33 | q | begin_step: a copy of end_stage: |
FORM_WILLIAMSON_2N | 2 | lsrk-33, lsrk-54 | q | end_stage: |
FORM_KETCHESON_2R | 2 | ssp-104 | q | begin_step: a copy; end_stage: Ketcheson's recipe |
FORM_SPLITTING | 1 | every splitting | q | end_stage: the flow's partition, |
FORM_LEAPFROG | 2 | leapfrog, leapfrog-raw | q | end_stage: ssp-22 in the two-register form |
FORM_MULTISTEP | the history rings (+ the start-up's stage registers; + two stage registers and | ab-<k>, am-<k>, abm-<k>, bdf-<k> | q; the start-up's stages past the first, and the fixed-point stages: their register | finish_step: |
The low-storage forms give the same solution as the Butcher form, to round-off (the leapfrog is a two-step method, not a form of a Runge–Kutta scheme) (C2). Only the Butcher form can return the step residual dq, because only it holds every stage residual until the update.
Ownership
You own the physics, SELAH owns the step
SELAH is a library you call, not a framework you live inside: it never sees your mesh, your boundary conditions or your physics, only the cells of the box you hand it.
Your solver
- the solution
qany rank 1 to 5, your bounds and layout - its ghost cellsfilled by you inside each stage window
- the residualwritten into
rhs_register() - the time loop and dtCFL, output, regrid, restart
- the masksolid cells; SELAH applies the policy
- optionally the registers
registers=: SELAH never frees them
end_stage · finish_step
SELAH
- the registers
registers_needed(scheme, form)buffers, freed bydestroy - the coefficientstableaux, Shu–Osher, 2N, splitting fractions
- every update rulestage states, step update, flows, filter
- stage times and weights
stage_time(k),stage_weight(k) - the queries
ssp_coefficient(),stage_euler_fraction(k),imag_axis_bound() - the leapfrog historythe one register kept across steps
the kernels' directives
FUNDAL
- device memory
dev_alloc: registers live on the GPU in a device build - the directivesone kernel source for the host, OpenMP and OpenACC
- transfers
dev_memcpy_*when you move data
Two rules hold everything together. SELAH never writes a ghost cell, of a register or of q. You never write a register except rhs_register(), and only inside its stage window.
The registers the stepper allocates come from FUNDAL (device memory in a device build, with device copies of the coefficients A and b); registers the caller passes with registers= the stepper never frees. The stepper has no finalizer: call destroy. Its components are public for the tests' sake, but they are not part of the API, and code should not read them.