Skip to content

CAMR::setPlotVariables silently deletes species the user listed in amr.plot_vars #114

Closed

Description

@WeiqunZhang

Severity: low · Category: io-restart
Locations: Source/Utils/CAMR_io.cpp:93-103
Based on commit 17997db (line numbers refer to that tree).

The defect

CAMR::setPlotVariables first lets AmrLevel::setPlotVariables() build the
state plot list -- either every state variable, or exactly the names given in
amr.plot_vars (amrex/Src/Amr/AMReX_AmrLevel.cpp:1904-1935) -- and then
unconditionally removes rho_F, rho_A, rho_P unless CAMR.plot_rhoy = 1:

bool plot_rhoy = false;
pp.query("plot_rhoy", plot_rhoy);
if (plot_rhoy) { ...addStatePlotVar... }
else           { for (i) amrex::Amr::deleteStatePlotVar(desc_lst[State_Type].name(UFS + i)); }

The intent (drop the bulky species from the default "everything" list) is
fine, but the else branch also runs when the user gave an explicit
amr.plot_vars = density xmom rho_F and never mentioned plot_rhoy. The
requested rho_F is then removed with no message, and writePlotFile (which
only consults isStatePlotVar) writes a plotfile without it. Nothing tells the
user that an extra, undocumented key (CAMR.plot_rhoy) is needed to make the
standard AMReX key work.

Why it matters

Silent no-op of a user-facing input: a plotfile is missing variables the inputs
file explicitly asked for. Post-processing scripts keyed on those names fail
downstream, and the cause is far from the symptom (the deletion happens once,
at the first plotfile, inside Amr::writePlotFile, AMReX_Amr.cpp:903).

How to reach it

Any Exec case, any DIM / USE_EB. Add
amr.plot_vars = density rho_F rho_A rho_P to e.g. Exec/Sod/inputs-x; the
resulting plt*/Header lists only density.

Suggested fix

Only strip the species when the user did not provide an explicit amr.plot_vars
list, or when they explicitly set plot_rhoy = 0. git apply --check passes on
17997db.

--- a/Source/Utils/CAMR_io.cpp
+++ b/Source/Utils/CAMR_io.cpp
@@ -90,13 +90,18 @@
 
   amrex::ParmParse pp("CAMR");
 
+  // Species are dropped from the default ("all state variables") plot list
+  // unless plot_rhoy is set.  If the user gave an explicit amr.plot_vars list
+  // and did not say anything about plot_rhoy, honor that list as written
+  // instead of silently removing the species from it.
   bool plot_rhoy = false;
-  pp.query("plot_rhoy", plot_rhoy);
+  const bool have_plot_rhoy = pp.query("plot_rhoy", plot_rhoy);
+  const bool have_plot_vars = amrex::ParmParse("amr").contains("plot_vars");
   if (plot_rhoy) {
     for (int i = 0; i < NUM_SPECIES; i++) {
       amrex::Amr::addStatePlotVar(desc_lst[State_Type].name(UFS + i));
     }
-  } else {
+  } else if (have_plot_rhoy || !have_plot_vars) {
     for (int i = 0; i < NUM_SPECIES; i++) {
       amrex::Amr::deleteStatePlotVar(desc_lst[State_Type].name(UFS + i));
     }

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