Skip to content

Commit

Permalink
Diagnostics: Warn w/o Positions
Browse files Browse the repository at this point in the history
If a user specifies `<diag_name>.<species_name>.variables`
without including particle position arguments we now warn.
  • Loading branch information
ax3l committed May 6, 2024
1 parent bc5d0a2 commit a100076
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
5 changes: 3 additions & 2 deletions Docs/source/usage/parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2689,10 +2689,11 @@ In-situ capabilities can be used by turning on Sensei or Ascent (provided they a

* ``<diag_name>.<species_name>.variables`` (list of `strings` separated by spaces, optional)
List of particle quantities to write to output.
Choices are ``w`` for the particle weight and ``ux`` ``uy`` ``uz`` for the particle momenta.
Choices are ``x``, ``y``, ``z`` for the particle positions (3D and RZ), ``x`` & ``z`` in 2D, ``z`` in 1D,
``w`` for the particle weight and ``ux``, ``uy``, ``uz`` for the particle momenta.
When using the lab-frame electrostatic solver, ``phi`` (electrostatic potential, on the macroparticles) is also available.
By default, all particle quantities (except ``phi``) are written.
If ``<diag_name>.<species_name>.variables = none``, no particle data are written, except for particle positions, which are always included.
If ``<diag_name>.<species_name>.variables = none``, no particle data are written.

* ``<diag_name>.<species_name>.random_fraction`` (`float`) optional
If provided ``<diag_name>.<species_name>.random_fraction = a``, only `a` fraction of the particle data of this species will be dumped randomly in diag ``<diag_name>``, i.e. if `rand() < a`, this particle will be dumped, where `rand()` denotes a random number generator.
Expand Down
17 changes: 15 additions & 2 deletions Source/Diagnostics/ParticleDiag/ParticleDiag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
#include "Utils/TextMsg.H"
#include "WarpX.H"

#include <ablastr/warn_manager/WarnManager.H>

#include <AMReX_ParmParse.H>

#include <map>
#include <vector>

using namespace amrex;

ParticleDiag::ParticleDiag(
ParticleDiag::ParticleDiag (
const std::string& diag_name, const std::string& name,
WarpXParticleContainer* pc, PinnedMemoryParticleContainer* pinned_pc):
m_diag_name(diag_name), m_name(name), m_pc(pc), m_pinned_pc(pinned_pc)
Expand All @@ -28,10 +30,11 @@ ParticleDiag::ParticleDiag(
amrex::Vector<std::string> variables;
const int variables_specified = pp_diag_name_species_name.queryarr("variables", variables);

if (variables_specified){
if (variables_specified) {
// If only specific variables have been specified, fill m_plot_flags with zero and only set
// requested variables to one
std::fill(m_plot_flags.begin(), m_plot_flags.end(), 0);
bool contains_positions = false;
if (variables[0] != "none"){
const std::map<std::string, int> existing_variable_names = pc->getParticleComps();
for (const auto& var : variables){
Expand All @@ -47,9 +50,19 @@ ParticleDiag::ParticleDiag(
"variables argument '" + var
+"' is not an existing attribute for this species");
m_plot_flags[existing_variable_names.at(var)] = 1;

if (var == "x" || var == "y" || var == "z")
contains_positions = true;
}
}
}

if (!contains_positions) {
ablastr::warn_manager::WMRecordWarning(
"Diagnostics",
diag_name + "." + name + ".variables contains no particle positions!",
ablastr::warn_manager::WarnPriority::high);
}
}

#ifdef WARPX_DIM_RZ
Expand Down

0 comments on commit a100076

Please sign in to comment.