Skip to content

hydro_transdd/transdo divide passives by pre-reset rrnew, corrupting species at rrnew<0 #83

Closed

Description

@WeiqunZhang

Severity: medium · Category: physics-numerics · Fix order: 13 of 25 — fix this 13th.

Filenames are numbered in reverse fix order: 001 = fix last, 025 = fix first. This file is 013.

Location: Source/Hydro/Godunov/Godunov_utils_3D.H:345

Based on commit 8f87fa8 (line numbers refer to that tree).

The defect

What is wrong — The passive/species updates in hydro_transdd (and hydro_transdo line 94) divide by rrnewr/rrnewl computed before the transverse_reset_density check, so when the reset triggers (rrnew < 0) the hydro state is restored but passives are divided by a negative or near-zero density.

Why it matters

3D Godunov (any build), transverse_reset_density=1 (default), near-vacuum cell where the transverse mass-flux difference exceeds rho (rrnewr<0): density/momentum/energy are reset but species mass fractions become huge or negative (compo/rrnewr with rrnewr<0), then feed species fluxes in hydro_cmpflx, corrupting species fields while total density stays sane.

Suggested fix

CAMR's transverse kernels descend from Castro's actual_trans_single/actual_trans_final (Castro/Source/hydro/trans.cpp), where the reset_density && rrnewn < 0 branch also restores every passive — qo_arr(i,j,k,nqp) = q_arr(i,j,k,nqp) — so the hydro state and the passives always come from the same state. Restore that coupling: hoist rrnewr/rrnewl and the reset predicate above the passive loop (in hydro_transdo they are currently recomputed inside it) and, on reset, write qnormp(iv,nqp) + hdt*srcpass, keeping CAMR's source term and dropping only the transverse term. The predicate must stay literally identical to the one in the hydro branch so the two can never disagree. The covered-face branches already pass qnorm through and need no change. Fix the 2D twin hydro_transd (Source/Hydro/Godunov/Godunov_utils_2D.H, passive loop at lines 96-121) in the same commit. Maintainer calls: whether to also guard small positive rrnew, and whether to port Castro's companion transverse_reset_rhoe and invalid-mass-fraction resets.

--- a/Source/Hydro/Godunov/Godunov_utils_3D.H
+++ b/Source/Hydro/Godunov/Godunov_utils_3D.H
@@ -78,25 +78,32 @@
   const amrex::Real flxe   = no_cov_face ? cdtdx * (flxx(ivpt, UEDEN) - flxx(iv, UEDEN)) : amrex::Real(0.0);
   const amrex::Real      c = qa(iv, QGAMC);
 
+  // If the transverse update would make the density negative we reset the
+  // state below, so the passive variables must be reset consistently
+  const bool reset_state_r = (transverse_reset_density == 1 &&
+                              qnormp(iv  , QRHO) - flxrho < amrex::Real(0.0));
+  const bool reset_state_l = (transverse_reset_density == 1 &&
+                              qnormm(ivpn, QRHO) - flxrho < amrex::Real(0.0));
+
   // Update passive variables
   for (int ipass = 0; ipass < NPASSIVE; ++ipass) {
       const int n = pmap.upassMap[ipass];
       const int nqp = pmap.qpassMap[ipass];
       const amrex::Real compn = no_cov_face ? cdtdx * (flxx(ivpt, n) - flxx(iv, n)) : amrex::Real(0.0);
 
       amrex::Real rr, rrnew, compo;
 
-      if (lo_face_not_covered)
+      if (lo_face_not_covered && !reset_state_r)
       {
           rr = qnormp(iv, QRHO);
           rrnew = rr - flxrho;
           compo = rr * qnormp(iv, nqp) - compn;
           qp(iv, nqp) = compo / rrnew;
       } else {
           qp(iv, nqp) = qnormp(iv, nqp);
       }
 
-      if (hi_face_not_covered)
+      if (hi_face_not_covered && !reset_state_l)
       {
           rr = qnormm(ivpn, QRHO);
           rrnew = rr - flxrho;
@@ -143,15 +150,14 @@
       amrex::Real rwnewr = rwr - flxw;
       amrex::Real renewr = rer - flxe;
 
-      bool reset_state = false;
+      const bool reset_state = reset_state_r;
 
-      if (transverse_reset_density == 1 && rrnewr < 0.) {
+      if (reset_state) {
          rrnewr = rrr;
          runewr = rur;
          rvnewr = rvr;
          rwnewr = rwr;
          renewr = rer;
-         reset_state = true;
       }
 
       // Convert back to primitive
@@ -201,14 +207,13 @@
       amrex::Real rwnewl = rwl - flxw;
       amrex::Real renewl = rel - flxe;
 
-      bool reset_state = false;
-      if (transverse_reset_density == 1 && rrnewl < 0.) {
+      const bool reset_state = reset_state_l;
+      if (reset_state) {
          rrnewl = rrl;
          runewl = rul;
          rvnewl = rvl;
          rwnewl = rwl;
          renewl = rel;
-         reset_state = true;
       }
 
       qm(ivpn, QRHO) = rrnewl;
@@ -328,31 +333,44 @@
   amrex::Real rrnewl = rrl - flxrho;
   amrex::Real rrnewr = rrr - flxrho;
 
+  // If the transverse update would make the density negative we reset the
+  // state below, so the passive variables must be reset consistently
+  const bool reset_state_r = (transverse_reset_density == 1 && rrnewr < 0.);
+  const bool reset_state_l = (transverse_reset_density == 1 && rrnewl < 0.);
+
   for (int ipass = 0; ipass < NPASSIVE; ++ipass) {
     const int n = pmap.upassMap[ipass];
     const int nqp = pmap.qpassMap[ipass];
     const amrex::Real srcpass = srcq(iv, nqp);
     const amrex::Real compn = no_cov_face ?
       cdtdx0 * (flxx(ivpt0, n) - flxx(iv, n)) +
       cdtdx1 * (flxy(ivpt1, n) - flxy(iv, n)) : amrex::Real(0.0);
 
     amrex::Real compo;
 
     // qp
     if (lo_face_not_covered)
     {
-      compo = rrr * qnormp(iv, nqp) - compn;
-      qp(iv, nqp) = compo / rrnewr + hdt * srcpass;
+      if (reset_state_r) {
+        qp(iv, nqp) = qnormp(iv, nqp) + hdt * srcpass;
+      } else {
+        compo = rrr * qnormp(iv, nqp) - compn;
+        qp(iv, nqp) = compo / rrnewr + hdt * srcpass;
+      }
     } else {
       qp(iv, nqp) = qnormp(iv, nqp);
     }
 
     // qm
 
     if (hi_face_not_covered)
     {
-      compo = rrl * qnormm(ivpn, nqp) - compn;
-      qm(ivpn, nqp) = compo / rrnewl + hdt * srcpass;
+      if (reset_state_l) {
+        qm(ivpn, nqp) = qnormm(ivpn, nqp) + hdt * srcpass;
+      } else {
+        compo = rrl * qnormm(ivpn, nqp) - compn;
+        qm(ivpn, nqp) = compo / rrnewl + hdt * srcpass;
+      }
     } else {
       qm(ivpn, nqp) = qnormm(ivpn, nqp);
     }
@@ -397,15 +415,14 @@
     amrex::Real rwnewr = rwr - flxw;
     amrex::Real renewr = rer - flxe;
 
-    bool reset_state = false;
+    const bool reset_state = reset_state_r;
 
-    if (transverse_reset_density == 1 && rrnewr < 0.) {
+    if (reset_state) {
       rrnewr = rrr;
       runewr = rur;
       rvnewr = rvr;
       rwnewr = rwr;
       renewr = rer;
-      reset_state = true;
     }
 
     qp(iv, QRHO) = rrnewr + hdt * srcrho;
@@ -445,14 +462,13 @@
     amrex::Real rwnewl = rwl - flxw;
     amrex::Real renewl = rel - flxe;
 
-    bool reset_state = false;
-    if (transverse_reset_density == 1 && rrnewl < 0.) {
+    const bool reset_state = reset_state_l;
+    if (reset_state) {
       rrnewl = rrl;
       runewl = rul;
       rvnewl = rvl;
       rwnewl = rwl;
       renewl = rel;
-      reset_state = true;
     }
 
     qm(ivpn, QRHO) = rrnewl + hdt * srcrho;

Hoists the transverse-reset test above the passive loops in both hydro_transdo and hydro_transdd (one flag per side) and reuses it in the hydro blocks, so passives skip the transverse term exactly when the state is reset (keeping hdt*srcpass in transdd). Pure C++/index logic, no AMReX API. INCOMPLETE BY DESIGN: the identical defect remains in Godunov_utils_2D.H hydro_transd (passive loop at lines 96-120 divides by an rrnew computed before the reset test at lines 146/200); this sketch does not touch the 2D twin, so fixing the finding fully takes both edits.

Diff(s) are against 8f87fa8, written from the current source and verified only with git apply --check — never compiled, never run, never applied to the tree. Treat them as precise intent, not tested patches.

Verification evidence

F030 — confirmed (one verifier lens)

Lens 1 (refutation attempt): hydro_transdd computes 'rrnewr = rrr - flxrho' (line 329) and divides passives 'qp(iv,nqp) = compo/rrnewr' (line 345) BEFORE the reset 'if (transverse_reset_density==1 && rrnewr<0.) rrnewr=rrr' (line 402); same for rrnewl at 355 vs 449. hydro_transdo lines 92-104 divide by rrnew with no reset ever. Default transverse_reset_density=1 (CAMR_defaults.H:29). riemannus then uses 'flx(n)=flxrho*q(nqp)' unclamped (Hydro_riemann.H:139); normalize_species only clamps state later, not the corrupted fluxes.


Based on commit 8f87fa8, which is also the tree the audit verified against. From an automated audit of Source/, Tutorials/ and Util/. Audit finding id: F030. Reviewer unit(s): Godunov-3D. Nothing here was compiled or run — the failure scenarios are code reasoning, so the reaching configuration above is the cheapest way to confirm or refute it.

Activity

  1. added a commit that references this issue on Aug 23, 2026
    6b3a6cd
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