Skip to content

PLIC: advection_type "PLIC" in HydroUtils - #255

Merged
WeiqunZhang merged 7 commits into
AMReX-Fluids:developmentfrom
ThomasHowarth:plic-4-hydroutils
Dec 2, 2026
Merged

WeiqunZhang merged 7 commits into
AMReX-Fluids:developmentfrom
ThomasHowarth:plic-4-hydroutils

Conversation

@ThomasHowarth

@ThomasHowarth ThomasHowarth commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

HydroUtils::ComputeFluxesOnBoxFromState advects a volume fraction with advection_type = "PLIC": PLIC::ComputeEdgeStateAndFluxes gives the edge states and the geometric fluxes, with the myc_height reconstruction. Where a corrective u_flux differs from u_mac (bit for bit), the new PLIC::CorrectiveFluxes overwrites the flux with edge state × u_flux. Where u_mac is zero or of the other sign, it uses the upwind F of u_flux instead, so the flux never draws on the downwind cell. knownFaceState works with iconserv = 1 (edge states) or -1 (fluxes). The boundary conditions are carried by the ghost cells of F, filled with PLIC::FillWallGhosts. "PLIC" aborts with EB (whole level, covered boxes included), for velocities and for more than one component, and ExtrapVelToFaces does not accept it. Optimized GPU builds skip the per-box Courant and iconserv checks, so callers check each level with PLIC::CheckCourantNumber before the MFIter loop.

Tests/PLIC advects through HydroUtils with test.use_hydroutils = 1 in inputs.2d.vortex, inputs.2d.wall_vortex and inputs.3d.deform (AMR, periodic and wall boundaries, 3D). It compares with PLIC to the bit, including corrective u_flux cases with and without area weighting, and the volume is conserved to round-off.

🤖 Generated with Claude Code

@ThomasHowarth
ThomasHowarth force-pushed the plic-4-hydroutils branch 10 times, most recently from d05ddda to bf07083 Compare November 20, 2026 12:23
@ThomasHowarth
ThomasHowarth marked this pull request as ready for review November 24, 2026 17:59
@WeiqunZhang

Copy link
Copy Markdown
Member

Important

Corrective u_flux can be multiplied by a downwind edge state — Utils/hydro_compute_edgestate_and_flux.cpp:213

  • CorrectiveFluxes uses PLIC's edge state, which is upwinded by u_mac alone. Where u_mac == 0 it always takes the lower cell's F, whatever the sign of u_flux.
  • Failure case: fluid at rest on a face, lower cell full (F=1), upper cell empty (F=0), sync correction u_flux < 0. The flux 1 * u_flux removes liquid from the empty cell, so F goes below 0 there and above 1 in the lower cell.
  • Fix: where u_mac == 0 or has the opposite sign to u_flux, pick the upwind F by the sign of u_flux, or document the limitation.

Nits

  1. Reconstruction is hard-wired to "myc_height" (hydro_compute_edgestate_and_flux.cpp:525). A solver that uses "youngs" or "myc" for FillWallGhosts and SharpFaceDensity either aborts on the nGrowF("myc_height") ghost-cell
    assertion or silently advects with a different normal. Let the caller choose, or document that every PLIC call must use myc_height.
  2. Two blocking waits per box on GPUs (:516). One is the Gpu::dtoh_memcpy of iconserv, the other the Courant reduction, because check_courant is left at its default. A HydroUtils caller can't turn either off, so the MFIter loop
    loses asynchronous launching across boxes.
  3. Area-weighted branch of CorrectiveFluxes is untested (Tests/PLIC/test_advect.cpp:472). CompareWithPLIC passes a corrective u_flux only with area_weighted = false, so a wrong area factor would pass.
  4. Thin coverage of the HydroUtils path (Tests/PLIC/inputs.2d.wall_vortex:24). It runs in only one single-level 2D wall input, so the "right after a regrid" comparison never happens, and coarse/fine ghost cells, periodic
    boundaries and 3D are not covered. The EB-signature overload isn't built by the test at all. Setting test.use_hydroutils = 1 in inputs.2d.vortex and inputs.3d.deform would cover most of this.
  5. PR description doesn't match the code (:529). It says HydroUtils::ComputeFluxes forms fluxes from PLIC's edge states and that PLIC::ComputeEdgeStateAndFluxes now accepts empty flux arrays. The diff keeps PLIC's geometric
    fluxes, overwrites only the faces where u_flux differs, and doesn't touch PLIC/.
  6. EB rejection for "PLIC" is not uniform (:503). The check sits after the early return for fully covered boxes, so those return silently with flux and face arrays unwritten. It also tests ebfact.isAllRegular(), which rejects any
    EB geometry, while the comment says only levels with cut cells are rejected.

Thomas Howarth and others added 6 commits December 1, 2026 11:07
HydroUtils::ComputeFluxesOnBoxFromState advects a volume fraction with
advection_type = "PLIC", as any other scalar: the edge states come from
PLIC::ComputeEdgeStateAndFluxes with the myc_height reconstruction, and
HydroUtils::ComputeFluxes forms the fluxes from them, so u_flux,
knownFaceState, area weighting and ComputeConvectiveTerm work unchanged.
The boundary conditions are carried by the ghost cells of F, filled with
PLIC::FillWallGhosts. "PLIC" aborts with embedded boundaries, for velocities
and for more than one component, and ExtrapVelToFaces does not accept it.

PLIC::ComputeEdgeStateAndFluxes accepts empty flux arrays, for the edge
states only.

Tests/PLIC advects through HydroUtils with test.use_hydroutils = 1, with the
same shape errors as the direct path and the volume conserved to round-off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TwkdHV9vdS67quGfmN9xjG
- HydroUtils writes the geometric fluxes of PLIC::ComputeEdgeStateAndFluxes
  when they are formed with u_mac, rather than edge state * u: where shear
  folds a flux volume the edge state is held to [0,1] and that product is not
  the liquid that crosses the face. Through HydroUtils the fluxes and edge
  states are now those of PLIC to the bit (inputs.3d.deform differed at 1e-8).
  With a corrective u_flux, or knownFaceState, the fluxes are still formed
  from the edge states.
- The PLIC branch is built only with HYDRO_USE_PLIC, which PLIC/Make.package
  and PLIC/CMakeLists.txt define, so GNUmake codes that do not list PLIC still
  build; "PLIC" then aborts.
- Check iconserv = 1 and that bc_arr is not passed.
- One short PLIC note in the ComputeFluxesOnBoxFromState docs, pointing to
  the PLIC section, rather than five copies.
- Tests/PLIC with test.use_hydroutils = 1 checks the HydroUtils fluxes and
  edge states against PLIC::ComputeEdgeStateAndFluxes, to the bit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The PLIC branch inline in ComputeFluxesOnBoxFromState, without a helper of
  21 parameters and a return value with two meanings.
- The device check of iconserv = 1 only with AMREX_DEBUG, rather than a
  kernel launch per box in every build.
- HYDRO_USE_PLIC a PRIVATE definition in CMake: only the library reads it.
- The flux kernel tests the flux Array4 itself rather than a copy of it.
- PLIC.rst says the geometric fluxes need u_flux to be the same Array4 as
  u_mac (or the overloads without u_flux).
- Tests/PLIC: iconserv as a Gpu::DeviceScalar, a synchronous copy of the
  BCRecs, and the two flux paths as if/else.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Check iconserv on the host in every build: 1, or -1 with knownFaceState.
  The debug-only device check rejected -1 and accepted 0 in release.
- Keep PLIC's geometric fluxes whenever u_flux holds the values of u_mac
  (compared in one reduction when the arrays differ), not only when it is
  the same Array4.
- Pass the real flux arrays to PLIC::ComputeEdgeStateAndFluxes, and revert
  its empty-flux mode, so the public API again aborts on a missing flux.
- ComputeConvectiveTerm aborts on "PLIC" in builds without PLIC, as
  ComputeFluxesOnBoxFromState does.
- Docs: "PLIC" in the bc_arr notes; the HydroUtils section of PLIC.rst as
  a list of the flux cases, and a note on rebuilding after adding PLIC.
- Tests/PLIC: with test.use_hydroutils, also check a copy of u_mac,
  area-weighted fluxes, a corrective u_flux and knownFaceState with
  iconserv 1 and -1, all to the bit; share the flux calls between the step
  and the comparison.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Choose between PLIC's geometric flux (u_flux equal to u_mac) and edge
  state * u_flux face by face, not box by box: boxes sharing a face could
  write different fluxes on it when u_flux differs on part of a level. This
  also drops a reduction, and its wait for the GPU, per box.
- Abort in R-Z with knownFaceState too.
- Docs: the ghost cells "PLIC" needs, the arguments it does not read, its
  waits for the GPU per box, and the note on the finest level back under
  Advection.
- Tests/PLIC: a u_flux that differs on part of the level, arrays reset
  before each call, no device lambda inside a lambda, the comparison every
  test.hydroutils_int steps (default 10), and inputs.2d.wall_vortex through
  HydroUtils.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Corrective fluxes: where u_mac is zero or of the other sign to u_flux,
  take the upwind F of u_flux rather than PLIC's edge state (upwinded by
  u_mac), so the flux never draws on the downwind cell. Moved to a public
  PLIC::CorrectiveFluxes, reusing upwind_fraction and FaceArea.
- The iconserv check and the per-box Courant check run in CPU and debug
  builds only; optimized GPU builds rely on PLIC::CheckCourantNumber
  before the MFIter loop, so the boxes are not serialized.
- The EB check for "PLIC" comes before the covered-box early return.
- Docs: myc_height is fixed, so FillWallGhosts and SharpFaceDensity must
  use it too; u_flux is compared with u_mac bit for bit.
- Tests: corrective u_flux of the sign of u_mac, reversed, and non-zero
  where u_mac is zero, without and with area weighting; a NaN edge state
  no longer hides behind max(); inputs.2d.vortex and inputs.3d.deform
  also advect through HydroUtils (AMR, periodic, 3D).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ThomasHowarth

Copy link
Copy Markdown
Contributor Author

Thanks for the review. All addressed in 2ed9d8f (rebased on development):

Important: corrective u_flux times a downwind edge state. Fixed. Where u_mac is zero or of the other sign to u_flux, the flux now takes the upwind F of u_flux (held to [0,1]) instead of PLIC's edge state, so it never draws on the downwind cell. Your rest-state case now gives a zero flux. Where the signs agree it is still PLIC's edge state × u_flux, and where u_flux == u_mac bit for bit it is PLIC's geometric flux. The face arrays keep PLIC's edge states. This lives in a new public PLIC::CorrectiveFluxes, so solvers that call PLIC directly get the same fluxes. It differs on purpose from Godunov/MOL/BDS, which keep the u_mac-upwinded state, because F must stay in [0,1].

Nits

  1. myc_height hard-wired. Documented, in PLIC.rst and hydro_utils.H: a solver advecting F through HydroUtils must pass "myc_height" to FillWallGhosts and SharpFaceDensity too. To use another reconstruction, call PLIC::ComputeEdgeStateAndFluxes directly.
  2. Two blocking waits per box. Optimized GPU builds now skip both the iconserv copy and the per-box Courant check. GPU callers check each level once with PLIC::CheckCourantNumber before the MFIter loop, which is now in the docs. CPU and debug builds keep both checks, because there they cost no asynchrony.
  3. Area-weighted corrective branch untested. The corrective cases now run with and without area weighting.
  4. Thin coverage. test.use_hydroutils = 1 is now also set in inputs.2d.vortex and inputs.3d.deform, which covers AMR (comparing right after regrids too), coarse/fine ghost cells, periodic boundaries and 3D. The corrective u_flux now covers four cases across the domain: same sign as u_mac, u_flux == u_mac, reversed, and shifted (non-zero where u_mac is zero). Each case boundary falls inside a box. The EB overload still isn't built by this test, since Tests/PLIC is a non-EB build. I also fixed a hole in the comparison: a NaN edge state could hide behind max().
  5. PR description. Rewritten to match the code.
  6. EB rejection. The check now comes before the covered-box early return, so a level with any cut or covered cells is rejected on every box. The comment now says "cut or covered cells", matching isAllRegular().

@WeiqunZhang

Copy link
Copy Markdown
Member

The downwind-edge-state fix does not cover knownFaceState = true (Utils/hydro_compute_edgestate_and_flux.cpp:497). I confirmed this in the code.

  • That path skips PLIC::CorrectiveFluxes and falls through to HydroUtils::ComputeFluxes, so the flux is still the u_mac-upwinded edge state times u_flux.
  • Your original failure case therefore survives there: saved edge states reused in a sync with iconserv = 1, u_mac == 0 on a face, lower cell full, upper cell empty, u_flux < 0.
  • The test's knownFaceState case only uses u_mac, so it doesn't catch this.
  • Cheapest fixes: abort when u_flux differs from u_mac on this path, or state the limit in PLIC.rst and hydro_utils.H.

- knownFaceState: the fluxes get PLIC::CorrectiveFluxes too, so where a
  corrective u_flux is zero-crossing or reversed relative to u_mac, the
  flux takes the upwind F of u_flux rather than the given edge state
  (upwinded by u_mac), as without knownFaceState. With iconserv = -1 the
  given fluxes are kept.
- PLIC::CorrectiveFluxes takes an optional device pointer to iconserv and
  reads it in its kernel, so HydroUtils needs no wait for the GPU per box;
  HydroUtils now calls it once for both paths.
- PLIC::CorrectiveFluxes checks that the fluxes, edge states, u_mac and
  u_flux cover the faces of bx, and that F has one ghost cell: with
  knownFaceState the other schemes read neither F nor u_mac.
- Docs: the knownFaceState correction, and that it needs u_mac and F with
  one ghost cell.
- Tests: knownFaceState with the corrective u_flux, with iconserv = 1
  (corrected) and -1 (copied).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ThomasHowarth

Copy link
Copy Markdown
Contributor Author

Thanks, you're right: the knownFaceState path skipped the correction. Fixed in 5d71f97.

knownFaceState with a corrective u_flux. The fluxes on that path now go through PLIC::CorrectiveFluxes too. Where u_flux differs from u_mac and u_mac is zero or of the other sign, the flux takes the upwind F of u_flux (held to [0,1]) instead of the given edge state, the same as without knownFaceState. Your case (saved edge states, iconserv = 1, u_mac == 0, lower cell full, upper empty, u_flux < 0) now gives a zero flux. With iconserv = -1 the given fluxes are kept, and u_flux is ignored as with the other schemes.

  • No new GPU wait: CorrectiveFluxes takes an optional device pointer to iconserv and reads it in its kernel. HydroUtils now calls it once for both paths.
  • New requirement: unlike the other schemes, a corrective u_flux with knownFaceState needs u_mac (the one the edge states were computed with) and F with one ghost cell. CorrectiveFluxes now asserts on its arrays' bounds, and PLIC.rst says so.
  • Tests: the knownFaceState cases now run with the corrective u_flux as well as u_mac, for iconserv = 1 (corrected) and -1 (copied). With the fix removed, the comparison fails. All three HydroUtils inputs pass (2D vortex, 2D wall vortex, 3D deform with AMR).

@WeiqunZhang
WeiqunZhang merged commit c55a202 into AMReX-Fluids:development Dec 2, 2026
12 checks passed
ThomasHowarth added a commit to ThomasHowarth/AMReX-Hydro that referenced this pull request Dec 3, 2026
Following Rudman (IJNMF), the Owkes & Desjardins flux volumes also give
the mass and momentum fluxes of each face, from the cuts of the volume
fraction with phase densities given as PhaseDensityArray or fields.

- ComputeMassMomentumFluxes computes the volume, mass and momentum
  fluxes in one call, optionally with the face velocity; dt must be
  positive.
- FarFieldMomentumFluxes fills the faces the cuts marked, away from
  the interface. far_field_mark is a quiet NaN, so that a face left
  unfilled shows up in the momentum update.
- CorrectiveMassMomentumFluxes is the counterpart of CorrectiveFluxes:
  where a corrective u_flux differs from umac, the mass flux carries
  the corrected volume fraction flux at the phase densities of the
  upwind cell, so rho stays the mixture density of F. Both share
  corrective_fraction.
- The mass and momentum entry points take check_courant, as
  ComputeEdgeStateAndFluxes does, for solvers that check the level once
  with CheckCourantNumber.
- The cut kernels walk the pieces of a flux volume once, and skip the
  liquid lookup per piece in a flux volume of one phase. The liquid
  flux kernel captures no momentum arguments.
- SharpFaceDensity reads its phase densities as PhaseDensityArray.
- New test_momentum (inputs.momentum) with a Translate problem: checks
  the corrective fluxes, and that the momentum is conserved in every
  case, relative to one cell of liquid.

Ported as one commit onto development after plic-4 (AMReX-Fluids#255) merged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V7EH6ZtZUnusy66tyAq5MH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants