Skip to content

Commit

Permalink
Move ParmParseWithOptionalGroup to Utils and update method names
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgrote committed Oct 30, 2023
1 parent 2f763e4 commit 4049b1d
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 99 deletions.
1 change: 0 additions & 1 deletion Source/Initialization/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ foreach(D IN LISTS WarpX_DIMS)
WarpXAMReXInit.cpp
InjectorDensity.cpp
InjectorMomentum.cpp
ParmParseWithOptionalGroup.cpp
PlasmaInjector.cpp
WarpXInitData.cpp
TemperatureProperties.cpp
Expand Down
1 change: 0 additions & 1 deletion Source/Initialization/Make.package
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
CEXE_sources += WarpXAMReXInit.cpp
CEXE_sources += WarpXInitData.cpp
CEXE_sources += ParmParseWithOptionalGroup.cpp
CEXE_sources += PlasmaInjector.cpp
CEXE_sources += InjectorDensity.cpp
CEXE_sources += InjectorMomentum.cpp
Expand Down
2 changes: 1 addition & 1 deletion Source/Initialization/PlasmaInjector.H
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifndef PLASMA_INJECTOR_H_
#define PLASMA_INJECTOR_H_

#include "ParmParseWithOptionalGroup.H"
#include "Utils/ParmParseWithOptionalGroup.H"
#include "InjectorDensity.H"
#include "InjectorFlux.H"
#include "InjectorMomentum.H"
Expand Down
84 changes: 42 additions & 42 deletions Source/Initialization/PlasmaInjector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name,

ParmParseWithOptionalGroup pp_species_dot_source(species_name, source_name);

pp_species_dot_source.query("radially_weighted", radially_weighted);
pp_species_dot_source.queryWithParser("radially_weighted", radially_weighted);
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(radially_weighted, "ERROR: Only radially_weighted=true is supported");

// Unlimited boundaries
Expand Down Expand Up @@ -103,15 +103,15 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name,
}
# endif

pp_species_dot_source.query("xmin", xmin);
pp_species_dot_source.query("ymin", ymin);
pp_species_dot_source.query("zmin", zmin);
pp_species_dot_source.query("xmax", xmax);
pp_species_dot_source.query("ymax", ymax);
pp_species_dot_source.query("zmax", zmax);
pp_species_dot_source.queryWithParser("xmin", xmin);
pp_species_dot_source.queryWithParser("ymin", ymin);
pp_species_dot_source.queryWithParser("zmin", zmin);
pp_species_dot_source.queryWithParser("xmax", xmax);
pp_species_dot_source.queryWithParser("ymax", ymax);
pp_species_dot_source.queryWithParser("zmax", zmax);

pp_species_dot_source.query("density_min", density_min);
pp_species_dot_source.query("density_max", density_max);
pp_species_dot_source.queryWithParser("density_min", density_min);
pp_species_dot_source.queryWithParser("density_max", density_max);

// Parse injection style
// Must be supplied for each source
Expand Down Expand Up @@ -193,24 +193,24 @@ PlasmaInjector::~PlasmaInjector () = default;

void PlasmaInjector::setupSingleParticle (ParmParseWithOptionalGroup& pp_species_dot_source)
{
pp_species_dot_source.get("single_particle_pos", single_particle_pos, 0, 3);
pp_species_dot_source.get("single_particle_u", single_particle_u, 0, 3);
pp_species_dot_source.getArrWithParser("single_particle_pos", single_particle_pos, 0, 3);
pp_species_dot_source.getArrWithParser("single_particle_u", single_particle_u, 0, 3);
for (auto& x : single_particle_u) {
x *= PhysConst::c;
}
pp_species_dot_source.get("single_particle_weight", single_particle_weight);
pp_species_dot_source.getWithParser("single_particle_weight", single_particle_weight);
add_single_particle = true;
}

void PlasmaInjector::setupMultipleParticles (ParmParseWithOptionalGroup& pp_species_dot_source)
{
pp_species_dot_source.get("multiple_particles_pos_x", multiple_particles_pos_x);
pp_species_dot_source.get("multiple_particles_pos_y", multiple_particles_pos_y);
pp_species_dot_source.get("multiple_particles_pos_z", multiple_particles_pos_z);
pp_species_dot_source.get("multiple_particles_ux", multiple_particles_ux);
pp_species_dot_source.get("multiple_particles_uy", multiple_particles_uy);
pp_species_dot_source.get("multiple_particles_uz", multiple_particles_uz);
pp_species_dot_source.get("multiple_particles_weight", multiple_particles_weight);
pp_species_dot_source.getArrWithParser("multiple_particles_pos_x", multiple_particles_pos_x);
pp_species_dot_source.getArrWithParser("multiple_particles_pos_y", multiple_particles_pos_y);
pp_species_dot_source.getArrWithParser("multiple_particles_pos_z", multiple_particles_pos_z);
pp_species_dot_source.getArrWithParser("multiple_particles_ux", multiple_particles_ux);
pp_species_dot_source.getArrWithParser("multiple_particles_uy", multiple_particles_uy);
pp_species_dot_source.getArrWithParser("multiple_particles_uz", multiple_particles_uz);
pp_species_dot_source.getArrWithParser("multiple_particles_weight", multiple_particles_weight);
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
((multiple_particles_pos_x.size() == multiple_particles_pos_y.size()) &&
(multiple_particles_pos_x.size() == multiple_particles_pos_z.size()) &&
Expand All @@ -227,19 +227,19 @@ void PlasmaInjector::setupMultipleParticles (ParmParseWithOptionalGroup& pp_spec

void PlasmaInjector::setupGaussianBeam (ParmParseWithOptionalGroup& pp_species_dot_source)
{
pp_species_dot_source.get("x_m", x_m);
pp_species_dot_source.get("y_m", y_m);
pp_species_dot_source.get("z_m", z_m);
pp_species_dot_source.get("x_rms", x_rms);
pp_species_dot_source.get("y_rms", y_rms);
pp_species_dot_source.get("z_rms", z_rms);
pp_species_dot_source.query("x_cut", x_cut);
pp_species_dot_source.query("y_cut", y_cut);
pp_species_dot_source.query("z_cut", z_cut);
pp_species_dot_source.get("q_tot", q_tot);
pp_species_dot_source.get("npart", npart);
pp_species_dot_source.query("do_symmetrize", do_symmetrize);
pp_species_dot_source.query("symmetrization_order", symmetrization_order);
pp_species_dot_source.getWithParser("x_m", x_m);
pp_species_dot_source.getWithParser("y_m", y_m);
pp_species_dot_source.getWithParser("z_m", z_m);
pp_species_dot_source.getWithParser("x_rms", x_rms);
pp_species_dot_source.getWithParser("y_rms", y_rms);
pp_species_dot_source.getWithParser("z_rms", z_rms);
pp_species_dot_source.queryWithParser("x_cut", x_cut);
pp_species_dot_source.queryWithParser("y_cut", y_cut);
pp_species_dot_source.queryWithParser("z_cut", z_cut);
pp_species_dot_source.getWithParser("q_tot", q_tot);
pp_species_dot_source.getWithParser("npart", npart);
pp_species_dot_source.queryWithParser("do_symmetrize", do_symmetrize);
pp_species_dot_source.queryWithParser("symmetrization_order", symmetrization_order);
const std::set<int> valid_symmetries = {4,8};
WARPX_ALWAYS_ASSERT_WITH_MESSAGE( valid_symmetries.count(symmetrization_order),
"Error: Symmetrization only supported to orders 4 or 8 ");
Expand All @@ -262,7 +262,7 @@ void PlasmaInjector::setupGaussianBeam (ParmParseWithOptionalGroup& pp_species_d

void PlasmaInjector::setupNRandomPerCell (ParmParseWithOptionalGroup& pp_species_dot_source)
{
pp_species_dot_source.get("num_particles_per_cell", num_particles_per_cell);
pp_species_dot_source.getWithParser("num_particles_per_cell", num_particles_per_cell);
#if WARPX_DIM_RZ
if (WarpX::n_rz_azimuthal_modes > 1) {
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
Expand Down Expand Up @@ -291,7 +291,7 @@ void PlasmaInjector::setupNRandomPerCell (ParmParseWithOptionalGroup& pp_species

void PlasmaInjector::setupNFluxPerCell (ParmParseWithOptionalGroup& pp_species_dot_source)
{
pp_species_dot_source.get("num_particles_per_cell", num_particles_per_cell_real);
pp_species_dot_source.getWithParser("num_particles_per_cell", num_particles_per_cell_real);
#ifdef WARPX_DIM_RZ
if (WarpX::n_rz_azimuthal_modes > 1) {
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
Expand All @@ -301,9 +301,9 @@ void PlasmaInjector::setupNFluxPerCell (ParmParseWithOptionalGroup& pp_species_d
"(Please visit PR#765 for more information.)");
}
#endif
pp_species_dot_source.get("surface_flux_pos", surface_flux_pos);
pp_species_dot_source.query("flux_tmin", flux_tmin);
pp_species_dot_source.query("flux_tmax", flux_tmax);
pp_species_dot_source.getWithParser("surface_flux_pos", surface_flux_pos);
pp_species_dot_source.queryWithParser("flux_tmin", flux_tmin);
pp_species_dot_source.queryWithParser("flux_tmax", flux_tmax);
std::string flux_normal_axis_string;
pp_species_dot_source.get("flux_normal_axis", flux_normal_axis_string);
flux_normal_axis = -1;
Expand Down Expand Up @@ -342,7 +342,7 @@ void PlasmaInjector::setupNFluxPerCell (ParmParseWithOptionalGroup& pp_species_d
#endif
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(flux_normal_axis >= 0,
"Error: Invalid value for flux_normal_axis. It must be " + flux_normal_axis_help);
pp_species_dot_source.get("flux_direction", flux_direction);
pp_species_dot_source.getWithParser("flux_direction", flux_direction);
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(flux_direction == +1 || flux_direction == -1,
"Error: flux_direction must be -1 or +1.");
// Construct InjectorPosition with InjectorPositionRandom.
Expand Down Expand Up @@ -376,7 +376,7 @@ void PlasmaInjector::setupNuniformPerCell (ParmParseWithOptionalGroup& pp_specie
#else
constexpr int num_required_ppc_each_dim = 3;
#endif
pp_species_dot_source.get("num_particles_per_cell_each_dim", num_particles_per_cell_each_dim,
pp_species_dot_source.getArrWithParser("num_particles_per_cell_each_dim", num_particles_per_cell_each_dim,
0, num_required_ppc_each_dim);
#if WARPX_DIM_XZ
num_particles_per_cell_each_dim.push_back(1);
Expand Down Expand Up @@ -427,8 +427,8 @@ void PlasmaInjector::setupExternalFile (ParmParseWithOptionalGroup& pp_species_d
std::string str_injection_file;
pp_species_dot_source.get("injection_file", str_injection_file);
// optional parameters
pp_species_dot_source.query("q_tot", q_tot);
pp_species_dot_source.query("z_shift",z_shift);
pp_species_dot_source.queryWithParser("q_tot", q_tot);
pp_species_dot_source.queryWithParser("z_shift",z_shift);

#ifdef WARPX_USE_OPENPMD
const amrex::ParmParse pp_species(species_name);
Expand Down Expand Up @@ -533,7 +533,7 @@ void PlasmaInjector::parseFlux (ParmParseWithOptionalGroup& pp_species_dot_sourc
std::transform(flux_prof_s.begin(), flux_prof_s.end(),
flux_prof_s.begin(), ::tolower);
if (flux_prof_s == "constant") {
pp_species_dot_source.get("flux", flux);
pp_species_dot_source.getWithParser("flux", flux);
// Construct InjectorFlux with InjectorFluxConstant.
h_inj_flux.reset(new InjectorFlux((InjectorFluxConstant*)nullptr, flux));
} else if (flux_prof_s == "parse_flux_function") {
Expand Down
2 changes: 1 addition & 1 deletion Source/Initialization/TemperatureProperties.H
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifndef TEMPERATURE_PROPERTIES_H_
#define TEMPERATURE_PROPERTIES_H_

#include "ParmParseWithOptionalGroup.H"
#include "Utils/ParmParseWithOptionalGroup.H"

#include <AMReX_Parser.H>
#include <AMReX_REAL.H>
Expand Down
2 changes: 1 addition & 1 deletion Source/Initialization/TemperatureProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ TemperatureProperties::TemperatureProperties (const ParmParseWithOptionalGroup&
pp.query("momentum_distribution_type", mom_dist_s);
if (temp_dist_s == "constant") {
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
pp.query("theta", theta),
pp.queryWithParser("theta", theta),
"Temperature parameter theta not specified");

// Do validation on theta value
Expand Down
2 changes: 1 addition & 1 deletion Source/Initialization/VelocityProperties.H
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef VELOCITY_PROPERTIES_H_
#define VELOCITY_PROPERTIES_H_

#include "ParmParseWithOptionalGroup.H"
#include "Utils/ParmParseWithOptionalGroup.H"

#include <AMReX_ParmParse.H>
#include <AMReX_Parser.H>
Expand Down
2 changes: 1 addition & 1 deletion Source/Initialization/VelocityProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ VelocityProperties::VelocityProperties (const ParmParseWithOptionalGroup& pp):

pp.query("beta_distribution_type", vel_dist_s);
if (vel_dist_s == "constant") {
pp.query("beta", m_velocity);
pp.queryWithParser("beta", m_velocity);
m_type = VelConstantValue;
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
m_velocity > -1 && m_velocity < 1,
Expand Down
1 change: 1 addition & 0 deletions Source/Utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ foreach(D IN LISTS WarpX_DIMS)
Interpolate.cpp
ParticleUtils.cpp
SpeciesUtils.cpp
ParmParseWithOptionalGroup.cpp
RelativeCellPosition.cpp
WarpXAlgorithmSelection.cpp
WarpXMovingWindow.cpp
Expand Down
1 change: 1 addition & 0 deletions Source/Utils/Make.package
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ CEXE_sources += IntervalsParser.cpp
CEXE_sources += RelativeCellPosition.cpp
CEXE_sources += ParticleUtils.cpp
CEXE_sources += SpeciesUtils.cpp
CEXE_sources += ParmParseWithOptionalGroup.cpp

include $(WARPX_HOME)/Source/Utils/Algorithms/Make.package
include $(WARPX_HOME)/Source/Utils/Logo/Make.package
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ struct ParmParseWithOptionalGroup

/* Note that this follows the code pattern of ParmParse and writes out
* each version of the routine rather than using templates */
bool query (const char* name, bool& ref) const;
bool query (const char* name, int& ref) const;
bool query (const char* name, double& ref) const;
bool query (const char* name, float& ref) const;
bool queryWithParser (const char* name, bool& ref) const;
bool queryWithParser (const char* name, int& ref) const;
bool queryWithParser (const char* name, double& ref) const;
bool queryWithParser (const char* name, float& ref) const;
bool query (const char* name, std::string& ref) const;

void get (const char* name, int& ref) const;
void get (const char* name, long& ref) const;
void get (const char* name, double& ref) const;
void get (const char* name, float& ref) const;
void getWithParser (const char* name, int& ref) const;
void getWithParser (const char* name, long& ref) const;
void getWithParser (const char* name, double& ref) const;
void getWithParser (const char* name, float& ref) const;
void get (const char* name, std::string& ref) const;
void get (const char* name, amrex::Vector<double>& ref) const;
void get (const char* name, amrex::Vector<float>& ref) const;
void get (const char* name, amrex::Vector<int>& ref, int start_ix, int num_val) const;
void get (const char* name, amrex::Vector<double>& ref, int start_ix, int num_val) const;
void get (const char* name, amrex::Vector<float>& ref, int start_ix, int num_val) const;
void getArrWithParser (const char* name, amrex::Vector<double>& ref) const;
void getArrWithParser (const char* name, amrex::Vector<float>& ref) const;
void getArrWithParser (const char* name, amrex::Vector<int>& ref, int start_ix, int num_val) const;
void getArrWithParser (const char* name, amrex::Vector<double>& ref, int start_ix, int num_val) const;
void getArrWithParser (const char* name, amrex::Vector<float>& ref, int start_ix, int num_val) const;

void get_long_string (const char* name, std::string& ref) const;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ParmParseWithOptionalGroup::ParmParseWithOptionalGroup(std::string const& a_pref
}
}

bool ParmParseWithOptionalGroup::query (const char* name, bool& ref) const
bool ParmParseWithOptionalGroup::queryWithParser (const char* name, bool& ref) const
{
// First, query name with the group name
const amrex::ParmParse pp_with_group(prefix_dot_group);
Expand All @@ -35,7 +35,7 @@ bool ParmParseWithOptionalGroup::query (const char* name, bool& ref) const
return is_specified;
}

bool ParmParseWithOptionalGroup::query (const char* name, int& ref) const
bool ParmParseWithOptionalGroup::queryWithParser (const char* name, int& ref) const
{
// First, query name with the group name
const amrex::ParmParse pp_with_group(prefix_dot_group);
Expand All @@ -48,7 +48,7 @@ bool ParmParseWithOptionalGroup::query (const char* name, int& ref) const
return is_specified;
}

bool ParmParseWithOptionalGroup::query (const char* name, double& ref) const
bool ParmParseWithOptionalGroup::queryWithParser (const char* name, double& ref) const
{
// First, query name with the group name
const amrex::ParmParse pp_with_group(prefix_dot_group);
Expand All @@ -61,7 +61,7 @@ bool ParmParseWithOptionalGroup::query (const char* name, double& ref) const
return is_specified;
}

bool ParmParseWithOptionalGroup::query (const char* name, float& ref) const
bool ParmParseWithOptionalGroup::queryWithParser (const char* name, float& ref) const
{
// First, query name with the group name
const amrex::ParmParse pp_with_group(prefix_dot_group);
Expand Down Expand Up @@ -102,7 +102,7 @@ void ParmParseWithOptionalGroup::get_long_string (const char* name, std::string&

}

void ParmParseWithOptionalGroup::get (const char* name, int& ref) const
void ParmParseWithOptionalGroup::getWithParser (const char* name, int& ref) const
{
// First, query name with the group name
const amrex::ParmParse pp_with_group(prefix_dot_group);
Expand All @@ -114,7 +114,7 @@ void ParmParseWithOptionalGroup::get (const char* name, int& ref) const
}
}

void ParmParseWithOptionalGroup::get (const char* name, long& ref) const
void ParmParseWithOptionalGroup::getWithParser (const char* name, long& ref) const
{
// First, query name with the group name
const amrex::ParmParse pp_with_group(prefix_dot_group);
Expand All @@ -126,7 +126,7 @@ void ParmParseWithOptionalGroup::get (const char* name, long& ref) const
}
}

void ParmParseWithOptionalGroup::get (const char* name, double& ref) const
void ParmParseWithOptionalGroup::getWithParser (const char* name, double& ref) const
{
// First, query name with the group name
const amrex::ParmParse pp_with_group(prefix_dot_group);
Expand All @@ -138,7 +138,7 @@ void ParmParseWithOptionalGroup::get (const char* name, double& ref) const
}
}

void ParmParseWithOptionalGroup::get (const char* name, float& ref) const
void ParmParseWithOptionalGroup::getWithParser (const char* name, float& ref) const
{
// First, query name with the group name
const amrex::ParmParse pp_with_group(prefix_dot_group);
Expand All @@ -162,7 +162,7 @@ void ParmParseWithOptionalGroup::get (const char* name, std::string& ref) const
}
}

void ParmParseWithOptionalGroup::get (const char* name, amrex::Vector<double>& ref) const
void ParmParseWithOptionalGroup::getArrWithParser (const char* name, amrex::Vector<double>& ref) const
{
// First, query name with the group name
const amrex::ParmParse pp_with_group(prefix_dot_group);
Expand All @@ -174,7 +174,7 @@ void ParmParseWithOptionalGroup::get (const char* name, amrex::Vector<double>& r
}
}

void ParmParseWithOptionalGroup::get (const char* name, amrex::Vector<float>& ref) const
void ParmParseWithOptionalGroup::getArrWithParser (const char* name, amrex::Vector<float>& ref) const
{
// First, query name with the group name
const amrex::ParmParse pp_with_group(prefix_dot_group);
Expand All @@ -186,7 +186,7 @@ void ParmParseWithOptionalGroup::get (const char* name, amrex::Vector<float>& re
}
}

void ParmParseWithOptionalGroup::get (const char* name, amrex::Vector<int>& ref, int start_ix, int num_val) const
void ParmParseWithOptionalGroup::getArrWithParser (const char* name, amrex::Vector<int>& ref, int start_ix, int num_val) const
{
// First, query name with the group name
const amrex::ParmParse pp_with_group(prefix_dot_group);
Expand All @@ -198,7 +198,7 @@ void ParmParseWithOptionalGroup::get (const char* name, amrex::Vector<int>& ref,
}
}

void ParmParseWithOptionalGroup::get (const char* name, amrex::Vector<double>& ref, int start_ix, int num_val) const
void ParmParseWithOptionalGroup::getArrWithParser (const char* name, amrex::Vector<double>& ref, int start_ix, int num_val) const
{
// First, query name with the group name
const amrex::ParmParse pp_with_group(prefix_dot_group);
Expand All @@ -210,7 +210,7 @@ void ParmParseWithOptionalGroup::get (const char* name, amrex::Vector<double>& r
}
}

void ParmParseWithOptionalGroup::get (const char* name, amrex::Vector<float>& ref, int start_ix, int num_val) const
void ParmParseWithOptionalGroup::getArrWithParser (const char* name, amrex::Vector<float>& ref, int start_ix, int num_val) const
{
// First, query name with the group name
const amrex::ParmParse pp_with_group(prefix_dot_group);
Expand Down
Loading

0 comments on commit 4049b1d

Please sign in to comment.