diff options
author | 2020-11-03 18:51:04 +0100 | |
---|---|---|
committer | 2020-11-03 09:51:04 -0800 | |
commit | e684a52a2adf3354d0060f7a6de44ded9f90a283 (patch) | |
tree | 9448802896948736aa0d88dd472a1b02b3ad01fd /Source/Utils/WarpXUtil.cpp | |
parent | 5378486783db866dffe8fd77d5bf01b50b5177ed (diff) | |
download | WarpX-e684a52a2adf3354d0060f7a6de44ded9f90a283.tar.gz WarpX-e684a52a2adf3354d0060f7a6de44ded9f90a283.tar.zst WarpX-e684a52a2adf3354d0060f7a6de44ded9f90a283.zip |
Use the parser for more input parameters (#1481)
* option to smart-query input arguments using the parser
* modify one example to illustrate
* cleaner naming
* cleaner call to the parser, no need to go through a pointer
* better naming and more doc for queryWithParser
* update the documentation
Diffstat (limited to '')
-rw-r--r-- | Source/Utils/WarpXUtil.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
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 |