aboutsummaryrefslogtreecommitdiff
path: root/Source/Initialization/PlasmaInjector.cpp
diff options
context:
space:
mode:
authorGravatar Neïl Zaim <49716072+NeilZaim@users.noreply.github.com> 2021-10-20 05:38:00 +0200
committerGravatar GitHub <noreply@github.com> 2021-10-19 20:38:00 -0700
commiteb9d7eed2ad04ffb4fdf37abb5e4e56bd88e75d5 (patch)
tree81f26153e962cd1edeee9a1b2091584f748322b6 /Source/Initialization/PlasmaInjector.cpp
parent82395a83095f7159fd8835debc85e42ff177b7f5 (diff)
downloadWarpX-eb9d7eed2ad04ffb4fdf37abb5e4e56bd88e75d5.tar.gz
WarpX-eb9d7eed2ad04ffb4fdf37abb5e4e56bd88e75d5.tar.zst
WarpX-eb9d7eed2ad04ffb4fdf37abb5e4e56bd88e75d5.zip
Simplify momentum initialization in example input files (#2309)
* Simplify momentum initialization in example input files * Update benchmarks * Trigger Build * Apply suggestions from code review Co-authored-by: Edoardo Zoni <59625522+EZoni@users.noreply.github.com> * Add more amrex prefix * Remove using namespace amrex in PlasmaInjector.cpp * Fix compilation with OpenPMD Co-authored-by: Edoardo Zoni <59625522+EZoni@users.noreply.github.com>
Diffstat (limited to 'Source/Initialization/PlasmaInjector.cpp')
-rw-r--r--Source/Initialization/PlasmaInjector.cpp137
1 files changed, 76 insertions, 61 deletions
diff --git a/Source/Initialization/PlasmaInjector.cpp b/Source/Initialization/PlasmaInjector.cpp
index aa02c94f5..1e4b632c0 100644
--- a/Source/Initialization/PlasmaInjector.cpp
+++ b/Source/Initialization/PlasmaInjector.cpp
@@ -27,6 +27,7 @@
#include <AMReX_Parser.H>
#include <AMReX_Print.H>
#include <AMReX_RandomEngine.H>
+#include <AMReX_REAL.H>
#include <algorithm>
#include <cctype>
@@ -36,8 +37,6 @@
#include <utility>
#include <vector>
-using namespace amrex;
-
namespace {
void StringParseAbortMessage(const std::string& var,
const std::string& name) {
@@ -54,7 +53,7 @@ PlasmaInjector::PlasmaInjector () {}
PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name)
: species_id(ispecies), species_name(name)
{
- ParmParse pp_species_name(species_name);
+ amrex::ParmParse pp_species_name(species_name);
#ifdef AMREX_USE_GPU
static_assert(std::is_trivially_copyable<InjectorPosition>::value,
@@ -78,7 +77,7 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name)
zmax = std::numeric_limits<amrex::Real>::max();
// NOTE: When periodic boundaries are used, default injection range is set to mother grid dimensions.
- const Geometry& geom = WarpX::GetInstance().Geom(0);
+ const amrex::Geometry& geom = WarpX::GetInstance().Geom(0);
if( geom.isPeriodic(0) ) {
xmin = geom.ProbLo(0);
xmax = geom.ProbHi(0);
@@ -132,9 +131,9 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name)
bool mass_is_specified = queryWithParser(pp_species_name, "mass", mass);
if ( charge_is_specified && species_is_specified ){
- Print() << "WARNING: Both '" << species_name << ".charge' and "
- << species_name << ".species_type' are specified\n'"
- << species_name << ".charge' will take precedence.\n";
+ amrex::Print() << "WARNING: Both '" << species_name << ".charge' and "
+ << species_name << ".species_type' are specified\n'"
+ << species_name << ".charge' will take precedence.\n";
}
if (!charge_is_specified && !species_is_specified && injection_style != "external_file"){
// external file will throw own assertions below if charge cannot be found
@@ -142,9 +141,9 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name)
}
if ( mass_is_specified && species_is_specified ){
- Print() << "WARNING: Both '" << species_name << ".mass' and "
- << species_name << ".species_type' are specified\n'"
- << species_name << ".mass' will take precedence.\n";
+ amrex::Print() << "WARNING: Both '" << species_name << ".mass' and "
+ << species_name << ".species_type' are specified\n'"
+ << species_name << ".mass' will take precedence.\n";
}
if (!mass_is_specified && !species_is_specified && injection_style != "external_file"){
// external file will throw own assertions below if mass cannot be found
@@ -295,7 +294,7 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name)
h_inj_pos = std::make_unique<InjectorPosition>(
(InjectorPositionRegular*)nullptr,
xmin, xmax, ymin, ymax, zmin, zmax,
- Dim3{num_particles_per_cell_each_dim[0],
+ amrex::Dim3{num_particles_per_cell_each_dim[0],
num_particles_per_cell_each_dim[1],
num_particles_per_cell_each_dim[2]});
num_particles_per_cell = num_particles_per_cell_each_dim[0] *
@@ -316,7 +315,7 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name)
queryWithParser(pp_species_name, "z_shift",z_shift);
#ifdef WARPX_USE_OPENPMD
- if (ParallelDescriptor::IOProcessor()) {
+ if (amrex::ParallelDescriptor::IOProcessor()) {
m_openpmd_input_series = std::make_unique<openPMD::Series>(
str_injection_file, openPMD::Access::READ_ONLY);
@@ -344,34 +343,36 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name)
"'" + ps_name + ".species_type' in your input file!\n");
if (charge_is_specified) {
- Print() << "WARNING: Both '" << ps_name << ".charge' and '"
- << ps_name << ".injection_file' specify a charge.\n'"
- << ps_name << ".charge' will take precedence.\n";
+ amrex::Print() << "WARNING: Both '" << ps_name << ".charge' and '"
+ << ps_name << ".injection_file' specify a charge.\n'"
+ << ps_name << ".charge' will take precedence.\n";
}
else if (species_is_specified) {
- Print() << "WARNING: Both '" << ps_name << ".species_type' and '"
- << ps_name << ".injection_file' specify a charge.\n'"
- << ps_name << ".species_type' will take precedence.\n";
+ amrex::Print() << "WARNING: Both '" << ps_name << ".species_type' and '"
+ << ps_name << ".injection_file' specify a charge.\n'"
+ << ps_name << ".species_type' will take precedence.\n";
}
else {
// TODO: Add ASSERT_WITH_MESSAGE to test if charge is a constant record
- ParticleReal const p_q = ps["charge"][openPMD::RecordComponent::SCALAR].loadChunk<ParticleReal>().get()[0];
+ amrex::ParticleReal const p_q =
+ ps["charge"][openPMD::RecordComponent::SCALAR].loadChunk<amrex::ParticleReal>().get()[0];
double const charge_unit = ps["charge"][openPMD::RecordComponent::SCALAR].unitSI();
charge = p_q * charge_unit;
}
if (mass_is_specified) {
- Print() << "WARNING: Both '" << ps_name << ".mass' and '"
- << ps_name << ".injection_file' specify a mass.\n'"
- << ps_name << ".mass' will take precedence.\n";
+ amrex::Print() << "WARNING: Both '" << ps_name << ".mass' and '"
+ << ps_name << ".injection_file' specify a mass.\n'"
+ << ps_name << ".mass' will take precedence.\n";
}
else if (species_is_specified) {
- Print() << "WARNING: Both '" << ps_name << ".species_type' and '"
- << ps_name << ".injection_file' specify a mass.\n'"
- << ps_name << ".species_type' will take precedence.\n";
+ amrex::Print() << "WARNING: Both '" << ps_name << ".species_type' and '"
+ << ps_name << ".injection_file' specify a mass.\n'"
+ << ps_name << ".species_type' will take precedence.\n";
}
else {
// TODO: Add ASSERT_WITH_MESSAGE to test if mass is a constant record
- ParticleReal const p_m = ps["mass"][openPMD::RecordComponent::SCALAR].loadChunk<ParticleReal>().get()[0];
+ amrex::ParticleReal const p_m =
+ ps["mass"][openPMD::RecordComponent::SCALAR].loadChunk<amrex::ParticleReal>().get()[0];
double const mass_unit = ps["mass"][openPMD::RecordComponent::SCALAR].unitSI();
mass = p_m * mass_unit;
}
@@ -379,13 +380,13 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name)
// Broadcast charge and mass to non-IO processors
if (!charge_is_specified && !species_is_specified)
- ParallelDescriptor::Bcast(&charge, 1,
- ParallelDescriptor::IOProcessorNumber());
+ amrex::ParallelDescriptor::Bcast(&charge, 1,
+ amrex::ParallelDescriptor::IOProcessorNumber());
if (!mass_is_specified && !species_is_specified)
- ParallelDescriptor::Bcast(&mass, 1,
- ParallelDescriptor::IOProcessorNumber());
+ amrex::ParallelDescriptor::Bcast(&mass, 1,
+ amrex::ParallelDescriptor::IOProcessorNumber());
#else
- Abort("Plasma injection via external_file requires openPMD support: "
+ amrex::Abort("Plasma injection via external_file requires openPMD support: "
"Add USE_OPENPMD=TRUE when compiling WarpX.\n");
#endif // WARPX_USE_OPENPMD
@@ -444,7 +445,7 @@ PlasmaInjector::~PlasmaInjector ()
// Depending on injection type at runtime, initialize inj_rho
// so that inj_rho->getDensity calls
// InjectorPosition[Constant or Custom or etc.].getDensity.
-void PlasmaInjector::parseDensity (ParmParse& pp)
+void PlasmaInjector::parseDensity (amrex::ParmParse& pp)
{
// parse density information
std::string rho_prof_s;
@@ -464,7 +465,8 @@ void PlasmaInjector::parseDensity (ParmParse& pp)
} else if (rho_prof_s == "parse_density_function") {
Store_parserString(pp, "density_function(x,y,z)", str_density_function);
// Construct InjectorDensity with InjectorDensityParser.
- density_parser = std::make_unique<Parser>(makeParser(str_density_function,{"x","y","z"}));
+ density_parser = std::make_unique<amrex::Parser>(makeParser(
+ str_density_function,{"x","y","z"}));
h_inj_rho.reset(new InjectorDensity((InjectorDensityParser*)nullptr,
density_parser->compile<3>()));
} else {
@@ -480,8 +482,10 @@ void PlasmaInjector::parseDensity (ParmParse& pp)
// Depending on injection type at runtime, initialize inj_mom
// so that inj_mom->getMomentum calls
// InjectorMomentum[Constant or Custom or etc.].getMomentum.
-void PlasmaInjector::parseMomentum (ParmParse& pp)
+void PlasmaInjector::parseMomentum (amrex::ParmParse& pp)
{
+ using namespace amrex::literals;
+
// parse momentum information
std::string mom_dist_s;
pp.get("momentum_distribution_type", mom_dist_s);
@@ -489,25 +493,31 @@ void PlasmaInjector::parseMomentum (ParmParse& pp)
mom_dist_s.end(),
mom_dist_s.begin(),
::tolower);
- if (mom_dist_s == "constant") {
- Real ux = 0.;
- Real uy = 0.;
- Real uz = 0.;
+ if (mom_dist_s == "at_rest") {
+ constexpr amrex::Real ux = 0._rt;
+ constexpr amrex::Real uy = 0._rt;
+ constexpr amrex::Real uz = 0._rt;
+ // Construct InjectorMomentum with InjectorMomentumConstant.
+ h_inj_mom.reset(new InjectorMomentum((InjectorMomentumConstant*)nullptr, ux, uy, uz));
+ } else if (mom_dist_s == "constant") {
+ amrex::Real ux = 0._rt;
+ amrex::Real uy = 0._rt;
+ amrex::Real uz = 0._rt;
queryWithParser(pp, "ux", ux);
queryWithParser(pp, "uy", uy);
queryWithParser(pp, "uz", uz);
// Construct InjectorMomentum with InjectorMomentumConstant.
- h_inj_mom.reset(new InjectorMomentum((InjectorMomentumConstant*)nullptr, ux,uy, uz));
+ h_inj_mom.reset(new InjectorMomentum((InjectorMomentumConstant*)nullptr, ux, uy, uz));
} else if (mom_dist_s == "custom") {
// Construct InjectorMomentum with InjectorMomentumCustom.
h_inj_mom.reset(new InjectorMomentum((InjectorMomentumCustom*)nullptr, species_name));
} else if (mom_dist_s == "gaussian") {
- Real ux_m = 0.;
- Real uy_m = 0.;
- Real uz_m = 0.;
- Real ux_th = 0.;
- Real uy_th = 0.;
- Real uz_th = 0.;
+ amrex::Real ux_m = 0._rt;
+ amrex::Real uy_m = 0._rt;
+ amrex::Real uz_m = 0._rt;
+ amrex::Real ux_th = 0._rt;
+ amrex::Real uy_th = 0._rt;
+ amrex::Real uz_th = 0._rt;
queryWithParser(pp, "ux_m", ux_m);
queryWithParser(pp, "uy_m", uy_m);
queryWithParser(pp, "uz_m", uz_m);
@@ -520,12 +530,12 @@ void PlasmaInjector::parseMomentum (ParmParse& pp)
} else if (mom_dist_s == "gaussianflux") {
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(surface_flux,
"Error: gaussianflux can only be used with injection_style = NFluxPerCell");
- Real ux_m = 0.;
- Real uy_m = 0.;
- Real uz_m = 0.;
- Real ux_th = 0.;
- Real uy_th = 0.;
- Real uz_th = 0.;
+ amrex::Real ux_m = 0._rt;
+ amrex::Real uy_m = 0._rt;
+ amrex::Real uz_m = 0._rt;
+ amrex::Real ux_th = 0._rt;
+ amrex::Real uy_th = 0._rt;
+ amrex::Real uz_th = 0._rt;
queryWithParser(pp, "ux_m", ux_m);
queryWithParser(pp, "uy_m", uy_m);
queryWithParser(pp, "uz_m", uz_m);
@@ -537,8 +547,8 @@ void PlasmaInjector::parseMomentum (ParmParse& pp)
ux_m, uy_m, uz_m, ux_th, uy_th, uz_th,
flux_normal_axis, flux_direction));
} else if (mom_dist_s == "maxwell_boltzmann"){
- Real beta = 0.;
- Real theta = 10.;
+ amrex::Real beta = 0._rt;
+ amrex::Real theta = 10._rt;
int dir = 0;
std::string direction = "x";
queryWithParser(pp, "beta", beta);
@@ -568,8 +578,8 @@ void PlasmaInjector::parseMomentum (ParmParse& pp)
// Construct InjectorMomentum with InjectorMomentumBoltzmann.
h_inj_mom.reset(new InjectorMomentum((InjectorMomentumBoltzmann*)nullptr, theta, beta, dir));
} else if (mom_dist_s == "maxwell_juttner"){
- Real beta = 0.;
- Real theta = 10.;
+ amrex::Real beta = 0._rt;
+ amrex::Real theta = 10._rt;
int dir = 0;
std::string direction = "x";
queryWithParser(pp, "beta", beta);
@@ -599,7 +609,7 @@ void PlasmaInjector::parseMomentum (ParmParse& pp)
// Construct InjectorMomentum with InjectorMomentumJuttner.
h_inj_mom.reset(new InjectorMomentum((InjectorMomentumJuttner*)nullptr, theta, beta, dir));
} else if (mom_dist_s == "radial_expansion") {
- Real u_over_r = 0.;
+ amrex::Real u_over_r = 0._rt;
queryWithParser(pp, "u_over_r", u_over_r);
// Construct InjectorMomentum with InjectorMomentumRadialExpansion.
h_inj_mom.reset(new InjectorMomentum
@@ -612,9 +622,12 @@ void PlasmaInjector::parseMomentum (ParmParse& pp)
Store_parserString(pp, "momentum_function_uz(x,y,z)",
str_momentum_function_uz);
// Construct InjectorMomentum with InjectorMomentumParser.
- ux_parser = std::make_unique<Parser>(makeParser(str_momentum_function_ux,{"x","y","z"}));
- uy_parser = std::make_unique<Parser>(makeParser(str_momentum_function_uy,{"x","y","z"}));
- uz_parser = std::make_unique<Parser>(makeParser(str_momentum_function_uz,{"x","y","z"}));
+ ux_parser = std::make_unique<amrex::Parser>(makeParser(str_momentum_function_ux,
+ {"x","y","z"}));
+ uy_parser = std::make_unique<amrex::Parser>(makeParser(str_momentum_function_uy,
+ {"x","y","z"}));
+ uz_parser = std::make_unique<amrex::Parser>(makeParser(str_momentum_function_uz,
+ {"x","y","z"}));
h_inj_mom.reset(new InjectorMomentum((InjectorMomentumParser*)nullptr,
ux_parser->compile<3>(),
uy_parser->compile<3>(),
@@ -629,12 +642,14 @@ void PlasmaInjector::parseMomentum (ParmParse& pp)
}
}
-XDim3 PlasmaInjector::getMomentum (Real x, Real y, Real z) const noexcept
+amrex::XDim3 PlasmaInjector::getMomentum (amrex::Real x,
+ amrex::Real y,
+ amrex::Real z) const noexcept
{
return h_inj_mom->getMomentum(x, y, z, amrex::RandomEngine{}); // gamma*beta
}
-bool PlasmaInjector::insideBounds (Real x, Real y, Real z) const noexcept
+bool PlasmaInjector::insideBounds (amrex::Real x, amrex::Real y, amrex::Real z) const noexcept
{
return (x < xmax and x >= xmin and
y < ymax and y >= ymin and