Templates and backends#
A template is a Python function#
zoomy_core.symsolver.strategies.hyperbolic.HyperbolicTemplate.march and
...chorin.ChorinTemplate.march are ordinary Python. Called once with sympy
symbols for Q, Qaux, p, time and mesh, they return one sympy graph
of the whole march. Three kinds of names appear in it
(zoomy_core/symsolver/core.py):
name |
what |
defined in |
|---|---|---|
kernel |
the NSM’s pointwise functions (flux, fluctuations, source, BC states) |
printed by each backend’s kernel printer |
|
a mesh-wide operation or solve: |
declared in |
|
talks to the outside: |
ordered by a token threaded through the graph |
Python if and for in a template run at build time, so an RK tableau is
unrolled. Run-time control flow is While and Cond. The pieces the
templates compose (residual, explicit_step, mood_step, imex_step,
reconstruction, time steps) are in zoomy_core/symsolver/discretization/.
One graph, two printers#
PyPrinter emits Python for NumPy and JAX, CxxPrinter emits C++ for OpenFOAM and AMReX
(zoomy_core/symsolver/backend_cxx.py prints the host program both C++ runtimes compile).
A change to a template changes every backend. A backend decides only how a block is computed.
Code printer: AMReX prints a template as C++.
Two templates#
A backend prints the graph in its language and supplies the building blocks the graph names (gradients, Riemann problems on all faces, reductions, linear solves). Two templates exist, each with one solver class per backend.
template |
solver classes |
for |
|---|---|---|
|
|
balance laws: SWE, SME, Euler, diffusion |
|
|
pressure split ( |
Where to change what#
to change |
edit |
reaches |
|---|---|---|
an equation, a closure, a boundary condition |
the model, its derivation or |
every backend, printed as kernels |
reconstruction, Riemann solver, wave speed |
|
every backend |
time stepping, MOOD, IMEX, Chorin stages |
the template or |
every backend |
a setting shared by all backends |
|
every backend |
a mesh-wide operation |
declare the |
every backend |
a setting of one backend |
the driver class of that backend |
that backend |
how a backend builds, launches or reads back |
the driver ( |
that backend |
Backends hold no numerical constants of their own. A run that needs different operators is fixed in the derivation, never in a printer or a runtime.
What a backend does#
backend |
step |
driver |
|---|---|---|
NumPy |
|
|
JAX |
the same Python source, run against |
|
foam |
|
|
AMReX |
the same |
|
The steps to add a block, a case or a backend are in Extending.
Design notes#
note |
topic |
|---|---|
templates, decisions, gates |
|
distributed runs: partition, halos, reductions |
|
the AMReX runtime, AMR |
|
pressure solvers and preconditioners |
|
the test matrix: cases, thresholds, environment |
|
the timing suite |
|
the thesis QR cases |