← Explainer · Markdown · Source on GitHub

# AMReX alignment

Design and planning, prepared 2026-09-26; numerical deliverables and evidence requirements reviewed against `5c4984e` the same day. **These documents add no runtime capability.**
Current task status and ownership live on the [work board](/docs/WORKBOARD).

The proposed direction is to adopt AMReX's separation of domain, index boxes,
field placement, patch storage and refinement levels within the existing C#/ILGPU
implementation. This is semantic alignment, not an AMReX binding, file-format
compatibility promise or commitment to reproduce its full API.
Prefer AMReX conventions and naming where practical, using C# spelling. The
[alignment design](/docs/amrex-alignment/DATA_MODEL_ALIGNMENT#naming-and-responsibility-migration)
adopts `Box`, `IntVect`, `IndexType` and inclusive bounds, and records why some
application-specific names remain different. Existing half-open loops may consume
explicitly derived endpoints; the convention change must preserve the same samples
and measured performance.

## Read in this order

| Document | Purpose |
| --- | --- |
| [Visual explainer](/) | Illustrated introduction to the concepts, current gaps and delivery sequence. Opens directly in a browser; no server, dependencies or build. |
| [Algorithm companion](/algorithms.html) | Read physical ideas, expand equations, then follow source and validation links. Offline HTML with current/proposed/unresolved labels. |
| [Numerical review reference](/docs/amrex-alignment/ALGORITHMS) | Detailed equations, assumptions, flux signs/units, scalar example, selected periodic MAC candidate, later cut-cell gaps and mathematical/physical review gates. |
| [Embedded-boundary review](/docs/amrex-alignment/EMBEDDED_BOUNDARIES) | Current geometry/wall treatment, source-identified risks and bounded evidence before cuts cross patch interfaces; illustrated in the algorithm companion. |
| [Data-structure alignment](/docs/amrex-alignment/DATA_MODEL_ALIGNMENT) | AMR-02: change the representation of today's supported simulations without adding multiblock or refinement features. Defines proposed contracts, migration steps and acceptance. |
| [GPU execution plan](/docs/plans/gpu-resident-processing) | GPU-01: resident numerical work, measured host setup/control/layout boundaries, current gaps and performance acceptance. Full migration does not block AMR-02. |
| [Boundary-condition alignment](/docs/plans/boundary-condition-alignment) | BC-01: shared setup validation and periodic correspondence. BC-02: qualify single-grid boundary and transport-stage semantics before S2 transport acceptance for the declared scope. |
| [Single-level conservative transport](/docs/amrex-alignment/SINGLE_LEVEL_TRANSPORT) | TRN-01: implement and qualify the specified frozen-carrier MUSCL/SSPRK2 periodic MAC timestep, then bounded method selection and demonstrated accuracy benefit before S2/S3 transport acceptance. |
| [S2 and S3 implementation](/docs/amrex-alignment/S2_S3_PLAN) | Subsequent numerical and workflow work: same-resolution patches, fixed refinement, then adaptation. |

The plans are co-located here at the project owner's request and indexed from
[implementation plans](https://github.com/hankbeasley/polycfd/blob/b7f5b9ba6f52355d9b196b586e4a6c8719d8feea/docs/plans/README.md). Their task status is not duplicated here.
The HTML explains the plans; the Markdown documents define their scope and acceptance.

`python3 tools/publish_explainer.py` stages both explainer pages and the Markdown documents
they link under ignored `output/explainer-site/`. `--out` may select that disposable directory
or a child directory; staging replaces its contents and rejects other locations. Markdown
is readable without JavaScript; its browser formatting uses marked, CSS and pinned
KaTeX assets from jsDelivr.
Publishing rewrites repository links in Markdown prose while preserving equations and code
examples verbatim.
Unpublished repository links, including kernel/test links, point to GitHub at the commit
resolved from `--source-ref` (default `HEAD`). Staging reads the working tree, so commit and
push the intended source before deploying to make the pinned links match the staged content.
Sibling-workspace and uncommitted local evidence links are labeled unavailable local
references; their contents are not published or given fabricated GitHub URLs.

`--deploy` uploads the staged site publicly to the Cloudflare Pages project
`polycfd-amrex-explainer` with wrangler, using `CLOUDFLARE_API_TOKEN` and
`CLOUDFLARE_ACCOUNT_ID`. The explainer is the site root
(https://polycfd-amrex-explainer.pages.dev/). Ordinary staging does not deploy anything.
On Windows, use `py -3.12 tools/publish_explainer.py --deploy`; the script launches
`npx.cmd` for Wrangler. On Linux, use `python3 tools/publish_explainer.py --deploy`.

### Authoring math in published Markdown

Use `$...$` for inline math on one source line, with no inner boundary whitespace,
and standalone `$$` lines around display math. The backslash forms `\(...\)` and `\[...\]` are also
supported; keep display delimiters on their own lines. Inline and fenced code stay
literal. Escape currency dollars as `\$` so prose is not interpreted as math.
The published Markdown viewer loads pinned KaTeX from the CDN; unavailable assets
or unsupported TeX leave readable source instead of hiding the equation. The two
standalone HTML explainer pages remain dependency-free and usable offline.

## Four separate claims

1. **Alignment:** a supported simulation is represented as one level with one patch.
   Existing physics, supported inputs and numerical checks remain unchanged.
2. **Transport:** TRN-01 establishes conservative single-level momentum transport and
   demonstrates accuracy benefit on preselected current workloads. Conservation alone
   does not prove greater accuracy; this numerical change is outside AMR-02.
3. **S2:** one level can be split into communicating patches on one GPU while preserving
   the physical problem and its accepted solution.
4. **S3:** fine regions are coupled to the coarse solution; later regridding changes those
   regions safely. Accuracy, conservation and cost must be established independently.

Preferred integration sequence: **AMR-02 -> TRN-01 -> S2 interface validation -> S3**.
The next numerical task implements and qualifies the
[selected periodic regular-grid MAC candidate](/docs/amrex-alignment/ALGORITHMS#first-regular-grid-mac-candidate):
minmod MUSCL/SSPRK2 with frozen accepted carriers, prescribed sources, the existing
old-pressure predictor, backward-Euler diffusion and one primary projection. The
[transport plan](/docs/amrex-alignment/SINGLE_LEVEL_TRANSPORT#next-deliverable-one-complete-regular-grid-mac-timestep)
defines the GPU scratch and stage contract. Full evolving flow is first order in
time, including the inviscid case; prescribed steady-carrier transport is second
order in time. Spatial reconstruction is nominally second order in smooth regions,
with order reduced by limiting. Runtime implementation and CUDA qualification remain
future work, alongside [PRJ-01 pressure qualification](/docs/amrex-alignment/ALGORITHMS#pressure-solver-qualification).
The audit starts from completed SOL-02: retained coarse RHS, adjoint restriction and
Chebyshev smoothing are implemented, not proposed repairs. Remaining true-residual,
final-continuity and periodic-geometry limits need bounded evidence. Then work through
the [S3-01 two-level pressure example](/docs/amrex-alignment/S2_S3_PLAN#first-two-level-pressure-example)
before implementing composite coupling; that research need not wait for transport
completion or block alignment. Keep the equation and its efficient solution distinct.

Each experiment must bind a precise claim to a pinned implementation, exact inputs,
reference, predeclared metrics/limits, CUDA command, artifact and explicit verdict.
Pending experiments remain not run. Freeze accuracy targets before measuring total
time to the same endpoint and error target, including pressure solves and live memory.

GPU-01 keeps fields and repeated numerical work resident while permitting bounded,
measured host control/layout metadata and setup. Full migration is independent of
AMR-02; alignment must preserve science and measured performance and introduce no
bulk numerical readbacks. New transport and patch/refinement operations satisfy the
policy for their scope without waiting for unrelated legacy migration. Explicit final
output is separate from control metadata and cannot hide CPU numerical feedback.
Budget experiments can begin earlier and S2 layout work can overlap, but its transport
interfaces must follow the validated method. Scalar work can support T1 without
claiming temperature functionality from a test harness.

[BC-01/BC-02](/docs/plans/boundary-condition-alignment) can proceed alongside alignment
and TRN-01. AMR-02 preserves existing numerical behavior; boundary corrections need
their own evidence. Qualify each method's physical boundaries on one grid before
accepting its S2 transport. Spatially mixed pressure/velocity BCs are deferred and
are not prerequisites for AMR-02, basic S2 or S3.

TRN-01 retains scientifically useful methods behind one recorded choice per run.
Geometry, motion and patch/refinement support are qualified per method; initial S3
can support only the accepted conservative method. Unknown or unsupported choices
must fail explicitly. Current runtime methods and defaults are unchanged by these plans.

One coarse patch covering the whole physical domain is a reasonable initial S3
constraint. It does not remove the need for same-level fine-patch interfaces or
coarse/fine coupling. An AMR level and a multigrid solver level are different objects.

The [naming and responsibility migration](/docs/amrex-alignment/DATA_MODEL_ALIGNMENT) separates boundary
regions from mesh patches, domain coordinates from embedded-boundary sources/data,
and authoritative field layouts from compact kernel descriptors. Keep level-wide
coordination with patch-local kernels, canonical field placement and distinct physical
refinement/multigrid identities. The numerical state remains MAC-staggered.

## Scope of this documentation task

AMR-01 established this folder; AMR-01a adds the transport recommendation; AMR-01b
adds bounded method selection and the algorithm review path; AMR-01c adds naming,
architecture and an initial strict GPU policy. AMR-01e revises that policy to preserve
performance while aligning with AMReX: resident numerics, bounded measured metadata,
host setup and independent AMR-02 acceptance across plans, guides and the explainer.
AMR-01f makes practical AMReX naming and inclusive box semantics the preferred
implementation direction, with explicit conversions and documented differences. AMR-01g
repairs boundary references and adds shared validation and single-grid boundary
qualification to the plans, retaining separate numerical acceptance. AMR-01h makes
the complete regular-grid timestep, post-SOL-02 pressure qualification and two-level
pressure example concrete deliverables, with stage tables and executable evidence
requirements in the existing plans. The current update selects the first periodic
candidate, fills its stage/resource contract and adds published Markdown math
rendering; it does not implement or qualify that numerical method. Documentation
acceptance is repository static verification plus visual/link checks of the explainer.
Completing these documentation tasks does not complete GPU-01, AMR-02, TRN-01, S2 or S3
or establish mathematical or physical correctness of a proposed algorithm.
No W4 decision, schema identity, scientific reference or performance allowance changes here.

## Reference map

- [AMReX basics](https://amrex-codes.github.io/amrex/docs_html/Basics.html): box and field concepts.
- [AMReX AmrCore](https://amrex-codes.github.io/amrex/docs_html/AmrCore.html): hierarchy lifecycle, filling and synchronization.
- [AMReX linear solvers](https://amrex-codes.github.io/amrex/docs_html/LinearSolvers.html): multilevel elliptic operators and multigrid.
- [AMReX-Hydro projections](https://amrex-fluids.github.io/amrex-hydro/docs_html/Projections.html): incompressibility and projection.
- [AMReX-Hydro boundary conditions](https://amrex-fluids.github.io/amrex-hydro/docs_html/bcs.html): Godunov boundary states, backflow policy and limits of mixed-BC support; compare with the [current boundary guide](/docs/BOUNDARY_CONDITIONS_HALOS) and [algorithm review](/docs/amrex-alignment/ALGORITHMS#boundary-conditions).
- [AMReX-Hydro methods](https://amrex-fluids.github.io/amrex-hydro/docs_html/) and [IAMR algorithm options](https://amrex-fluids.github.io/IAMR/docs_html/AlgorithmOptions.html): candidate transport references and formulation choices.
- [AMReX embedded boundaries](https://amrex-codes.github.io/amrex/docs_html/EB.html): geometric database and cut-cell data.

Official references were consulted on 2026-09-26. Their development documentation
can change; before implementation, record the AMReX release/commit used for any
algorithm or interoperability comparison. PolyCFD-specific contracts below are
design proposals, not claims that AMReX prescribes our implementation.