aboutsummaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/Initialization/PlasmaInjector.cpp18
-rw-r--r--Source/Utils/WarpXUtil.H14
-rw-r--r--Source/Utils/WarpXUtil.cpp20
3 files changed, 42 insertions, 10 deletions
diff --git a/Source/Initialization/PlasmaInjector.cpp b/Source/Initialization/PlasmaInjector.cpp
index 69aefc47e..2fbc7ad19 100644
--- a/Source/Initialization/PlasmaInjector.cpp
+++ b/Source/Initialization/PlasmaInjector.cpp
@@ -120,15 +120,15 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name)
}
# endif
- pp.query("xmin", xmin);
- pp.query("ymin", ymin);
- pp.query("zmin", zmin);
- pp.query("xmax", xmax);
- pp.query("ymax", ymax);
- pp.query("zmax", zmax);
-
- pp.query("density_min", density_min);
- pp.query("density_max", density_max);
+ queryWithParser(pp, "xmin", xmin);
+ queryWithParser(pp, "ymin", ymin);
+ queryWithParser(pp, "zmin", zmin);
+ queryWithParser(pp, "xmax", xmax);
+ queryWithParser(pp, "ymax", ymax);
+ queryWithParser(pp, "zmax", zmax);
+
+ queryWithParser(pp, "density_min", density_min);
+ queryWithParser(pp, "density_max", density_max);
std::string physical_species_s;
bool species_is_specified = pp.query("species_type", physical_species_s);
diff --git a/Source/Utils/WarpXUtil.H b/Source/Utils/WarpXUtil.H
index d3682be2f..e5a01a44a 100644
--- a/Source/Utils/WarpXUtil.H
+++ b/Source/Utils/WarpXUtil.H
@@ -161,6 +161,20 @@ T trilinear_interp(T x0, T x1,T y0, T y1, T z0, T z1,
*/
WarpXParser makeParser (std::string const& parse_function, std::vector<std::string> const& varnames);
+/**
+ * \brief Similar to amrex::ParmParse::query, but also supports math expressions for the value.
+ *
+ * amrex::ParmParse::query reads a name and a value from the input file. This function does the
+ * same, and applies the WarpXParser to the value, so the user has the choice to specify a value or
+ * a math expression (including user-defined constants).
+ * Only works for amrex::Real numbers, one would need another version for integers etc.
+ *
+ * \param[in] a_pp amrex::ParmParse object
+ * \param[in] str name of the parameter to read
+ * \param[out] val where the value queried and parsed is stored
+ */
+int queryWithParser (amrex::ParmParse& a_pp, char const * const str, amrex::Real& val);
+
namespace WarpXUtilMsg{
/** \brief If is_expression_true is false, this function prints msg and calls amrex::abort()
diff --git a/Source/Utils/WarpXUtil.cpp b/Source/Utils/WarpXUtil.cpp
index 7a584f6e1..4372c132e 100644
--- a/Source/Utils/WarpXUtil.cpp
+++ b/Source/Utils/WarpXUtil.cpp
@@ -190,7 +190,6 @@ void Store_parserString(amrex::ParmParse& pp, std::string query_string,
f.clear();
}
-
WarpXParser makeParser (std::string const& parse_function, std::vector<std::string> const& varnames)
{
WarpXParser parser(parse_function);
@@ -213,6 +212,25 @@ WarpXParser makeParser (std::string const& parse_function, std::vector<std::stri
return parser;
}
+int
+queryWithParser (amrex::ParmParse& a_pp, char const * const str, amrex::Real& val)
+{
+ // call amrex::ParmParse::query, check if the user specified str.
+ std::string tmp_str;
+ int is_specified = a_pp.query(str, tmp_str);
+ if (is_specified)
+ {
+ // If so, create a parser object and apply it to the value provided by the user.
+ std::string str_val;
+ Store_parserString(a_pp, str, str_val);
+
+ auto parser = makeParser(str_val, {});
+ val = parser.eval();
+ }
+ // return the same output as amrex::ParmParse::query
+ return is_specified;
+}
+
/**
* \brief Ensures that the blocks are setup correctly for the RZ spectral solver
* When using the RZ spectral solver, the Hankel transform cannot be