diff options
Diffstat (limited to 'Source/Initialization/PlasmaInjector.cpp')
-rw-r--r-- | Source/Initialization/PlasmaInjector.cpp | 111 |
1 files changed, 29 insertions, 82 deletions
diff --git a/Source/Initialization/PlasmaInjector.cpp b/Source/Initialization/PlasmaInjector.cpp index d4c9e9ba5..6c9f66bc0 100644 --- a/Source/Initialization/PlasmaInjector.cpp +++ b/Source/Initialization/PlasmaInjector.cpp @@ -22,7 +22,6 @@ #include <string> #include <memory> - using namespace amrex; namespace { @@ -34,40 +33,6 @@ namespace { string = stringstream.str(); amrex::Abort(string.c_str()); } - - Real parseChargeName(const ParmParse& pp, const std::string& name) { - Real result; - if (name == "q_e") { - return PhysConst::q_e; - } else if (pp.query("charge", result)) { - return result; - } else { - StringParseAbortMessage("Charge", name); - return 0.0; - } - } - - Real parseChargeString(const ParmParse& pp, const std::string& name) { - if(name.substr(0, 1) == "-") - return -1.0 * parseChargeName(pp, name.substr(1, name.size() - 1)); - return parseChargeName(pp, name); - } - - Real parseMassString(const ParmParse& pp, const std::string& name) { - Real result; - if (name == "m_e") { - return PhysConst::m_e; - } else if (name == "m_p"){ - return PhysConst::m_p; - } else if (name == "inf"){ - return std::numeric_limits<double>::infinity(); - } else if (pp.query("mass", result)) { - return result; - } else { - StringParseAbortMessage("Mass", name); - return 0.0; - } - } } PlasmaInjector::PlasmaInjector () {} @@ -136,9 +101,7 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name) bool species_is_specified = pp.query("species_type", physical_species_s); if (species_is_specified){ physical_species = species::from_string( physical_species_s ); - // charge = SpeciesCharge[physical_species]; charge = species::get_charge( physical_species ); - // mass = SpeciesMass[physical_species]; mass = species::get_mass( physical_species ); } @@ -146,18 +109,9 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name) pp.query("injection_style", s_inj_style); // parse charge and mass - std::string charge_s; - std::string mass_s; - bool charge_is_specified = pp.query("charge", charge_s); - bool mass_is_specified = pp.query("mass", mass_s); - - if (charge_is_specified){ - std::transform(charge_s.begin(), - charge_s.end(), - charge_s.begin(), - ::tolower); - charge = parseChargeString(pp, charge_s); - } + bool charge_is_specified = queryWithParser(pp, "charge", charge); + bool mass_is_specified = queryWithParser(pp, "mass", mass); + if ( charge_is_specified && species_is_specified ){ Print() << "WARNING: Both '" << species_name << ".charge' and " << species_name << ".species_type' are specified\n'" @@ -168,13 +122,6 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name) amrex::Abort("Need to specify at least one of species_type or charge"); } - if (mass_is_specified){ - std::transform(mass_s.begin(), - mass_s.end(), - mass_s.begin(), - ::tolower); - mass = parseMassString(pp, mass_s); - } if ( mass_is_specified && species_is_specified ){ Print() << "WARNING: Both '" << species_name << ".mass' and " << species_name << ".species_type' are specified\n'" @@ -205,16 +152,16 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name) add_single_particle = true; return; } else if (part_pos_s == "gaussian_beam") { - pp.get("x_m", x_m); - pp.get("y_m", y_m); - pp.get("z_m", z_m); - pp.get("x_rms", x_rms); - pp.get("y_rms", y_rms); - pp.get("z_rms", z_rms); - pp.query("x_cut", x_cut); - pp.query("y_cut", y_cut); - pp.query("z_cut", z_cut); - pp.get("q_tot", q_tot); + getWithParser(pp, "x_m", x_m); + getWithParser(pp, "y_m", y_m); + getWithParser(pp, "z_m", z_m); + getWithParser(pp, "x_rms", x_rms); + getWithParser(pp, "y_rms", y_rms); + getWithParser(pp, "z_rms", z_rms); + queryWithParser(pp, "x_cut", x_cut); + queryWithParser(pp, "y_cut", y_cut); + queryWithParser(pp, "z_cut", z_cut); + getWithParser(pp, "q_tot", q_tot); pp.get("npart", npart); pp.query("do_symmetrize", do_symmetrize); gaussian_beam = true; @@ -274,8 +221,8 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name) std::string str_injection_file; pp.get("injection_file", str_injection_file); // optional parameters - pp.query("q_tot", q_tot); - pp.query("z_shift",z_shift); + queryWithParser(pp, "q_tot", q_tot); + queryWithParser(pp, "z_shift",z_shift); #ifdef WARPX_USE_OPENPMD if (ParallelDescriptor::IOProcessor()) { @@ -454,9 +401,9 @@ void PlasmaInjector::parseMomentum (ParmParse& pp) Real ux = 0.; Real uy = 0.; Real uz = 0.; - pp.query("ux", ux); - pp.query("uy", uy); - pp.query("uz", uz); + 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)); } else if (mom_dist_s == "custom") { @@ -469,12 +416,12 @@ void PlasmaInjector::parseMomentum (ParmParse& pp) Real ux_th = 0.; Real uy_th = 0.; Real uz_th = 0.; - pp.query("ux_m", ux_m); - pp.query("uy_m", uy_m); - pp.query("uz_m", uz_m); - pp.query("ux_th", ux_th); - pp.query("uy_th", uy_th); - pp.query("uz_th", uz_th); + queryWithParser(pp, "ux_m", ux_m); + queryWithParser(pp, "uy_m", uy_m); + queryWithParser(pp, "uz_m", uz_m); + queryWithParser(pp, "ux_th", ux_th); + queryWithParser(pp, "uy_th", uy_th); + queryWithParser(pp, "uz_th", uz_th); // Construct InjectorMomentum with InjectorMomentumGaussian. h_inj_mom.reset(new InjectorMomentum((InjectorMomentumGaussian*)nullptr, ux_m, uy_m, uz_m, ux_th, uy_th, uz_th)); @@ -483,11 +430,11 @@ void PlasmaInjector::parseMomentum (ParmParse& pp) Real theta = 10.; int dir = 0; std::string direction = "x"; - pp.query("beta", beta); + queryWithParser(pp, "beta", beta); if(beta < 0){ amrex::Abort("Please enter a positive beta value. Drift direction is set with <s_name>.bulk_vel_dir = 'x' or '+x', '-x', 'y' or '+y', etc."); } - pp.query("theta", theta); + queryWithParser(pp, "theta", theta); pp.query("bulk_vel_dir", direction); if(direction[0] == '-'){ beta = -beta; @@ -514,11 +461,11 @@ void PlasmaInjector::parseMomentum (ParmParse& pp) Real theta = 10.; int dir = 0; std::string direction = "x"; - pp.query("beta", beta); + queryWithParser(pp, "beta", beta); if(beta < 0){ amrex::Abort("Please enter a positive beta value. Drift direction is set with <s_name>.bulk_vel_dir = 'x' or '+x', '-x', 'y' or '+y', etc."); } - pp.query("theta", theta); + queryWithParser(pp, "theta", theta); pp.query("bulk_vel_dir", direction); if(direction[0] == '-'){ beta = -beta; @@ -542,7 +489,7 @@ void PlasmaInjector::parseMomentum (ParmParse& pp) h_inj_mom.reset(new InjectorMomentum((InjectorMomentumJuttner*)nullptr, theta, beta, dir)); } else if (mom_dist_s == "radial_expansion") { Real u_over_r = 0.; - pp.query("u_over_r", u_over_r); + queryWithParser(pp, "u_over_r", u_over_r); // Construct InjectorMomentum with InjectorMomentumRadialExpansion. h_inj_mom.reset(new InjectorMomentum ((InjectorMomentumRadialExpansion*)nullptr, u_over_r)); |