| FEAT 3
    Finite Element Analysis Toolbox | 
Parsed scalar function implementation. More...
#include <parsed_function.hpp>
 
  
| Classes | |
| class | Evaluator | 
| Public Types | |
| typedef Analytic::Image::Scalar | ImageType | 
| This function is always scalar.  More... | |
| Public Member Functions | |
| ParsedScalarFunction () | |
| Standard constructor.  More... | |
| ParsedScalarFunction (const String &function) | |
| Constructor.  More... | |
| void | add_constant (const String &name, double value) | 
| Adds a constant to the parser.  More... | |
| void | add_variable (const String &name, double value=0.0) | 
| Adds an extra variable to the parser.  More... | |
| void | parse (const String &function) | 
| Parses a function.  More... | |
| void | set_variable (const String &name, double value) | 
| Sets the value of an extra variable.  More... | |
| Static Public Attributes | |
| static constexpr bool | can_grad = false | 
| we cannot compute gradients  More... | |
| static constexpr bool | can_hess = false | 
| we cannot compute hessians  More... | |
| static constexpr bool | can_value = true | 
| we can compute function values  More... | |
| static constexpr int | domain_dim = dim_ | 
| validate our dimension  More... | |
| Private Attributes | |
| std::map< String, double > | _extra_vars | 
| our extra variable names  More... | |
| ::FunctionParser | _parser | 
| the actual function parser object  More... | |
Parsed scalar function implementation.
This class provides an implementation of the Analytic::Function interface which can parse and evaluate a formula in the up to three variables 'x', 'y' and 'z' as well as user-defined extra variables given as a string at runtime.
fparser third-party library, which is used for the actual parsing and evaluation.For a full documentation and a list of supported expressions, see the documentation of the underlying parser at the page Syntax overview of ParsedScalar/VectorFunction.
There are two possibilities how to create an instance of this class: If you have a 'simple' function without any symbolic constants, you can use the constructor which takes the function string as a single parameter.
If your function requires additional (problem specific) constants (e.g. Reynolds number), you first need to create an instance of this class by using the standard constructor, then add all your required constants by using the add_constant function and finally parse your function string by calling the parse function.
This class already offers the following pre-defined constants:
pi = 3.14159...eps = ~1E-16| dim_ | The dimension of the function, i.e. the number of variables. Must be 1 <= dim_ <= 3. | 
Note to Implementers:
The FunctionParser class, which is defined by the 'fparser' library, is actually just a typedef for the template class instance FunctionParserBase<double>. This may lead the reader to the (erroneous) conclusion, that one might easily templatize this ParsedFunction class in the datatype, thus adding support for other interesting floating point types like the __float128 type of GCC's libquadmath. Unfortunately, most of the auxiliary function templates implemented in the depths of the 'fparser' library are only specialized for the common build-in types without offering any generic implementation. Therefore, trying to use the FunctionParserBase class template with a somewhat interesting type like __float128 is unfortunately doomed to end in linker errors :(
Definition at line 102 of file parsed_function.hpp.
| typedef Analytic::Image::Scalar FEAT::Analytic::ParsedScalarFunction< dim_ >::ImageType | 
This function is always scalar.
Definition at line 113 of file parsed_function.hpp.
| 
 | inlineexplicit | 
Standard constructor.
This constructor adds the following constants to the underlying parser:
pi = 3.14159...eps = ~1E-16 Definition at line 138 of file parsed_function.hpp.
References FEAT::Analytic::ParsedScalarFunction< dim_ >::_parser.
| 
 | inlineexplicit | 
Constructor.
This constructor creates a parsed function from a String.
| [in] | function | The expression that defines the function in the variables x,y, andz. | 
| ParsedFunctionParseError | An instance of the ParsedFunctionParseError exception is thrown if the fparser library fails to parse the formula. The message of the exception contains more information on the cause of the error and should be presented the user in an appropriate way. | 
Definition at line 161 of file parsed_function.hpp.
References FEAT::Analytic::ParsedScalarFunction< dim_ >::parse().
| 
 | inline | 
Adds a constant to the parser.
| [in] | name | The name of the constant. | 
| [in] | value | The value of the constant. | 
Definition at line 176 of file parsed_function.hpp.
References FEAT::Analytic::ParsedScalarFunction< dim_ >::_parser, and FEAT::value.
| 
 | inline | 
Adds an extra variable to the parser.
The value of the extra variable can be changed later on by using the set_variable function.
| [in] | name | The name of the variable. Must not be 'x', 'y' or 'z'. | 
| [in] | value | The value for the extra variable. | 
Definition at line 192 of file parsed_function.hpp.
References FEAT::Analytic::ParsedScalarFunction< dim_ >::_extra_vars, FEAT::String::compare_no_case(), FEAT::value, and XASSERTM.
| 
 | inline | 
Parses a function.
| [in] | function | The expression that defines the function in the variables x,y, andz. | 
| ParsedFunctionParseError | An instance of the ParsedFunctionParseError exception is thrown if the fparser library fails to parse the formula. The message of the exception contains more information on the cause of the error and should be presented the user in an appropriate way. | 
Definition at line 229 of file parsed_function.hpp.
References FEAT::Analytic::ParsedScalarFunction< dim_ >::_extra_vars, and FEAT::Analytic::ParsedScalarFunction< dim_ >::_parser.
Referenced by FEAT::Analytic::ParsedScalarFunction< dim_ >::ParsedScalarFunction().
| 
 | inline | 
Sets the value of an extra variable.
| [in] | name | The name of the variable. Must have been added by using the add_variable function. | 
| [in] | value | The value for the extra variable. | 
Definition at line 210 of file parsed_function.hpp.
References FEAT::Analytic::ParsedScalarFunction< dim_ >::_extra_vars, FEAT::value, and XASSERTM.
| 
 | private | 
our extra variable names
Definition at line 128 of file parsed_function.hpp.
Referenced by FEAT::Analytic::ParsedScalarFunction< dim_ >::add_variable(), FEAT::Analytic::ParsedScalarFunction< dim_ >::parse(), and FEAT::Analytic::ParsedScalarFunction< dim_ >::set_variable().
| 
 | private | 
the actual function parser object
Definition at line 126 of file parsed_function.hpp.
Referenced by FEAT::Analytic::ParsedScalarFunction< dim_ >::ParsedScalarFunction(), FEAT::Analytic::ParsedScalarFunction< dim_ >::add_constant(), and FEAT::Analytic::ParsedScalarFunction< dim_ >::parse().
| 
 | staticconstexpr | 
we cannot compute gradients
Definition at line 119 of file parsed_function.hpp.
| 
 | staticconstexpr | 
we cannot compute hessians
Definition at line 122 of file parsed_function.hpp.
| 
 | staticconstexpr | 
we can compute function values
Definition at line 116 of file parsed_function.hpp.
| 
 | staticconstexpr | 
validate our dimension
specify our domain dimension
Definition at line 110 of file parsed_function.hpp.