Skip to content

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:

The two layouts

LayoutIndex orderContiguous in memoryUsed by
LAYOUT_V_FIRST(v, i, j, k, b)the components of a cellCPU fields (ADAM's CPU backend)
LAYOUT_V_LAST(b, i, j, k, v)the same cell of every blockdevice 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.

The box

  • box_interior(layout, nv, ni, nj, nk, ngc, blocks_number) builds the box of the first blocks_number blocks.
  • bx%lb holds the array's lower bounds, which the kernels need to address it (ghosts included). bx%lo:bx%hi is the loop range.
  • box_components(bx, v1, v2) narrows a box to components v1..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:

The stage contract

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.

The stage contract: the calls of one step and who acts at eachOne step of any scheme: begin_step(bx, q); then for k from 1 to stages(): begin_stage(k, bx, dt, q), the caller fills the ghost cells of the stage state and writes its residual into rhs_register(), end_stage(k, bx, dt, q); then finish_step(bx, dt, q). Inside the stage window of k, stage_state() and rhs_register() are live; outside it they are null.YOUR SOLVERSELAH STEPPERtime loop, q,ghosts, residualreflux withstage_weight(k)1 evaluate on q or stage_state()2 fill the ghosts of the stage state3 write the residual into rhs_register()begin_step(bx, q)begin_stage(k, bx, dt, q)end_stage(k, bx, dt, q)finish_step(bx, dt, q)next k, up to stages()copies qⁿ where theform needs itbuilds the stage stateButcher form; the otherskeep it in qadvances q in place2R, 2N, Ketcheson,splitting, leapfrog, linear SSPthe Butcher update(and dq); the leapfrogkeeps its historythe stage window of k: stage_state(), rhs_register() live · outside it: null
  1. begin_step(bx, q): SELAH copies qⁿ where the form needs it.
  2. 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).
  3. 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().
  4. 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.
  5. finish_step(bx, dt, q): the Butcher update (and dq); the leapfrog keeps its history. You reflux with stage_weight(k).
  6. Outside the stage window, stage_state() and rhs_register() are null.

The stage contract is the agreement that makes this safe:

  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), 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, AMR seam fill, physical boundaries.
  4. 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() and stage_state() are null: fetch them again at every stage.
  5. After finish_step the registers are scratch.

stage_weight(k) is the effective Butcher weight bk of stage k in every Runge–Kutta form, the weight a flux register needs (Tutorial 8). Every clause is tested (C3).

Storage forms ​

A scheme can run in several storage forms, which keep different registers and do the work at different calls:

Register maps

FormRegistersSchemesThe stage stateWhere the work happens
FORM_BUTCHERs + 1every Runge–Kutta schemeits 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_2R2euler, ssp-22, ssp-33qbegin_step: a copy of qn; end_stage: q=aqn+bq+ΔtcR
FORM_WILLIAMSON_2N2lsrk-33, lsrk-54qend_stage: ΔQ=AΔQ+ΔtR; q+=BΔQ
FORM_KETCHESON_2R2ssp-104qbegin_step: a copy; end_stage: Ketcheson's recipe
FORM_SPLITTING1every splittingqend_stage: the flow's partition, qp+=ckΔtR
FORM_LEAPFROG2leapfrog, leapfrog-rawqend_stage: qn+1=h+2ΔtR and the filter, h (the history, kept across steps) ← the filtered qn; the first step: ssp-22 in the two-register form
FORM_MULTISTEPthe history rings (+ the start-up's stage registers; + two stage registers and E for the implicit schemes)ab-<k>, am-<k>, abm-<k>, bdf-<k>q; the start-up's stages past the first, and the fixed-point stages: their registerfinish_step: qn+1=∑jajUn+1−j+Δt∑jbjRn+1−j from the rings (kept across steps), qn into the solution ring in the same pass; the rings turn by one index

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 ​

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.

the caller

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 registersregisters=: SELAH never frees them
Between your solver and SELAH, the step calls: begin_step · begin_stage
end_stage · finish_step
the library

SELAH

  • the registersregisters_needed(scheme, form) buffers, freed by destroy
  • the coefficientstableaux, Shu–Osher, 2N, splitting fractions
  • every update rulestage states, step update, flows, filter
  • stage times and weightsstage_time(k), stage_weight(k)
  • the queriesssp_coefficient(), stage_euler_fraction(k), imag_axis_bound()
  • the leapfrog historythe one register kept across steps
Between SELAH and FUNDAL: device memory
the kernels' directives
the backend

FUNDAL

  • device memorydev_alloc: registers live on the GPU in a device build
  • the directivesone kernel source for the host, OpenMP and OpenACC
  • transfersdev_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.