Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Parser #595

Merged
merged 20 commits into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions examples/blowout_wake/inputs_SI
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ hipace.predcorr_max_iterations = 1
hipace.predcorr_B_mixing_factor = 0.12
hipace.predcorr_B_error_tolerance = -1

my_constants.kp_inv = 10.e-6
my_constants.kp = 1. / kp_inv
my_constants.wp = clight * kp
my_constants.ne = wp^2 * m_e * epsilon0 / q_e^2

amr.blocking_factor = 2
amr.max_level = 0

Expand All @@ -16,25 +21,25 @@ hipace.numprocs_y = 1
hipace.depos_order_xy = 2

geometry.coord_sys = 0 # 0: Cartesian
geometry.is_periodic = 1 1 0 # Is periodic?
geometry.prob_lo = -80.e-6 -80.e-6 -60.e-6 # physical domain
geometry.prob_hi = 80.e-6 80.e-6 60.e-6
geometry.is_periodic = true true false # Is periodic?
geometry.prob_lo = -8.*kp_inv -8.*kp_inv -6.*kp_inv # physical domain
geometry.prob_hi = 8.*kp_inv 8.*kp_inv 6.*kp_inv

beams.names = beam
beam.injection_type = fixed_ppc
beam.profile = gaussian
beam.zmin = -59.e-6
beam.zmax = 59.e-6
beam.radius = 12.e-6
beam.density = 8.47187610257747e23 # 3*ne
beam.density = 3.*ne
beam.u_mean = 0. 0. 2000
beam.u_std = 0. 0. 0.
beam.position_mean = 0. 0. 0
beam.position_std = 3.e-6 3.e-6 14.1e-6
beam.ppc = 1 1 1

plasmas.names = plasma
plasma.density = 2.8239587008591567e23 # at this density, 1/kp = 10um
plasma.density = ne
plasma.ppc = 1 1
plasma.u_mean = 0.0 0.0 0.
plasma.element = electron
Expand Down
19 changes: 12 additions & 7 deletions examples/blowout_wake/inputs_ionization_SI
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ hipace.predcorr_max_iterations = 1
hipace.predcorr_B_mixing_factor = 0.12
hipace.predcorr_B_error_tolerance = -1

my_constants.ne = 1.25e24
my_constants.wp = sqrt(ne * q_e^2 / (epsilon0 * m_e))
my_constants.kp = wp / clight
my_constants.kp_inv = 1. / kp # =4.753069541um

amr.blocking_factor = 2
amr.max_level = 0

Expand All @@ -24,23 +29,23 @@ geometry.prob_hi = 20.e-6 20.e-6 30.e-6
beams.names = beam
beam.injection_type = fixed_ppc
beam.profile = flattop
beam.zmin = 15.493860918e-6
beam.zmax = 25e-6
beam.radius = 2.376534771e-6
beam.density = 5e24
beam.zmin = 25.e-6 - 2. * kp_inv
beam.zmax = 25.e-6
beam.radius = kp_inv / 2
beam.density = 4. * ne
beam.u_mean = 0. 0. 2000
beam.u_std = 0. 0. 0.
beam.ppc = 1 1 1

plasmas.names = elec ion

elec.density = 1.25e24 # at this density, 1/kp = 4.753069541um
elec.density = ne
elec.ppc = 0 0
elec.u_mean = 0.0 0.0 0.0
elec.element = electron
elec.neutralize_background = 0
elec.neutralize_background = false

ion.density = 1.25e24 # at this density, 1/kp = 4.753069541um
ion.density = ne
ion.ppc = 1 1
ion.u_mean = 0.0 0.0 0.0
ion.element = H
Expand Down
4 changes: 2 additions & 2 deletions examples/blowout_wake/inputs_normalized
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ hipace.numprocs_y = 1
hipace.depos_order_xy = 2

geometry.coord_sys = 0 # 0: Cartesian
geometry.is_periodic = 1 1 0 # Is periodic?
geometry.prob_lo = -8. -8. -6 # physical domain
geometry.is_periodic = true true false # Is periodic?
geometry.prob_lo = -8. -8. -6 # physical domain
geometry.prob_hi = 8. 8. 6

beams.names = beam
Expand Down
11 changes: 8 additions & 3 deletions examples/linear_wake/inputs_SI
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
amr.n_cell = 32 32 200

my_constants.kp_inv = 10.e-6
my_constants.kp = 1. / kp_inv
my_constants.wp = clight * kp
my_constants.ne = wp^2 * m_e * epsilon0 / q_e^2

amr.blocking_factor = 2
amr.max_level = 0

Expand All @@ -12,7 +17,7 @@ hipace.numprocs_y = 1
hipace.depos_order_xy = 2

geometry.coord_sys = 0 # 0: Cartesian
geometry.is_periodic = 1 1 0 # Is periodic?
geometry.is_periodic = true true false # Is periodic?
geometry.prob_lo = -100.e-6 -100.e-6 -75.e-6 # physical domain
geometry.prob_hi = 100.e-6 100.e-6 20.e-6

Expand All @@ -22,13 +27,13 @@ beam.profile = flattop
beam.zmin = -10.e-6
beam.zmax = 10.e-6
beam.radius = 30.e-6
beam.density = 2.8239587008591567e21
beam.density = 0.01 * ne
beam.u_mean = 0. 0. 2000
beam.u_std = 0. 0. 0.
beam.ppc = 1 1 1

plasmas.names = plasma
plasma.density = 2.8239587008591567e23 # at this density, 1/kp = 10um
plasma.density = ne
plasma.ppc = 1 1
plasma.u_mean = 0.0 0.0 0.
plasma.element = electron
Expand Down
21 changes: 15 additions & 6 deletions src/Hipace.H
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "utils/AdaptiveTimeStep.H"
#include "utils/GridCurrent.H"
#include "utils/Constants.H"
#include "utils/Parser.H"
#include "diagnostics/Diagnostic.H"
#include "diagnostics/OpenPMDWriter.H"

Expand All @@ -24,8 +25,21 @@

#include <memory>


/** \brief Helper struct to initialize m_phys_const and Parser before amrex::AmrCore */
struct Hipace_early_init
{
/** Constructor of m_phys_const, initialize Hipace::m_instance, Hipace::m_normalized_units
* and Parser Constants */
Hipace_early_init (Hipace* instance);

/** Struct containing physical constants (which values depends on the unit system, determined
* at runtime): SI or normalized units. */
PhysConst m_phys_const;
};

/** \brief Singleton class, that intialize, runs and finalizes the simulation */
class Hipace final : public amrex::AmrCore
class Hipace final : public Hipace_early_init, public amrex::AmrCore
{
public:
/** Ctor: read general input parameters, call constructors of main member variables
Expand Down Expand Up @@ -190,15 +204,10 @@ public:
/** status of the physical time send request */
MPI_Request m_tsend_request = MPI_REQUEST_NULL;

private:
/** Pointer to current (and only) instance of class Hipace */
static Hipace* m_instance;
public:
/** Whether to use normalized units */
static bool m_normalized_units;
/** Struct containing physical constants (which values depends on the unit system, determined
* at runtime): SI or normalized units. */
PhysConst m_phys_const;
/** All field data (3D array, slices) and field methods */
Fields m_fields;
/** Contains all beam species */
Expand Down
79 changes: 43 additions & 36 deletions src/Hipace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ bool Hipace::m_do_tiling = false;
bool Hipace::m_do_tiling = true;
#endif

Hipace_early_init::Hipace_early_init (Hipace* instance)
{
Hipace::m_instance = instance;
amrex::ParmParse pph("hipace");
queryWithParser(pph ,"normalized_units", Hipace::m_normalized_units);
if (Hipace::m_normalized_units) {
m_phys_const = make_constants_normalized();
} else {
m_phys_const = make_constants_SI();
}
Parser::addConstantsToParser(m_phys_const);
Parser::replaceAmrexParamsWithParser();
}

Hipace&
Hipace::GetInstance ()
{
Expand All @@ -59,59 +73,52 @@ Hipace::GetInstance ()
}

Hipace::Hipace () :
m_phys_const([this](){
m_instance = this;
amrex::ParmParse pph("hipace");
pph.query("normalized_units", this->m_normalized_units);
if (this->m_normalized_units){
return make_constants_normalized();
} else {
return make_constants_SI();
}
}()),
Hipace_early_init(this),
MaxThevenet marked this conversation as resolved.
Show resolved Hide resolved
amrex::AmrCore(),
m_fields(this),
m_multi_beam(this),
m_multi_plasma(this),
m_diags(this->maxLevel()+1)
{
amrex::ParmParse pp;// Traditionally, max_step and stop_time do not have prefix.
pp.query("max_step", m_max_step);
queryWithParser(pp, "max_step", m_max_step);

#ifndef AMREX_USE_GPU
int seed;
if (pp.query("random_seed", seed)) amrex::ResetRandomSeed(seed);
if (queryWithParser(pp, "random_seed", seed)) amrex::ResetRandomSeed(seed);
#endif

amrex::ParmParse pph("hipace");
pph.query("dt", m_dt);
pph.query("verbose", m_verbose);
pph.query("numprocs_x", m_numprocs_x);
pph.query("numprocs_y", m_numprocs_y);

queryWithParser(pph, "dt", m_dt);
queryWithParser(pph, "verbose", m_verbose);
queryWithParser(pph, "numprocs_x", m_numprocs_x);
queryWithParser(pph, "numprocs_y", m_numprocs_y);
m_numprocs_z = amrex::ParallelDescriptor::NProcs() / (m_numprocs_x*m_numprocs_y);
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_numprocs_z <= m_max_step+1,
"Please use more or equal time steps than number of ranks");
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_numprocs_x*m_numprocs_y*m_numprocs_z
== amrex::ParallelDescriptor::NProcs(),
"Check hipace.numprocs_x and hipace.numprocs_y");
pph.query("boxes_in_z", m_boxes_in_z);
queryWithParser(pph, "boxes_in_z", m_boxes_in_z);
if (m_boxes_in_z > 1) AMREX_ALWAYS_ASSERT_WITH_MESSAGE( m_numprocs_z == 1,
"Multiple boxes per rank only implemented for one rank.");
pph.query("depos_order_xy", m_depos_order_xy);
pph.query("depos_order_z", m_depos_order_z);
pph.query("predcorr_B_error_tolerance", m_predcorr_B_error_tolerance);
pph.query("predcorr_max_iterations", m_predcorr_max_iterations);
pph.query("predcorr_B_mixing_factor", m_predcorr_B_mixing_factor);
pph.query("output_period", m_output_period);
queryWithParser(pph, "depos_order_xy", m_depos_order_xy);
queryWithParser(pph, "depos_order_z", m_depos_order_z);
queryWithParser(pph, "predcorr_B_error_tolerance", m_predcorr_B_error_tolerance);
queryWithParser(pph, "predcorr_max_iterations", m_predcorr_max_iterations);
queryWithParser(pph, "predcorr_B_mixing_factor", m_predcorr_B_mixing_factor);
queryWithParser(pph, "output_period", m_output_period);
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_output_period != 0,
"To avoid output, please use output_period = -1.");
pph.query("beam_injection_cr", m_beam_injection_cr);
pph.query("do_beam_jx_jy_deposition", m_do_beam_jx_jy_deposition);
pph.query("do_device_synchronize", m_do_device_synchronize);
pph.query("external_ExmBy_slope", m_external_ExmBy_slope);
pph.query("external_Ez_slope", m_external_Ez_slope);
pph.query("external_Ez_uniform", m_external_Ez_uniform);
queryWithParser(pph, "beam_injection_cr", m_beam_injection_cr);
queryWithParser(pph, "do_beam_jx_jy_deposition", m_do_beam_jx_jy_deposition);
queryWithParser(pph, "do_device_synchronize", m_do_device_synchronize);
queryWithParser(pph, "external_ExmBy_slope", m_external_ExmBy_slope);
queryWithParser(pph, "external_Ez_slope", m_external_Ez_slope);
queryWithParser(pph, "external_Ez_uniform", m_external_Ez_uniform);
std::string solver = "predictor-corrector";
pph.query("bxby_solver", solver);
queryWithParser(pph, "bxby_solver", solver);
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(
solver == "predictor-corrector" ||
solver == "explicit",
Expand All @@ -121,9 +128,9 @@ Hipace::Hipace () :
!(m_explicit && !m_multi_plasma.AllSpeciesNeutralizeBackground()),
"Ion motion with explicit solver is not implemented, need to use neutralize_background");

pph.query("MG_tolerance_rel", m_MG_tolerance_rel);
pph.query("MG_tolerance_abs", m_MG_tolerance_abs);
pph.query("do_tiling", m_do_tiling);
queryWithParser(pph, "MG_tolerance_rel", m_MG_tolerance_rel);
queryWithParser(pph, "MG_tolerance_abs", m_MG_tolerance_abs);
queryWithParser(pph, "do_tiling", m_do_tiling);
#ifdef AMREX_USE_GPU
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_do_tiling==0, "Tiling must be turned off to run on GPU.");
#endif
Expand All @@ -133,14 +140,14 @@ Hipace::Hipace () :
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(!m_explicit, "Mesh refinement + explicit solver is not yet"
" supported! Please use hipace.bxby_solver = predictor-corrector");
amrex::Array<amrex::Real, AMREX_SPACEDIM> loc_array;
pph.get("patch_lo", loc_array);
getWithParser(pph, "patch_lo", loc_array);
for (int idim=0; idim<AMREX_SPACEDIM; ++idim) patch_lo[idim] = loc_array[idim];
pph.get("patch_hi", loc_array);
getWithParser(pph, "patch_hi", loc_array);
for (int idim=0; idim<AMREX_SPACEDIM; ++idim) patch_hi[idim] = loc_array[idim];
}

#ifdef AMREX_USE_MPI
pph.query("skip_empty_comms", m_skip_empty_comms);
queryWithParser(pph, "skip_empty_comms", m_skip_empty_comms);
int myproc = amrex::ParallelDescriptor::MyProc();
m_rank_z = myproc/(m_numprocs_x*m_numprocs_y);
MPI_Comm_split(amrex::ParallelDescriptor::Communicator(), m_rank_z, myproc, &m_comm_xy);
Expand Down
10 changes: 5 additions & 5 deletions src/diagnostics/Diagnostic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Diagnostic::Diagnostic (int nlev)
{
amrex::ParmParse ppd("diagnostic");
std::string str_type;
ppd.get("diag_type", str_type);
getWithParser(ppd, "diag_type", str_type);
if (str_type == "xyz"){
m_diag_type = DiagType::xyz;
m_slice_dir = -1;
Expand All @@ -26,7 +26,7 @@ Diagnostic::Diagnostic (int nlev)
for(int ilev = 0; ilev<nlev; ++ilev) {
amrex::Array<int,3> diag_coarsen_arr{1,1,1};
// set all levels the same for now
ppd.query("coarsening", diag_coarsen_arr);
queryWithParser(ppd, "coarsening", diag_coarsen_arr);
if(m_slice_dir == 0 || m_slice_dir == 1) {
diag_coarsen_arr[m_slice_dir] = 1;
}
Expand All @@ -35,7 +35,7 @@ Diagnostic::Diagnostic (int nlev)
"Coarsening ratio must be >= 1");
}

ppd.queryarr("field_data", m_comps_output);
queryWithParser(ppd, "field_data", m_comps_output);
const amrex::Vector<std::string> all_field_comps
{"ExmBy", "EypBx", "Ez", "Bx", "By", "Bz", "jx", "jx_beam", "jy", "jy_beam", "jz",
"jz_beam", "rho", "Psi"};
Expand Down Expand Up @@ -68,9 +68,9 @@ Diagnostic::Diagnostic (int nlev)
amrex::ParmParse ppb("beams");
// read in all beam names
amrex::Vector<std::string> all_beam_names;
ppb.queryarr("names", all_beam_names);
queryWithParser(ppb, "names", all_beam_names);
// read in which beam should be written to file
ppd.queryarr("beam_data", m_output_beam_names);
queryWithParser(ppd, "beam_data", m_output_beam_names);

if(m_output_beam_names.empty()) {
m_output_beam_names = all_beam_names;
Expand Down
6 changes: 3 additions & 3 deletions src/diagnostics/OpenPMDWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ OpenPMDWriter::OpenPMDWriter ()
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_real_names.size() == BeamIdx::nattribs,
"List of real names in openPMD Writer class do not match BeamIdx::nattribs");
amrex::ParmParse pp("hipace");
pp.query("file_prefix", m_file_prefix);
pp.query("openpmd_backend", m_openpmd_backend);
queryWithParser(pp, "file_prefix", m_file_prefix);
queryWithParser(pp, "openpmd_backend", m_openpmd_backend);

// temporary workaround until openPMD-viewer gets fixed
amrex::ParmParse ppd("diagnostic");
ppd.query("openpmd_viewer_u_workaround", m_openpmd_viewer_workaround);
queryWithParser(ppd, "openpmd_viewer_u_workaround", m_openpmd_viewer_workaround);
}

void
Expand Down
2 changes: 1 addition & 1 deletion src/fields/Fields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Fields::Fields (Hipace const* a_hipace)
: m_slices(a_hipace->maxLevel()+1)
{
amrex::ParmParse ppf("fields");
ppf.query("do_dirichlet_poisson", m_do_dirichlet_poisson);
queryWithParser(ppf, "do_dirichlet_poisson", m_do_dirichlet_poisson);
}

void
Expand Down
2 changes: 1 addition & 1 deletion src/fields/fft_poisson_solver/fft/WrapCuDST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ namespace AnyDST

amrex::ParmParse pp("hipace");
dst_plan.use_small_dst = (std::max(real_size[0], real_size[1]) >= 511);
pp.query("use_small_dst", dst_plan.use_small_dst);
queryWithParser(pp, "use_small_dst", dst_plan.use_small_dst);

if(!dst_plan.use_small_dst) {
const int nx = real_size[0];
Expand Down
Loading