diff options
Diffstat (limited to 'Source/Utils')
-rw-r--r-- | Source/Utils/WarpXUtil.H | 14 | ||||
-rw-r--r-- | Source/Utils/WarpXUtil.cpp | 20 |
2 files changed, 33 insertions, 1 deletions
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 |