Skip to content

CAMR::construct_hydro_source (EB): regular-box fallback is decided on grow(bx,2|3) but the non-EB kernels read to distance 4 and flatten() differs from flatten_eb() there, so face fluxes at box boundaries near the body depend on the box layout #111

Closed

Description

@WeiqunZhang

Severity: medium · Category: eb
Locations: Source/Hydro/CAMR_construct_hydro_source.cpp:161-169, Source/Hydro/CAMR_construct_hydro_source.cpp:255, Source/Hydro/Godunov/flatten.H:28-33,79-84,129-133, Source/EB/eb_utils.H:7-21
Based on commit 17997db (line numbers refer to that tree).

The defect

In EB builds every tile is routed either to the EB path (hydro_umdrv_eb) or, when
flagfab.getType(grow(bx,ngrow_bx)) is FabType::regular, to the plain non-EB hydro_umdrv
(CAMR_construct_hydro_source.cpp:161-169,255), with ngrow_bx = 2 (FluxRedist/NoRedist) or 3
(StateRedist).

The non-EB kernels do not stop reading at distance 2. The cells whose traced states reach the
final fluxes on the faces of bx are those of bxg1 = grow(bx,1) (T3/T4), and for those cells
flatten reads q at +-3 through its shifted stencil (flatten.H:28-33,79-84), i.e. at distance
4 from bx, and plm_slope (order 4) reads +-2, distance 3. Only distance <= 2 (or 3) is
guaranteed regular. Two things can therefore sit inside the used stencils:

  • covered cells at distance 4 (q = 0, CAMR_construct_hydro_source.cpp:133). They enter only the
    qppshft/qmmshft denominator of flatten (flatten.H:83-88, guarded by max(small_pres,..)),
    because a cell face-adjacent to a regular cell cannot be covered, so the tmp = min(..) operands
    at +-2 are never covered. No inf/NaN for used cells (T3's concern), but see next point;
  • cut cells at distance 3. The EB path evaluates the very same cell with flatten_eb
    (flatten.H:129-133), which returns 1 (no flattening) as soon as is_cut_neighborhood
    (eb_utils.H) finds a single-valued cell within 3 cells along the direction, whereas the
    fallback evaluates the Colella-Woodward flattening on the data. plm_slope_eb only degrades on
    covered neighbours, so it agrees with plm_slope for all used cells; the flattening
    coefficient, which multiplies every slope, is the difference.

Concrete 2D case (Godunov, FluxRedist, use_flattening = 1 default): tile A bx = [0,15]x[0,15],
tile B bx = [16,31]x[0,15], cut cell at (19,8). grow(bxA,2) = [-2,17]^2 is regular, so A takes
the fallback; grow(bxB,2) contains (19,8), so B takes the EB path. Cell (16,8) is in A's bxg1 and
in B's bx. A computes flatten(16,8,dir=0) from p,u at i = 13..19 and gets < 1 if a shock is near
i ~ 15-17; B computes flatten_eb(16,8,0) = 1 because of the cut cell at (19,8). The right state
on the shared face i = 16 (qxp(16,8)) therefore differs, hydro_cmpflx on face (16,8) yields two
different fluxes, A updates (15,8) with one and B updates (16,8) with the other. Same in 3D and
with StateRedist (ngrow_bx = 3 is still < 4).

Why it matters

The update is not conservative across the tile/grid boundary (the two sides of one face use
different fluxes), and the answer near the body changes with amr.max_grid_size, hydro_tile_size
(CPU tiling is on by default: hydro_tile_size = 1024,16,16) and the MPI decomposition, whenever a
shock is within the flattening stencil of a cell that is within 3 cells of the body and a box
boundary runs through that region. A single-box run and a two-box run of the same problem give
different results; the difference is O(1) in the flattening coefficient of the affected cells.

How to reach it

Exec/SodPlusSphere (USE_EB = TRUE) with CAMR.do_mol = 0 (Godunov; the shipped inputs use
do_mol = 1, where the MOL slopes read only +-1 and this particular mechanism does not apply), default use_flattening = 1, amr.max_grid_size = 16 vs 64:
the shock from the Sod interface hits the sphere at x = 0.7; cells 1-3 cells upstream of the
sphere that fall into different boxes get different flattening. DIM = 2 or 3, CPU or GPU.

Suggested fix

Take the fallback only when grow(bx,4) is entirely regular (keep bxg_i for the EB path). Then
every cell whose stencil reaches the faces of bx has no cut cell within +-3, so
flatten_eb == flatten, plm_slope_eb == plm_slope, and eb_divu == hydro_divu (all cells around
the relevant nodes are regular): the two paths produce identical fluxes on shared faces.
numGrow() >= 5 in every EB configuration, so the flag fab (basic grow = numGrow,
Source/main.cpp:112) covers grow(bx,4).

--- a/Source/Hydro/CAMR_construct_hydro_source.cpp
+++ b/Source/Hydro/CAMR_construct_hydro_source.cpp
@@ -166,7 +166,14 @@ CAMR::construct_hydro_source (const MultiFab& S,
            ngrow_bx = 2;
         }
         const Box& bxg_i  = grow(bx,ngrow_bx);
-        if (flagfab.getType(bxg_i) != FabType::regular) {
+
+        // The non-EB kernels used in the fallback read q up to 4 cells outside
+        // bx (flatten: +-3 around the bxg1 ring) and flatten_eb() returns 1
+        // within 3 cells of a cut cell, so the two paths give the same fluxes
+        // on the faces of bx only if grow(bx,4) is entirely regular.  numGrow()
+        // is at least 5 in EB builds, so the flag fab covers this box.
+        const Box& bx_reg = grow(bx, amrex::max(ngrow_bx, 4));
+        if (flagfab.getType(bx_reg) != FabType::regular) {
 
             EBFluxRegister* fr_as_crse = nullptr;
             if (do_reflux && level < parent->finestLevel()) {

(git apply --check OK; scratch copy in audit/notes/T5-scratch/006-fallback-grow4.diff.)

Activity

  1. added a commit that references this issue on Nov 17, 2026
    ca188fb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions