Skip to content

weno_Re_flux with IBM reads solid cells past gp_layers, making viscous results compiler-dependent #2041

Backlog

Description

@sbryngelson

Summary. With weno_Re_flux = T and ib = T, the viscous WENO reconstruction reads solid cells that the immersed-boundary treatment never assigns, because gp_layers is smaller than the viscous stencil's reach. Those cells hold whatever was last in memory, so the result is compiler-dependent.

The arithmetic.

  • gp_layers = 3 is a fixed parameter (src/common/m_constants.fpp): the IBM assigns ghost values to solid cells within 3 layers of fluid.
  • The viscous reconstruction needs 2*weno_polyn + 2 cells of valid data — which is exactly what s_initialize_global_parameters reserves for the halo in the viscous branch (src/common/m_helper_basic.fpp: if (viscous) buff_size = 2*weno_polyn + 2).
  • For weno_order = 5, weno_polyn = 2, so the stencil wants 6 cells but only 3 are filled. Cells 4-6 deep into the solid are read and never written.

Evidence. A 2D viscous + IBM case with weno_Re_flux = T, fd_order = 4, weno_order = 5, an isothermal rectangle IB, 30 steps, run identically under two compilers (Cray CCE 20 and AMD amdflang/AFAR 24.3.0, both CPU, serial, same source tree and same inputs):

gp_layers max relative difference, Cray vs amdflang
3 (default) 5.2e-02 (y-momentum next to the body)
6 0.0 — bit-for-bit identical across every output value

gp_layers = 6 is 2*weno_polyn + 2 for weno_order = 5, i.e. exactly the depth that makes the stencil's reads land on assigned cells. Nothing else changed between the two rows.

A companion observation: four viscous IBM tests without weno_Re_flux differ between the same two compilers by only 1.3e-10 to 3.6e-10, i.e. ordinary floating-point noise. The 5e-02 scale appears only when weno_Re_flux = T.

Why it matters.

  • Results depend on the compiler (and, in principle, on anything else that changes what was previously in those cells), which defeats golden-file comparison across CI lanes. MFC's test tolerance for IB cases is 1e-10, and 5e-02 is eight orders of magnitude past it.
  • It is reading memory that was never written for this purpose, so the values are not meaningfully bounded.
  • Master's own suite pairs weno_Re_flux with ib = T in many cases, so this is reachable upstream, not only in a downstream branch.

Suggested fix. Make the filled depth cover the stencil that reads it: require gp_layers >= 2*weno_polyn + 2 when viscous (and weno_polyn + 2 otherwise), rather than hardcoding 3. That means gp_layers becomes a value set during initialization from weno_order and viscous instead of a parameter. Alternatively, restrict the viscous reconstruction stencil near immersed boundaries so it never reads beyond the filled layers.

Raising gp_layers costs ghost points (memory and the per-point work), so tying it to the stencil rather than globally raising it seems preferable.

What I verified vs inferred: the two table rows are measured, on the same tree with only gp_layers changed. The identification of 2*weno_polyn + 2 as the required depth is inferred from the matching buff_size expression and from 6 being the value that produces bit-identical output; I did not instrument the stencil to log its exact index range.

Found while validating IB ghost-state changes with Claude Code.

Activity

  1. sbryngelson commented on Oct 12, 2026

    @sbryngelson
    MemberAuthor

    Correction to the "Why it matters" section above. I wrote that master's test suite pairs weno_Re_flux with ib = T in many cases. That is wrong, and I should not have claimed it — it came from a crude text-window search that spanned unrelated cases.

    Walking toolchain/mfc/test/cases.py's stack.push/stack.pop properly on master: there are 11 case stacks with "ib": "T" and 8 with "weno_Re_flux": "T", and none of them overlap. Master's suite never runs the two together.

    So the accurate statement of scope is:

    • The code is on master. gp_layers = 3 (src/common/m_constants.fpp:49) and the viscous halo requirement 2*weno_polyn + 2 (src/common/m_helper_basic.fpp:130) are both master's; nothing in my branch touches either.
    • The defect is latent upstream. Because no master test enables both flags, upstream CI does not exercise this path, which is presumably why it has not surfaced as cross-lane golden disagreement.
    • It is reachable by any case that sets both, which is how we hit it.
    • I have not reproduced it on master itself — the measurements above are on a downstream branch whose IB ghost values differ from master, although gp_layers and the viscous stencil are unmodified. Reproducing on master would need a new case combining the two flags.

    The measured result stands on its own terms: on one tree, with only gp_layers changed from 3 to 6, two compilers go from differing by 5.2e-02 to agreeing bit-for-bit. I would still expect the same on master given the shared arithmetic, but that is an expectation, not a measurement.

    Correction prepared with Claude Code.

  2. sbryngelson commented on Oct 12, 2026

    @sbryngelson
    MemberAuthor

    Second correction: the mechanism in this issue is not demonstrated, and I would treat the report as unconfirmed.

    I ran the reproduction on master itself (62f658a) that the first correction said was missing: master's own examples/2D_ibm (viscous = T, weno_Re_flux = T, ib = T, weno_order = 5, circle IB), 30 steps, serial, built four ways — {Cray CCE 20, AMD amdflang AFAR 24.3.0} x {gp_layers 3, 6}. All four produced output; 15 files and ~7.2M values compared per pair.

    gp_layers Cray vs amdflang on master
    3 largest absolute difference 2.3e-08 on a field whose peak magnitude is 6.0e-03
    6 the same, at the same index

    So on master, with that case: the two compilers agree to ordinary floating-point noise, and changing gp_layers from 3 to 6 makes no difference at all. The largest relative numbers in that comparison (up to 1e-1) are between values like -9e-14 and -1e-13, which is output precision on an effectively zero quantity, not a disagreement.

    What that means for this issue. The measurement in the original report is real, but it is on a downstream case that also has chemistry, an 1800 K isothermal wall, and a rectangle with corners. Two readings now fit it equally well:

    1. the viscous stencil reads solid cells past the filled layers (what I claimed), or
    2. gp_layers = 6 changes the near-corner solution enough that it is no longer in a regime where small floating-point differences amplify.

    Nothing I have distinguishes them, and the plain viscous case above argues against the first being sufficient on its own. The arithmetic mismatch I pointed at (gp_layers = 3 versus 2*weno_polyn + 2 for the viscous halo) is still a real property of the code and may be worth a look on its own terms, but I should not have presented it as the established cause.

    Unless a maintainer sees value in keeping it open as a question about that arithmetic, this can be closed; I will reopen with a proper reproducer if I can isolate which ingredient (chemistry, the hot wall, or the corners) is required.

    Apologies for the churn on this one.

    Correction prepared with Claude Code.

  3. sbryngelson commented on Oct 14, 2026

    @sbryngelson
    MemberAuthor

    Third and final correction: I believe this issue should be closed as not a defect. The mechanism I described does not exist.

    Two earlier comments walked back the evidence. Reading the code properly now explains why the symptom test came back negative, and identifies three separate errors in the original report.

    1. There is no uninitialised memory, so there is no mechanism for compiler-dependence. src/simulation/m_rhs.fpp zeroes the RHS for every cell inside a body:

    if (ib) then
        do l = 0, p; do k = 0, n; do j = 0, m
            if (ib_markers%sf(j, k, l) /= 0) then
                do i = 1, sys_size
                    rhs_vf(i)%sf(j, k, l) = 0._wp

    So solid cells are never evolved: they hold exactly the state pre_process wrote, for the whole run. The claim that cells past gp_layers "hold whatever was last in memory, so the result is compiler-dependent" is wrong — they hold a definite, initialised, frozen value. That is why the four-way build comparison on master's own examples/2D_ibm found Cray and amdflang agreeing to 2.3e-08 with gp_layers at both 3 and 6: there was never any compiler-dependence to find.

    2. The arithmetic compares the wrong two numbers. The report sets gp_layers = 3 against the viscous halo requirement 2*weno_polyn + 2 = 6. The halo width is not the stencil reach that matters here. What matters is how deep a stencil reaches from a face adjacent to fluid, since those are the only faces whose fluxes enter a fluid cell's RHS. For fluid cell j with a ghost at j-1:

    • the viscous gradient at j-1 (s_apply_scalar_divergence_theorem) is a 3-cell stencil reaching j-2, i.e. distance 2 into the solid;
    • the WENO reconstruction for the j-1/2 face reaches j-3, i.e. distance 3.

    s_find_ghost_points flags a solid cell as a ghost when any cell within ±gp_layers is fluid, so the filled shell is 3 cells deep in box distance. Distance 2 and 3 are both inside it. Frozen cells at distance >= 4 are never read by any flux that reaches fluid, at weno_order = 5.

    3. The runtime test is negative. On the downstream case that motivated the report, running with weno_Re_flux = F — which removes the viscous WENO reconstruction entirely, the only path this issue is about — the failure still occurs, one step earlier. Only disabling viscosity altogether avoids it. So the viscous WENO path is not the mechanism.

    What the original measurement actually was. On a downstream branch, changing only gp_layers 3 -> 6 took two compilers from differing by 5.2e-02 to agreeing bit-for-bit. Given the above, the second reading offered in my earlier correction is the right one: gp_layers = 6 changed the near-corner solution enough to leave a regime where small floating-point differences amplified. That is a statement about a sensitive case, not about reading unwritten memory.

    The one real observation worth keeping. Solid cells at distance >= 4 do hold the initial condition for the entire run, so any future change that widens a near-wall stencil — a higher weno_order, a wider viscous stencil, or a scheme that reconstructs across more cells — would read a stale state that diverges from the neighbouring fluid as the solution evolves. That would be deterministic, not compiler-dependent, and it would be a reason to tie gp_layers to the stencil reach rather than fixing it at 3. It is not a bug today.

    Apologies for the noise on this one. The original report was filed from stencil arithmetic without checking either the RHS masking or the actual reach from fluid-adjacent faces.

    Written with Claude Code.

  4. sbryngelson commented on Oct 15, 2026

    @sbryngelson
    MemberAuthor

    Correction to my previous comment: I miscounted the stencil reach, and I withdraw the suggestion to close this issue.

    I said the reach from a fluid-adjacent face is 3 cells and compared gp_layers against the wrong number. With weno_Re_flux = T the reach is longer, because two WENO reconstructions are nested:

    1. s_get_viscous builds the cell-centred velocity gradients from WENO face values of the primitives plus the divergence theorem, so the gradient at cell c depends on primitives in c-3 .. c+3.
    2. Those gradient fields are WENO-reconstructed again to the faces (s_reconstruct_cell_boundary_values_visc_deriv, src/simulation/m_rhs.fpp:1016-1025). The face between fluid cell f and solid cell f-1 therefore reads gradients at f-3 .. f+2.

    So that face reads primitives out to f-6, i.e. 6 cells into the solid. That is 2*weno_polyn + 2, the halo size the viscous branch allocates in src/common/m_helper_basic.fpp, and it is the arithmetic in the original report. Against gp_layers = 3, cells 4-6 deep are read. I have not traced the weno_Re_flux = F path to the same standard, so I make no claim about its reach.

    What stays corrected. Those cells are not uninitialised memory: the RHS is zeroed inside bodies (m_rhs.fpp:840), so they hold the pre_process state for the whole run. The effect is deterministic. I still have no evidence of compiler dependence (on master's examples/2D_ibm, Cray against amdflang agree to 2.3e-8 at both gp_layers = 3 and 6), so "compiler-dependent" in the title is unsupported, but the stale-cell read itself looks real.

    Evidence for the effect. Our no-slip channel study (IB Poiseuille channel, downstream branch with the mirror ghost fill, not master) with weno_Re_flux = T: an odd-even oscillation of about +/-5% of u_max in the first 6 cells at 32 cells/gap (+/-0.5% at 64), which drops about 5x with gp_layers = 6. The same case with weno_Re_flux = F has a flat error of 2.4-2.9e-4 and no such oscillation (L2/u_max 3.2e-2 with T against 2.9e-4 with F at 32 cells/gap).

    Not yet done. I have not reproduced this on master itself, and I have not isolated it by changing only gp_layers; the gp_layers = 6 run above is on the downstream branch. A clean test is the channel on master with gp_layers 3 versus 6.

    Written with Claude Code.

  5. sbryngelson commented on Nov 25, 2026

    @sbryngelson
    MemberAuthor

    Ran the clean test the last comment asked for on current master (bb9cfe5e1): the same tree built twice, differing only in gp_layers (3, the master value, vs 6, src/common/m_constants.fpp:60). The viscous flux with weno_Re_flux = T does read solid cells 4-6 deep, but the result only changes when the ghost velocity is not the wall velocity. The default wall hides it; the opt-in higher-order walls expose it.

    Case: 2D, 64x64, fixed no-slip circle at a generic position (centre (0.4137, 0.5213), R = 0.1531), u = 0.1, Re = 100, WENO5, HLLC, 50 RK3 steps, wingtip GNU 13.3 CPU, 1 rank. Columns: largest difference between gp_layers = 3 and 6, over fluid cells only (the solid cells differ in every run, by 0.06-0.23, as expected).

    wall / viscous options max |diff| fluid, rho rho*u (relative) fluid cells differing
    default wall, weno_Re_flux = T 0 0 0
    default wall, weno_Re_flux = F 0 0 0
    ib_second_order_vel = T, weno_Re_flux = T 1.6e-4 2.6e-4 (2.4e-3) 3714 (of about 3790 fluid cells)
    ib_second_order_vel = T, weno_Re_flux = F 0 0 0
    ib_wall_order = 2, weno_Re_flux = T 3.4e-5 1.6e-5 (1.5e-4) 3667
    ib_second_order_vel = T, weno_Re_flux = T, ib_visc_compact = T 0 0 0

    Reading:

    • With weno_Re_flux = F the fluid is bit-identical: its reach stays within 3 layers.
    • With weno_Re_flux = T the nested reconstruction reaches past 3 layers, as the 2026-10-15 comment worked out. With the default wall every solid velocity equals the body velocity (the ghosts are set to vel_w and the deeper cells are reset to it), so what it reads there is the same at depth 4-6 and nothing changes. Once the ghost velocity is extrapolated (ib_second_order_vel, ib_wall_order = 2), the depth-1-3 ghosts differ from the frozen cells below them, and the fluid depends on how many layers are filled.
    • ib_visc_compact = T (IBM: opt-in compact viscous velocity gradients next to immersed bodies (ib_visc_compact) #2212) removes the dependence completely.
    • It is deterministic (same compiler, same tree), so "compiler-dependent" in the title does not hold, as the earlier corrections said.

    This matters more now that #2486 proposes ib_wall_order = 2 (and TSC) as the default.

    Size: small to medium. Fix sketch (either):

    1. With ib = T and weno_Re_flux = T, always use the compact gradient next to bodies: default ib_visc_compact to T in that combination, or have the validator require it with ib_second_order_vel / ib_wall_order = 2. Small, and only the goldens of those combinations move.
    2. Size the filled shell from the stencil, gp_layers = 2*weno_polyn + 2 when weno_Re_flux, making gp_layers a runtime value. Medium: more ghost points, and every IB golden with weno_Re_flux and a non-default wall moves.

    AI-assisted (Claude Code).

  6. sbryngelson commented on Nov 26, 2026

    @sbryngelson
    MemberAuthor

    Status after #2486 (which now says "Refs #2041" rather than closing this issue).

    What #2486 does. It turns on the compact viscous gradient next to bodies by default (ib_visc_compact = T wherever it applies: a body, viscous, weno_Re_flux, Cartesian coordinates). In the case from the comment above, run with the new IB defaults (ib_wall_order = 2, TSC):

    • gp_layers 3 and 6 then give bit-identical fluid cells.
    • With ib_visc_compact = F they differ by up to 4.4e-5 absolute (3.5e-4 relative) in about 1450 fluid cells.

    What remains open (documented next to ib_visc_compact in case.md):

    1. ib_visc_compact = F, the opt-out that restores the WENO viscous gradient, still reads solid cells past the filled layers. #2486 adds weno_Re_flux -> ib_visc_compact=F tests (2D/3D, 1 and 2 fluids), so that path keeps goldens. Its dependence on the fill depth is unchanged.
    2. Cylindrical coordinates. ib_visc_compact does not apply there (the validator refuses it), so an axisymmetric viscous weno_Re_flux IB case keeps the dependence. Nothing prohibits IB with cyl_coord, and no test exercises it.

    The remaining fix is option 2 of the earlier comment: size the filled shell from the stencil, gp_layers = 2*weno_polyn + 2 when weno_Re_flux, as a runtime value. Alternatively, extend the compact gradient to cylindrical coordinates.

    AI-assisted (Claude Code).

  7. sbryngelson commented on Nov 27, 2026

    @sbryngelson
    MemberAuthor

    Reopening: #2486 (merged as fa91d50) fixes the default case — the compact IB viscous gradient is now on by default wherever IB, viscous and weno_Re_flux are on in Cartesian coordinates, and gp_layers 3 vs 6 is bit-identical there. It was meant as "Refs #2041"; a commit message closed this issue. What remains, as noted in case.md: the ib_visc_compact = F opt-out and cylindrical-coordinate IB runs with weno_Re_flux still read solid cells past gp_layers (up to 3.5e-4 relative between gp_layers 3 and 6).

    AI-assisted (Claude Code).

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