diff options
author | 2020-12-02 09:43:11 +0100 | |
---|---|---|
committer | 2020-12-02 00:43:11 -0800 | |
commit | 2fbb92dca17e624c6d3c4f51caa412a585b10c32 (patch) | |
tree | c6b5e4534e65d0cb487061e6108419a7d4fe23a1 /Source/Utils/WarpXUtil.cpp | |
parent | 330c6c56ea64a3f4183483f529e66f59aff8f92d (diff) | |
download | WarpX-2fbb92dca17e624c6d3c4f51caa412a585b10c32.tar.gz WarpX-2fbb92dca17e624c6d3c4f51caa412a585b10c32.tar.zst WarpX-2fbb92dca17e624c6d3c4f51caa412a585b10c32.zip |
More parser-enabled ParmParse.query and ParmParse.get (#1501)
* Parser can be used for most input parameters, including charge and mass
* update documentation for the math parser
* eol
* remove typo and update doc for parser
* Apply suggestions from code review
Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja>
Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja>
Diffstat (limited to 'Source/Utils/WarpXUtil.cpp')
-rw-r--r-- | Source/Utils/WarpXUtil.cpp | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/Source/Utils/WarpXUtil.cpp b/Source/Utils/WarpXUtil.cpp index 4372c132e..7b66b416e 100644 --- a/Source/Utils/WarpXUtil.cpp +++ b/Source/Utils/WarpXUtil.cpp @@ -21,7 +21,7 @@ void ReadBoostedFrameParameters(Real& gamma_boost, Real& beta_boost, Vector<int>& boost_direction) { ParmParse pp("warpx"); - pp.query("gamma_boost", gamma_boost); + queryWithParser(pp, "gamma_boost", gamma_boost); if( gamma_boost > 1. ) { beta_boost = std::sqrt(1.-1./pow(gamma_boost,2)); std::string s; @@ -178,7 +178,7 @@ namespace WarpXUtilIO{ } } -void Store_parserString(amrex::ParmParse& pp, std::string query_string, +void Store_parserString(const amrex::ParmParse& pp, std::string query_string, std::string& stored_string) { std::vector<std::string> f; @@ -200,10 +200,28 @@ WarpXParser makeParser (std::string const& parse_function, std::vector<std::stri for (auto it = symbols.begin(); it != symbols.end(); ) { Real v; if (pp.query(it->c_str(), v)) { - parser.setConstant(*it, v); - it = symbols.erase(it); + parser.setConstant(*it, v); + it = symbols.erase(it); + } else if (std::strcmp(it->c_str(), "q_e") == 0) { + parser.setConstant(*it, PhysConst::q_e); + it = symbols.erase(it); + } else if (std::strcmp(it->c_str(), "m_e") == 0) { + parser.setConstant(*it, PhysConst::m_e); + it = symbols.erase(it); + } else if (std::strcmp(it->c_str(), "m_p") == 0) { + parser.setConstant(*it, PhysConst::m_p); + it = symbols.erase(it); + } else if (std::strcmp(it->c_str(), "epsilon0") == 0) { + parser.setConstant(*it, PhysConst::ep0); + it = symbols.erase(it); + } else if (std::strcmp(it->c_str(), "clight") == 0) { + parser.setConstant(*it, PhysConst::c); + it = symbols.erase(it); + } else if (std::strcmp(it->c_str(), "pi") == 0) { + parser.setConstant(*it, MathConst::pi); + it = symbols.erase(it); } else { - ++it; + ++it; } } for (auto const& s : symbols) { @@ -213,7 +231,7 @@ WarpXParser makeParser (std::string const& parse_function, std::vector<std::stri } int -queryWithParser (amrex::ParmParse& a_pp, char const * const str, amrex::Real& val) +queryWithParser (const 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; @@ -231,6 +249,17 @@ queryWithParser (amrex::ParmParse& a_pp, char const * const str, amrex::Real& va return is_specified; } +void +getWithParser (const amrex::ParmParse& a_pp, char const * const str, amrex::Real& val) +{ + // 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(); +} + /** * \brief Ensures that the blocks are setup correctly for the RZ spectral solver * When using the RZ spectral solver, the Hankel transform cannot be @@ -345,4 +374,3 @@ namespace WarpXUtilStr } } - |