Skip to content

AMR follow-up: STL regrid and motion, controllers with an IB, fine T_cond restart, chemistry IB wall, subcycling with bubbles, IGR, moving bodies, any depth and ratio 4, particles - #2539

Draft
sbryngelson wants to merge 37 commits into
MFlowCode:masterfrom
sbryngelson:amr-followup

Conversation

@sbryngelson

@sbryngelson sbryngelson commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Contribution Policy

All contributions are expected to demonstrate:

  • A clear understanding of the codebase
  • Alignment with product direction
  • Thoughtful reasoning behind changes
  • Evidence of real-world usage or hands-on experience with the problem

If these expectations are not met, we would prefer to implement the changes ourselves rather than spend time reviewing low-effort submissions.

Follow-up to #2536.

Closes #2240, closes #2232, closes #2255, closes #2244, closes #2225, closes #2231, closes #2226, closes #2233, closes #2266.

Where the remainders live. #2543 to #2554 hold the follow-up work, with #2227, #2228, #2229 and #2230 already open. QBMM (#2235) stays open: it segfaults at start-up under AMR on GPU.

Draft until the final GPU, Cray and NVIDIA runs on this head pass.

Added since opening:

The full verification runs once those are in.

What is in it

Item Change Check
#2240, STL bodies with regrid and motion s_get_ib_aabb gives an STL body's rotated box for s_amr_body_bbox. Fixes a segfault: the initial blocks were placed before the STL models were loaded. Against a uniform 128² run: static with regrid 3.9e-12 (analytic circle 3.8e-12); translating 2.4e-3 (circle 5.7e-3, the known moving-body difference)
#2231 with an immersed body The fine body-force hook loads the block's own markers. amr_check block core: mean_dpdx 2.5e-3 → 8.9e-9; mean_qdot with chemistry 1.7 → 2.0e-12
Restart of the fine blocks' ghost T_cond One restart file per level, filled from the parked fine ghosts. Restart against a straight run, isothermal body: 6.8e-2 relative → within the test tolerance
Block-edge difference in #2536's chemistry-diffusion IB check Documented in amr.md; no code change. It comes from the coarse/fine ghost fill at a composition jump that crosses the block edge, not from the body: it is present without the body, and it moves with the jump. Cells one in from the edge match to 2e-11
#2226, isothermal wall with chemistry Validator only, now that #2536 has fixed the fine T_cond. amr_check: inert 3.2e-11; 1200 K with gas reactions 5.7e-12
#2232, amr_subcycle with Lagrangian bubbles Validator only; the update order was already right. Subcycled against lock-step: bit-identical away from the block
#2244, subcycling at any depth and at amr_ref_ratio = 4 amr_ref_ratio substeps with 1/ratio fractions in the recursive driver. Existing subcycled goldens bit-identical; three-level mass −9.1e-13; ratio 4: 3e-16 static, 0 dynamic
#2225, amr_subcycle with prescribed motion Each fine stage sets the bodies' pose at its own time. Translating circle against uniform 128²: 1.9e-10 near the body
#2232, amr_subcycle with IGR (single rank) The coarse sigma is blended to each fine stage's time. Block core against the uniform fine grid: 9.5e-6, against 1.1e-5 lock-step (IGR's coarse/fine truncation error)
#2255, Lagrangian particles on level 0 Guards on the particle dynamics, the two-way source and the gradients in the fine RHS; a particle support box; the Lagrangian-bubble AMR hooks extended to particles. Against the no-block run: 3e-11; np = 2 against np = 1: 1e-14; a block over the particles aborts with a message
amr_check under a batch job run_amr_check passes the test command's run arguments (-c <computer>) to its inner runs. Every amr_check test passes inside a Frontier job; on master none did (see the correction below).

Still rejected

  • surface_reaction;
  • thermal_bc = 2 and 3, and thermal_layer;
  • mean_temp_wall: it needs its own temperature scratch space in the fine RHS;
  • force-driven motion under subcycling;
  • amr_prolong = 2 at ratio 4.

1. Does it solve the problem?

See the check column above: each item compares against a uniform fine grid, a no-block run, a lock-step run or an exact invariant.

2. Does it create another one?

Check Result
Tests Each item's own runs, CPU: AMR 170/170, IGR 28, Lagrange bubbles 33, Lagrange particles 30 (time-stepping items); AMR 162, IBM 145, Chemistry 80 (IB/thermal items); validator unit tests 217–218. The full run of this combined branch is pending.
Golden files changed None
GPU compile amdflang --gpu mp and CCE --gpu acc/--gpu mp on each half; the combined branch is pending
Not tested The combined branch on GPU, NVIDIA, the full suite and the benchmark (pending)

3. Is it slower?

Pending: benchmarked on an MI250X against master once the branch is final.

Made with Claude Code.

…inner runs

Every other test forwards the arguments after the test command's "--" (e.g.
-c <computer>) to ./mfc.sh run; run_amr_check did not, so inside a batch job
the amr_check inner runs used the default template and failed. 11 of the 13
amr_check tests now pass inside a Frontier job (none did); the two chemistry
ones still need their case-specific build, which a Frontier compute node
cannot make.
…#2240)

s_amr_body_bbox bounds an STL body (geometries 5, 12) by the model's
rotated box, from the new s_get_ib_aabb that s_get_bounding_indices now
shares, so regrid keeps the blocks containing the body. The STL models
and the body orientations are set up before the initial blocks are
placed, which read that box.

Against a uniform 128^2 run over the body (coarse cells 24..39), 20
steps: a static Circle_IBM.stl body under regrid every 2 steps differs
by 3.9e-12 (the analytic circle: 3.8e-12); the same body translating at
0.5 differs by 2.4e-3 (the analytic circle: 5.7e-3, the moving-body
difference documented for ib_mass_relax). On the PR head both runs are
rejected, and s_amr_body_bbox aborted for STL.
…lowCode#2231)

The fine body-force hook zeroed mean_dpdx/mean_mflux and mean_qdot/
mean_temp in solid cells by the coarse ib_markers read at block indices.
It now loads the block's own markers (ib_markers_fine) and
s_compute_body_forces_rhs takes the frame's markers, so the ib
exclusion for both controllers is lifted.

amr_check against the uniform fine grid, static circle on a periodic
block (block core): mean_dpdx(1) = -5 differs by 2.5e-3 on the PR head
and 8.9e-9 now (the same case without the source: 8.9e-9 next to the
body); chemistry diffusion with mean_qdot = 1e11: 1.7 before, 2.0e-12
now.
The 1.3 at the block edge of the chemistry-diffusion IB amr_check is
y-momentum, 8e-5 kg/(m^2 s) after one step, on the edge cells over the
H2/air jump. It is the same without the body and follows the jump when
it is moved along the edge (x = L/2 to 0.4 L); a smaller body, ten
coarse cells off the edge, gives the same 8e-5. The coarse grid alone
has none there. With the body its flow sets the y-momentum scale to
3e-4, hence 1.3; without it the scale is 1 and the edge reports the
x-momentum 5.6e-3. The cells one in match the uniform grid to 2e-11.
With chemistry the isothermal wall (thermal_bc = 1) sets only the ghost
state and its T_cond, which each fine block now takes from its own
ghosts (s_ibm_fine_conduction_temperature), so the validator allows it.
The reacting surface (its wall sources are coarse-grid state), the
lumped and energy-balance walls, and the initial thermal layer stay
rejected.

amr_check against the uniform fine grid, H2/air diffusion past the
static circle (block core): Twall = 400 K inert, 3.2e-11; Twall =
1200 K with the gas reactions on, 5.7e-12. Rejected on the PR head.
The ib_tcond restart file held only the coarse ghosts, so a restarted
AMR run with chemistry diffusion and a body started the fine ghosts
without their T_cond. Each level now writes its own file
(ib_tcond_<step>_L<lev>.dat, the same format keyed by the level's global
cell index) from the ghosts parked in gp_park, and the restart reads it
back after s_amr_setup_ib. The writer and reader are split so the
coarse and fine files share them.

Restart roundtrip of a 4-step H2/air diffusion case past a static
isothermal circle (Twall = 400 K) on a static block: on the PR head the
restarted run differs from the straight run by 1.25 absolute
(6.8e-2 relative) in the conserved fields; now it matches within the
test tolerance.
The cloud advances with level 0's stages before s_amr_subcycle_fine runs; the
fine RHS skips the EL hooks (.not. amr_in_fine_advance) and the per-stage
overlap check and the regrid clipping keep the blocks clear of the cloud, so
the subcycled fine substeps never read or write the bubbles. The ordering is
correct as is: lift the rejection.

Check (2D two-way bubble case, a pressure patch inside a static block):
subcycled against lock-step, the bubble history and every cell away from the
block are bit-identical; inside the block they differ by 9e-8 (lock-step
against the no-block run: 3e-5).
)

s_amr_subcycle_level took two substeps per parent step with literal 0.5
factors. It now takes amr_ref_ratio substeps of dt/ratio, with fractions
1/ratio; at ratio 2 every factor is the same power of two, so the two-level
results are bit-identical (the existing subcycled goldens regenerate
unchanged). Level >= 2 blocks already blend their parent's substep-start
backup (amr_stor_st) per block, so depth needs nothing more. Lift the ratio and
depth rejections; amr_prolong = 2 stays ratio 2.

Checks: three-level subcycled Sod conserves mass and energy as lock-step does
(-9.1e-13, -1.3e-12; the same boundary loss); ratio 4, two levels, static and
dynamic: 3e-16 and 0. A smooth periodic density wave: subcycled minus
lock-step is 6.5e-7 (three levels, ratio 2) and 3.5e-8 (ratio 4) and halves
with dt; mass and energy stay within 4e-16.
Under subcycling the coarse step moves the bodies to the step-end pose before
the fine substeps, which never rebuilt their IB data. Each fine stage now sets
the bodies to the pose of its own time (s_amr_ib_pose: the kinematics for
kin_model > 0, else the blend of the step-start and step-end poses), and after
the stage sets the pose of the state it produced and runs the rebuild and
correction the stage left waiting (s_amr_fine_stage_ib). The end pose is
restored exactly. Force-driven bodies stay rejected: their force needs the fine
faces at the coarse stage.

Check (translating circle, static 2:1 block, 20 steps): subcycled against a
uniform 128^2 run at the fine dt: 1.9e-10 near the body, 8.8e-9 over the
block; lock-step against 128^2 at its dt: 4.7e-12 and 4.3e-9.
The fine sigma seed read the coarse sigma left by level 0's last stage (stage
time 1/2 for RK3) at every substep. Keep the coarse sigma solved at stage times
0 and 1 (stages 1 and 2) and blend it to each fine stage's time before its
seed; restore the step-end sigma after the substeps (the coarse warm start).
IGR has no flux registers, so the coupling stays restriction-only.

Check (2D IGR case, static block, single rank): block core against the
uniform fine grid, density 9.5e-6 subcycled (fine dt) and 1.1e-5 lock-step;
the coupling's truncation error dominates both.
- m_rhs: the particle dynamics, the two-way source and
  s_compute_particle_gradients run on the coarse grid only
  (.not. amr_in_fine_advance), as the bubble hooks do.
- s_lag_particle_bbox_local, and s_amr_lag_bbox_local picking the bubble or
  particle cloud; the regrid clipping (s_amr_compute_lag_supp), the per-stage
  overlap check (s_amr_check_lag_clear) and the coarse-halo hoist exclusion
  now key on euler_lagrange. The mapCells + 2 pad covers the particle kernel
  (1 cell), interpolation (<= 3) and gradient stencils. The alpha closure is
  kept: the particles' fluid alphas sum to one.
- Vet particles_lagrange and particle_params%*; this lifts the specific
  rejection added in 9ac1124.

Checks (2D, a static block across the y = 0.8 jump, clear of the particles):
one-way and two-way against the no-block run: 3e-11 away from the block,
particle histories within 1e-16; np = 2 runs (no stall) and matches np = 1 to
1e-14; a block over the particles aborts with the overlap message.
@sbryngelson sbryngelson added the claude-full-review Trigger Claude Code review label Nov 28, 2026
@github-actions

Copy link
Copy Markdown

Claude Code Review

Head SHA: 5ade0b8

No review was produced. Claude ran but wrote no review (Claude step: failure). Run and transcript: https://github.com/MFlowCode/MFC/actions/runs/46091352093

@github-actions

Copy link
Copy Markdown

Claude Code Review

Head SHA: 5ade0b8

No review was produced. Claude ran but wrote no review (Claude step: failure). Run and transcript: https://github.com/MFlowCode/MFC/actions/runs/46091358107

…bsteps

Under amr_subcycle the reports ran before s_amr_subcycle_fine, so the
substeps' counts landed a step late and the last step's were lost.
The static builder insets each level in its parent without looking at
the bodies, so from level 3 on a body could straddle a level boundary
with no abort. Master rejected static amr_max_level > 2 outright; keep
that rejection when ib = T.
The static builder aborts unless amr_max_blocks >= level-1 block count
+ amr_max_level - 1; the validator checked only amr_max_blocks >= 2.
With at least one level-1 block, require amr_max_blocks >= amr_max_level.
Operator-split reaction and burn substeps now run on each block, STL
bodies are allowed on static blocks, and the isothermal wall is allowed
without chemistry; multi-level needs amr_max_blocks >= amr_max_level.
A pointer to the current frame's markers (ib_markers, or ib_markers_fine
in the fine advance) replaces the six if/else pairs that repeated each
call with only the marker field changed. The callee still receives the
module variable itself, so device presence is unchanged.
The coarse set, coarse restore and fine-frame paths were three copies of
the same ghost loop; s_ibm_conduction_temperature(q_T_sf, set) holds the
coarse and fine forms. The fine path keeps one kernel per batch member.
With chemistry and burn substeps, s_amr_split_fine swapped every block in
and out twice. Both are cell-local, so one pass per block runs both.
The fine RHS and the fine reaction substep write their temperatures into
q_T_sf at block-frame indices, so level-0 cells (inside and outside the
blocks) took the next conversion and split guesses from unrelated fine
cells. Save and restore q_T_sf around the fine stage, the subcycled
advance and the fine split. In a reactive shock tube with a static block
on the front this moves minor species by up to 1e-7 relative (Newton
tolerance level); flow variables agree to 4e-13.
…arse boundary fill

s_get_capillary filled the ghost layer of the colour-function gradient with
s_populate_capillary_buffers, which on a fine frame applies the coarse grid's
physical or MPI boundary at the block faces (at np = 1 with periodic bc, a copy
across the slab). On fine frames the gradient is now computed one layer into the
block's own ghost primitives and the boundary fill is skipped; the coarse path is
unchanged.
The capillary stress and work ride on flux_src_rsx_vf (mom..E), which the
registers captured only if viscous, so an inviscid surface-tension run was not
refluxed at coarse/fine faces.
The colour function's rhs pairs its advective flux with c*(u_r - u_l)/dx, as a
volume fraction does, but only the flux was refluxed, so c drifted in the coarse
cells along a block face (to 0.95 inside a droplet) and the spurious colour
gradient drove currents there. eqn_idx%c joins the face-velocity corrected
equations with coefficient c.
Vets surface_tension under AMR with amr_max_level = 1 (static or regridded
blocks, lock-step or subcycled, multi-rank); multi-level stays rejected.
Tests: a static capillary droplet whose block cuts the interface (one and two
ranks, regrid, amr_subcycle) and an amr_check of a square drop.
The compact face-normal gradient is already the default with weno_Re_flux, and fine
frames difference across the face with the block's own spacing. An explicit T was
rejected only because the flag was missing from the vetted list.
grcbc_in, grcbc_out and grcbc_vel_out only change the characteristic BC's L, which
s_cbc applies on the coarse grid at the domain boundary; fine frames return before it.
Golden: a 1D static block with a GRCBC inflow and outflow.
post_process reads level 0 with the fine solution restricted into it, as for its other
derived outputs. The volume and total energy sums equal the composite ones, since the
restriction conserves them; the kinetic and internal energies are level-0 values.
This was referenced Nov 28, 2026
The coarse stages move a two-way body on their own faces; the fine
substeps then collect their faces' impulse (substep dt times the stage
weight) less the covered coarse faces', and after the substeps that
difference corrects the body's step-end velocity and pose, as the
reflux does for the fluid. Each fine stage sets the pose at its own
time, as for prescribed motion. The validator no longer rejects
moving_ibm = 2 with amr_subcycle.
The fine blocks' thermally developed source reads each member's own
temperatures, copied from the batch slab at its offset with the
primitive state, and the viscous-dissipation removal in the fine RHS
uses the block's markers. The source arrays are sized for the fine
frames. The coarse source already reads the level-0 temperatures after
the fine stage: mean_temp_wall requires chemistry, whose fine passes
save and restore them. The validator no longer rejects mean_temp_wall
with amr. The thermal channel example gains a --body option (an
isothermal square) for the AMR tests.
Without ib_flux_wall (still rejected under AMR, MFlowCode#2230) a reacting wall is
ghost state only: each ghost point solves the surface balance from its
image point and sets its ghost state and T_cond, which the per-block
swap and gp_park already carry. ib_wall_src is read only under
ib_flux_wall, so it needs no per-block storage. Lift the surface_reaction
gate; thermal_bc = 2, 3 and thermal_layer stay rejected. The surface
report says its counts cover all AMR levels.

run_amr_check put a second "--" before the test command's run arguments
when a case had its own (-j 4), which hid -c <computer> from the inner
runs: the chemistry amr_checks failed inside a batch job for that reason.

Checks (MI250X, amdflang OpenMP offload):
- amr_check, the 2D_ibm_reacting_surface wall (1200 K, gas reactions)
  in a closed box with the body in the block core: 9.8e-11 (inert wall
  9.8e-11); before: rejected.
- 200 steps, block vs no block against the uniform 2x grid: CO the wall
  produced 1.1e-5 off (coarse 1.2), gas mass and energy within 2R of the
  body 3.4e-6 and 1.6e-6 (coarse 2.4e-4 and 1.2e-3).
The bubble variables are ordinary conserved variables, the bubble source
and the divergence it reads are cell-local on the block's own grid, and
the adv_n closure already runs per block (m_stage_hooks). Two seams
remain: s_compute_ptilde wrote the level-0 probe field ptil from the fine
frames (now skipped there), and adap_dt advances the bubble ODE on level 0
only (rejected under AMR). Allowed: one fluid, polytropic, with adv_n or
polydisperse; rejected: adap_dt, QBMM (an AMR run segfaults at start-up),
non-polytropic, num_fluids > 1, amr_prolong = 2 and immersed bodies.
The shared bubble test parameters move to BUBBLE_EE_MODS (the existing
cases' parameters are unchanged).

Checks (MI250X, amdflang OpenMP offload), before: rejected:
- amr_check, block core against the uniform 2x grid after one step:
  1D 1.3e-11, adv_n 1.3e-11, polydisperse (nb = 3) 1.8e-11, RK2 1.3e-11,
  2D (block split in four members) 1.3e-11.
- Evolving cloud, no acoustic source: 2D bubbly liquid (4 % void) with a
  square at twice the pressure inside the block, L1 error against the
  uniform 2x grid inside the block, block over coarse: at t = 1, 0.13
  for density, energy, void fraction and nR, 1.13 for momentum, 0.99
  for nV; at t = 2 and 3, 0.34 to 0.61 for every variable.
…walls are now tested

The suite lint requires every AMR-vetted flag to be set by an AMR test: adv_n
and polydisperse were covered only by amr_check convergence cases, so a static-
block golden of each joins the existing bubbles_euler one. The mean_temp_wall
tests set bc_[xyz]%isothermal_*, so it leaves AMR_UNTESTED_FLAGS.
# Conflicts:
#	toolchain/mfc/case_validator.py
@github-actions

Copy link
Copy Markdown

Lines of Code

File Lines Diff
src/simulation/m_ibm.fpp 4247 +109
src/simulation/m_amr_stage.fpp 413 +88
src/simulation/m_amr_advance.fpp 446 +86
src/simulation/m_rhs.fpp 2212 -31
src/simulation/m_amr_store.fpp 492 +16
src/simulation/m_particles_EL.fpp 922 +16
src/simulation/m_amr_state.fpp 463 +15
src/simulation/m_ib_patches.fpp 666 -11
src/simulation/m_start_up.fpp 1564 +9
src/simulation/m_body_forces.fpp 691 +7
src/simulation/m_amr_registers.fpp 704 +3
src/simulation/m_amr_distribution.fpp 623 +2
src/simulation/m_time_steppers.fpp 1061 +2
src/simulation/m_amr_regrid.fpp 913 -1
src/simulation/m_surface_tension.fpp 265 +1
Directory Lines Diff
simulation 43684 +311
total 63801 +311

NVHPC 25.5 and 25.11 on a V100 differ from the amdflang MI250X goldens by up to
2.5e-10 (DCA29D70, through the regrids) and 1.3e-10 (5EF5DE01), past the 1e-10
bubble default; 1e-9 keeps a 4x margin.
…ance

override_tol = 1e-9 dropped their single comparison to the 1e-4 floor (it was 1e-2,
the bubble default scaled for single); a --single run differs from the double
golden by 5.5e-4.
@sbryngelson

Copy link
Copy Markdown
Member Author

CI fix (2ceafb7): single-precision tolerance for the static-block bubble goldens

In the GNU no-debug (--single) lane, 5EF5DE01 (bubbles_euler) and D379DF5E (polydisperse) failed against the double-precision goldens. The largest errors were in the bubble variables of prim.3, the last saved step: 2.3e-2 relative (1.3e-2 absolute) against the 1e-2 tolerance.

These three static-block tests now use override_tol_single=5e-2. The double-precision tolerance stays at 1e-9. UUIDs and goldens are unchanged, and the precheck passes.

(Posted with Claude Code.)

@sbryngelson

Copy link
Copy Markdown
Member Author

CI fix (856483b): GRCBC relaxation length under AMR

4B973840 (AMR -> 1D -> static block -> grcbc) failed on the GNU and Intel no-debug lanes. Both gave the same wrong state: the cells at both domain ends stayed at their initial values, for example density 1.00003 at the inflow cell against 1.0594 in the golden.

Cause. s_initialize_cbc_module set the relaxation lengths as Del_in = Del_out = maxval(dx). With AMR, dx is allocated to m_alloc, the size of the largest block, and the entries beyond the coarse grid are never set. A debug print on a CPU build showed Del_in = 8.4e276, which makes every GRCBC term zero. The GPU builds happened to read benign values there, so the golden and the GPU lanes were unaffected.

Fix. The reduction now runs over the grid's own range, dx(-buff_size:m + buff_size) (and dy/dz likewise). Without AMR that is exactly the old range, so non-AMR results are bit-identical.

Checks (Frontier):

Check Result
CPU (amdflang), 4B973840 passes against the existing golden
MI250X (--gpu mp), 4B973840 passes against the existing golden
MI250X, the non-AMR grcbc x tests 3/3 pass
CPU: AMR against no AMR, same case, before the fix boundary cells differed by up to 0.22
GPU: AMR against no AMR, same case agree to 5e-7 (the block's own difference)

The golden is unchanged, and the precheck passes.

(Posted with Claude Code.)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment