AMReX-Astro / AMReX-Astro/Castro

MHD utility transforms do not consistently carry `QFX/UFX` auxiliary fields

Open
#3,249 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

ai-code-audit bug :bug: mhd
Dominant language
C++
Stars
340
Forks
105
Avg merge
3d 8h
Merged PRs (30d)
8

Description

Summary

The MHD primitive/conserved conversion helpers only treat species (QFS/UFS) and omit auxiliary composition fields (QFX/UFX). In ConsToPrim, QFX is read for EOS input without being initialized from UFX. In PrimToCons/PToC, UFX is never written from primitive data. In qflux, QFX updates are not computed.

Location

  • Source/mhd/mhd_util.H:124
  • Source/mhd/mhd_util.H:136
  • Source/mhd/mhd_util.H:40
  • Source/mhd/mhd_util.H:173
  • Source/mhd/mhd_util.cpp:101

Problem Details

Current patterns:

  • ConsToPrim sets QFS from UFS, then reads q_zone[QFX+n] into eos_state.aux[n] without initializing QFX.
  • PrimToCons and PToC write UFS but do not write UFX.
  • qflux computes primitive flux updates for QFS but not QFX.

When NAUX_NET > 0, this can feed undefined aux data into EOS and leave auxiliary transport state inconsistent.

Impact

  • Undefined aux inputs to EOS in MHD update path.
  • Missing or corrupted auxiliary advection updates.
  • Potential non-deterministic behavior in runs/networks that use auxiliary variables.

Suggested Patch

diff --git a/Source/mhd/mhd_util.H b/Source/mhd/mhd_util.H
--- a/Source/mhd/mhd_util.H
+++ b/Source/mhd/mhd_util.H
@@
   for (int n = 0; n < NumSpec; n++) {
     qflx[QFS+n] = (flx[UFS+n] - flx[URHO] * q_zone[QFS+n]) / q_zone[QRHO];
   }
+#if NAUX_NET > 0
+  for (int n = 0; n < NumAux; n++) {
+    qflx[QFX+n] = (flx[UFX+n] - flx[URHO] * q_zone[QFX+n]) / q_zone[QRHO];
+  }
+#endif
@@
   for (int n = 0; n < NumSpec; n++) {
     q_zone[QFS+n] = U_zone[UFS+n] / U_zone[URHO];
   }
+#if NAUX_NET > 0
+  for (int n = 0; n < NumAux; n++) {
+    q_zone[QFX+n] = U_zone[UFX+n] / U_zone[URHO];
+  }
+#endif
@@
   for (int n = 0; n < NumSpec; n++) {
     U(UFS+n) = U(URHO) * q(QFS+n);
   }
+#if NAUX_NET > 0
+  for (int n = 0; n < NumAux; n++) {
+    U(UFX+n) = U(URHO) * q(QFX+n);
+  }
+#endif

diff --git a/Source/mhd/mhd_util.cpp b/Source/mhd/mhd_util.cpp
--- a/Source/mhd/mhd_util.cpp
+++ b/Source/mhd/mhd_util.cpp
@@
     for (int n = 0; n < NumSpec; n++) {
       u_arr(i,j,k,UFS+n) = q_arr(i,j,k,QRHO) * q_arr(i,j,k,QFS+n);
     }
+#if NAUX_NET > 0
+    for (int n = 0; n < NumAux; n++) {
+      u_arr(i,j,k,UFX+n) = q_arr(i,j,k,QRHO) * q_arr(i,j,k,QFX+n);
+    }
+#endif

Prepared by Codex

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Source/mhd/mhd_util.H at lines 40, 124, 136, and 173, then inspect Source/mhd/mhd_util.cpp:101. Trace the existing QFS/UFS conversion and flux handling, compare the proposed QFX/UFX paths under NAUX_NET > 0, and validate that auxiliary values are initialized, converted, and updated consistently without affecting builds where no auxiliary fields exist.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
hpc
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.