WarpX
Classes | Functions
utils::parser Namespace Reference

Classes

class  SliceParser
 This class is a parser for slices of the form i:j:k where i, j and k are integers representing respectively the starting point, the stopping point and the period. More...
 
class  IntervalsParser
 This class is a parser for multiple slices of the form x,y,z,... where x, y and z are slices of the form i:j:k, as defined in the SliceParser class. This class contains a vector of SliceParsers. More...
 
class  BTDIntervalsParser
 This class is a parser for multiple slices of the form x,y,z,... where x, y and z are slices of the form i:j:k, as defined in the SliceParser class. This class contains a vector of SliceParsers. The supported function set differs from the IntervalsParser. More...
 

Functions

int safeCastToInt (amrex::Real x, const std::string &real_name)
 Do a safe cast of a real to an int This ensures that the float value is within the range of ints and if not, raises an exception. More...
 
long safeCastToLong (amrex::Real x, const std::string &real_name)
 Do a safe cast of a real to a long This ensures that the float value is within the range of longs and if not, raises an exception. More...
 
amrex::Parser makeParser (std::string const &parse_function, amrex::Vector< std::string > const &varnames)
 Initialize an amrex::Parser object from a string containing a math expression. More...
 
void Store_parserString (amrex::ParmParse const &pp, std::string const &query_string, std::string &stored_string)
 Parse a string (typically a mathematical expression) from the input file and store it into a variable. More...
 
void Store_parserString (const amrex::ParmParse &pp, std::string const &group, std::string const &query_string, std::string &stored_string)
 Parse a string (typically a mathematical expression) from the input file and store it into a variable. The group name specified is optional part of the parameter name. A parameter that includes the group name takes precedence over one without the group name. If this routine is called like get(pp, "group", "name", val), it will query both "group.name" or "name" and return the value of "group.name" if found, otherwise the value of "name". More...
 
double parseStringtoDouble (const std::string &str)
 
int parseStringtoInt (const std::string &str, const std::string &name)
 
template<int N>
amrex::ParserExecutor< N > compileParser (amrex::Parser const *parser)
 
template<typename T >
int queryWithParser (const amrex::ParmParse &a_pp, char const *const str, T &val)
 
template<typename T >
int queryArrWithParser (const amrex::ParmParse &a_pp, char const *const str, std::vector< T > &val)
 
template<typename T >
int queryArrWithParser (const amrex::ParmParse &a_pp, char const *const str, std::vector< T > &val, const int start_ix, const int num_val)
 
template<typename T >
void getWithParser (const amrex::ParmParse &a_pp, char const *const str, T &val)
 
template<typename T >
void getArrWithParser (const amrex::ParmParse &a_pp, char const *const str, std::vector< T > &val)
 
template<typename T >
void getArrWithParser (const amrex::ParmParse &a_pp, char const *const str, std::vector< T > &val, const int start_ix, const int num_val)
 
template<typename T >
int queryWithParser (const amrex::ParmParse &a_pp, std::string const &group, char const *const str, T &val)
 
template<typename T >
int queryArrWithParser (const amrex::ParmParse &a_pp, std::string const &group, char const *const str, std::vector< T > &val)
 
template<typename T >
int queryArrWithParser (const amrex::ParmParse &a_pp, std::string const &group, char const *const str, std::vector< T > &val, const int start_ix, const int num_val)
 
int query (const amrex::ParmParse &a_pp, std::string const &group, char const *str, std::string &val)
 
template<typename T >
void getWithParser (const amrex::ParmParse &a_pp, std::string const &group, char const *const str, T &val)
 
template<typename T >
void getArrWithParser (const amrex::ParmParse &a_pp, std::string const &group, char const *const str, std::vector< T > &val)
 
template<typename T >
void getArrWithParser (const amrex::ParmParse &a_pp, std::string const &group, char const *const str, std::vector< T > &val, const int start_ix, const int num_val)
 
void get (amrex::ParmParse const &a_pp, std::string const &group, char const *str, std::string &val)
 

Function Documentation

◆ compileParser()

template<int N>
amrex::ParserExecutor<N> utils::parser::compileParser ( amrex::Parser const *  parser)

◆ get()

void utils::parser::get ( amrex::ParmParse const &  a_pp,
std::string const &  group,
char const *  str,
std::string &  val 
)

Wraps around amrex::ParmParse::get, but also supports an option group name

The group name specified is optional part of the parameter name. A parameter that includes the group name takes precedence over one without the group name. If this routine is called like get(pp, "group", "name", val), it will query both "group.name" or "name" and return the value of "group.name" if found, otherwise the value of "name".

Parameters
[in]a_ppamrex::ParmParse object
[in]groupname of the optional group
[in]strname of the parameter to read
[out]valwhere the value queried and parsed is stored

◆ getArrWithParser() [1/4]

template<typename T >
void utils::parser::getArrWithParser ( const amrex::ParmParse a_pp,
char const *const  str,
std::vector< T > &  val 
)

◆ getArrWithParser() [2/4]

template<typename T >
void utils::parser::getArrWithParser ( const amrex::ParmParse a_pp,
char const *const  str,
std::vector< T > &  val,
const int  start_ix,
const int  num_val 
)

Similar to amrex::ParmParse::get, but also supports math expressions for the value.

amrex::ParmParse::get reads a name and a value from the input file. This function does the same, and applies the Parser to the value, so the user has the choice to specify a value or a math expression (including user-defined constants). Works for amrex::Real numbers and integers.

Parameters
[in]a_ppamrex::ParmParse object
[in]strname of the parameter to read
[out]valwhere the value queried and parsed is stored
[in]start_ixstart index in the list of inputs values (optional with arrays, default is amrex::ParmParse::FIRST for starting with the first input value)
[in]num_valnumber of input values to use (optional with arrays, default is amrex::ParmParse::LAST for reading until the last input value)

◆ getArrWithParser() [3/4]

template<typename T >
void utils::parser::getArrWithParser ( const amrex::ParmParse a_pp,
std::string const &  group,
char const *const  str,
std::vector< T > &  val 
)

◆ getArrWithParser() [4/4]

template<typename T >
void utils::parser::getArrWithParser ( const amrex::ParmParse a_pp,
std::string const &  group,
char const *const  str,
std::vector< T > &  val,
const int  start_ix,
const int  num_val 
)

Similar to amrex::ParmParse::get, but also supports math expressions for the value.

amrex::ParmParse::get reads a name and a value from the input file. This function does the same, and applies the Parser to the value, so the user has the choice to specify a value or a math expression (including user-defined constants). Works for amrex::Real numbers and integers. The group name specified is optional part of the parameter name. A parameter that includes the group name takes precedence over one without the group name. If this routine is called like getArrWithParser(pp, "group", "name", val, start_ix, num_val), it will query both "group.name" or "name" and return the value of "group.name" if found, otherwise the value of "name".

Parameters
[in]a_ppamrex::ParmParse object
[in]groupname of the optional group
[in]strname of the parameter to read
[out]valwhere the value queried and parsed is stored
[in]start_ixstart index in the list of inputs values (optional with arrays, default is amrex::ParmParse::FIRST for starting with the first input value)
[in]num_valnumber of input values to use (optional with arrays, default is amrex::ParmParse::LAST for reading until the last input value)

◆ getWithParser() [1/2]

template<typename T >
void utils::parser::getWithParser ( const amrex::ParmParse a_pp,
char const *const  str,
T &  val 
)

Similar to amrex::ParmParse::get, but also supports math expressions for the value.

amrex::ParmParse::get reads a name and a value from the input file. This function does the same, and applies the Parser to the value, so the user has the choice to specify a value or a math expression (including user-defined constants). Works for amrex::Real numbers and integers.

Parameters
[in]a_ppamrex::ParmParse object
[in]strname of the parameter to read
[out]valwhere the value queried and parsed is stored

◆ getWithParser() [2/2]

template<typename T >
void utils::parser::getWithParser ( const amrex::ParmParse a_pp,
std::string const &  group,
char const *const  str,
T &  val 
)

Similar to amrex::ParmParse::get, but also supports math expressions for the value.

amrex::ParmParse::get reads a name and a value from the input file. This function does the same, and applies the Parser to the value, so the user has the choice to specify a value or a math expression (including user-defined constants). Works for amrex::Real numbers and integers. The group name specified is optional part of the parameter name. A parameter that includes the group name takes precedence over one without the group name. If this routine is called like getWithParser(pp, "group", "name", val), it will query both "group.name" or "name" and return the value of "group.name" if found, otherwise the value of "name".

Parameters
[in]a_ppamrex::ParmParse object
[in]groupname of the optional group
[in]strname of the parameter to read
[out]valwhere the value queried and parsed is stored

◆ makeParser()

amrex::Parser utils::parser::makeParser ( std::string const &  parse_function,
amrex::Vector< std::string > const &  varnames 
)

Initialize an amrex::Parser object from a string containing a math expression.

Parameters
parse_functionString to read to initialize the parser.
varnamesA list of predefined independent variables

◆ parseStringtoDouble()

double utils::parser::parseStringtoDouble ( const std::string &  str)

Parse a string and return as a double precision floating point number

In case the string cannot be interpreted as a double, this function ... <throws an exception? aborts with error message?>

Parameters
strThe string to be parsed
Returns
representation as a double

◆ parseStringtoInt()

int utils::parser::parseStringtoInt ( const std::string &  str,
const std::string &  name 
)

Parse a string and return an int

In case the string cannot be interpreted as Real, this function ... <throws an exception? aborts with error message?>

Parameters
strThe string to be parsed
nameFor integers, the name, to be used in error messages
Returns
rounded closest integer

◆ query()

int utils::parser::query ( const amrex::ParmParse a_pp,
std::string const &  group,
char const *  str,
std::string &  val 
)

Wraps around amrex::ParmParse::query, but also supports an option group name

The group name specified is optional part of the parameter name. A parameter that includes the group name takes precedence over one without the group name. If this routine is called like get(pp, "group", "name", val), it will query both "group.name" or "name" and return the value of "group.name" if found, otherwise the value of "name".

Parameters
[in]a_ppamrex::ParmParse object
[in]groupname of the optional group
[in]strname of the parameter to read
[out]valwhere the value queried and parsed is stored

◆ queryArrWithParser() [1/4]

template<typename T >
int utils::parser::queryArrWithParser ( const amrex::ParmParse a_pp,
char const *const  str,
std::vector< T > &  val 
)

◆ queryArrWithParser() [2/4]

template<typename T >
int utils::parser::queryArrWithParser ( const amrex::ParmParse a_pp,
char const *const  str,
std::vector< T > &  val,
const int  start_ix,
const int  num_val 
)

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 amrex::Parser to the value, so the user has the choice to specify a value or a math expression (including user-defined constants). Works for amrex::Real numbers and integers.

Parameters
[in]a_ppamrex::ParmParse object
[in]strname of the parameter to read
[out]valwhere the value queried and parsed is stored, either a scalar or vector
[in]start_ixstart index in the list of inputs values (optional with arrays, default is amrex::ParmParse::FIRST for starting with the first input value)
[in]num_valnumber of input values to use (optional with arrays, default is amrex::ParmParse::LAST for reading until the last input value)

◆ queryArrWithParser() [3/4]

template<typename T >
int utils::parser::queryArrWithParser ( const amrex::ParmParse a_pp,
std::string const &  group,
char const *const  str,
std::vector< T > &  val 
)

◆ queryArrWithParser() [4/4]

template<typename T >
int utils::parser::queryArrWithParser ( const amrex::ParmParse a_pp,
std::string const &  group,
char const *const  str,
std::vector< T > &  val,
const int  start_ix,
const int  num_val 
)

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 amrex::Parser to the value, so the user has the choice to specify a value or a math expression (including user-defined constants). Works for amrex::Real numbers and integers. The group name specified is optional part of the parameter name. A parameter that includes the group name takes precedence over one without the group name. If this routine is called like queryArrWithParser(pp, "group", "name", val, start_ix, num_val), it will query both "group.name" or "name" and return the value of "group.name" if found, otherwise the value of "name".

Parameters
[in]a_ppamrex::ParmParse object
[in]groupname of the optional group
[in]strname of the parameter to read
[out]valwhere the value queried and parsed is stored, either a scalar or vector
[in]start_ixstart index in the list of inputs values (optional with arrays, default is amrex::ParmParse::FIRST for starting with the first input value)
[in]num_valnumber of input values to use (optional with arrays, default is amrex::ParmParse::LAST for reading until the last input value)

◆ queryWithParser() [1/2]

template<typename T >
int utils::parser::queryWithParser ( const amrex::ParmParse a_pp,
char const *const  str,
T &  val 
)

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 amrex::Parser to the value, so the user has the choice to specify a value or a math expression (including user-defined constants). Works for amrex::Real numbers and integers.

Parameters
[in]a_ppamrex::ParmParse object
[in]strname of the parameter to read
[out]valwhere the value queried and parsed is stored, either a scalar or vector

◆ queryWithParser() [2/2]

template<typename T >
int utils::parser::queryWithParser ( const amrex::ParmParse a_pp,
std::string const &  group,
char const *const  str,
T &  val 
)

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 amrex::Parser to the value, so the user has the choice to specify a value or a math expression (including user-defined constants). Works for amrex::Real numbers and integers. The group name specified is optional part of the parameter name. A parameter that includes the group name takes precedence over one without the group name. If this routine is called like queryWithParser(pp, "group", "name", val), it will query both "group.name" or "name" and return the value of "group.name" if found, otherwise the value of "name".

Parameters
[in]a_ppamrex::ParmParse object
[in]groupname of the optional group
[in]strname of the parameter to read
[out]valwhere the value queried and parsed is stored, either a scalar or vector

◆ safeCastToInt()

int utils::parser::safeCastToInt ( amrex::Real  x,
const std::string &  real_name 
)

Do a safe cast of a real to an int This ensures that the float value is within the range of ints and if not, raises an exception.

Parameters
xReal value to cast
real_nameString, the name of the variable being casted to use in the error message

◆ safeCastToLong()

long utils::parser::safeCastToLong ( amrex::Real  x,
const std::string &  real_name 
)

Do a safe cast of a real to a long This ensures that the float value is within the range of longs and if not, raises an exception.

Parameters
xReal value to cast
real_nameString, the name of the variable being casted to use in the error message

◆ Store_parserString() [1/2]

void utils::parser::Store_parserString ( amrex::ParmParse const &  pp,
std::string const &  query_string,
std::string &  stored_string 
)

Parse a string (typically a mathematical expression) from the input file and store it into a variable.

Parameters
ppused to read the query_string pp.<function>=string
query_stringParmParse.query will look for this string
stored_stringvariable in which the string to parse is stored

◆ Store_parserString() [2/2]

void utils::parser::Store_parserString ( const amrex::ParmParse pp,
std::string const &  group,
std::string const &  query_string,
std::string &  stored_string 
)

Parse a string (typically a mathematical expression) from the input file and store it into a variable. The group name specified is optional part of the parameter name. A parameter that includes the group name takes precedence over one without the group name. If this routine is called like get(pp, "group", "name", val), it will query both "group.name" or "name" and return the value of "group.name" if found, otherwise the value of "name".

Parameters
[in]ppused to read the query_string pp.<function>=string
[in]groupname of the optional group
[in]query_stringParmParse.query will look for this string
[out]stored_stringvariable in which the string to parse is stored