FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
FEAT::Analytic::ParsedScalarFunction< dim_ > Class Template Reference

Parsed scalar function implementation. More...

#include <parsed_function.hpp>

Inheritance diagram for FEAT::Analytic::ParsedScalarFunction< dim_ >:
FEAT::Analytic::Function

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...
 

Detailed Description

template<int dim_>
class FEAT::Analytic::ParsedScalarFunction< dim_ >

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.

Attention
This class is only available if FEAT is configured and build with support for the 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
Template Parameters
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 :(

Author
Peter Zajac

Definition at line 102 of file parsed_function.hpp.

Member Typedef Documentation

◆ ImageType

template<int dim_>
typedef Analytic::Image::Scalar FEAT::Analytic::ParsedScalarFunction< dim_ >::ImageType

This function is always scalar.

Definition at line 113 of file parsed_function.hpp.

Constructor & Destructor Documentation

◆ ParsedScalarFunction() [1/2]

template<int dim_>
FEAT::Analytic::ParsedScalarFunction< dim_ >::ParsedScalarFunction ( )
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.

◆ ParsedScalarFunction() [2/2]

template<int dim_>
FEAT::Analytic::ParsedScalarFunction< dim_ >::ParsedScalarFunction ( const String function)
inlineexplicit

Constructor.

This constructor creates a parsed function from a String.

Parameters
[in]functionThe expression that defines the function in the variables x, y, and z.
Exceptions
ParsedFunctionParseErrorAn 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().

Member Function Documentation

◆ add_constant()

template<int dim_>
void FEAT::Analytic::ParsedScalarFunction< dim_ >::add_constant ( const String name,
double  value 
)
inline

Adds a constant to the parser.

Parameters
[in]nameThe name of the constant.
[in]valueThe value of the constant.

Definition at line 176 of file parsed_function.hpp.

References FEAT::Analytic::ParsedScalarFunction< dim_ >::_parser, and FEAT::value.

◆ add_variable()

template<int dim_>
void FEAT::Analytic::ParsedScalarFunction< dim_ >::add_variable ( const String name,
double  value = 0.0 
)
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.

Parameters
[in]nameThe name of the variable. Must not be 'x', 'y' or 'z'.
[in]valueThe 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.

◆ parse()

template<int dim_>
void FEAT::Analytic::ParsedScalarFunction< dim_ >::parse ( const String function)
inline

Parses a function.

Parameters
[in]functionThe expression that defines the function in the variables x, y, and z.
Exceptions
ParsedFunctionParseErrorAn 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().

◆ set_variable()

template<int dim_>
void FEAT::Analytic::ParsedScalarFunction< dim_ >::set_variable ( const String name,
double  value 
)
inline

Sets the value of an extra variable.

Parameters
[in]nameThe name of the variable. Must have been added by using the add_variable function.
[in]valueThe 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.

Member Data Documentation

◆ _extra_vars

◆ _parser

◆ can_grad

template<int dim_>
constexpr bool FEAT::Analytic::ParsedScalarFunction< dim_ >::can_grad = false
staticconstexpr

we cannot compute gradients

Definition at line 119 of file parsed_function.hpp.

◆ can_hess

template<int dim_>
constexpr bool FEAT::Analytic::ParsedScalarFunction< dim_ >::can_hess = false
staticconstexpr

we cannot compute hessians

Definition at line 122 of file parsed_function.hpp.

◆ can_value

template<int dim_>
constexpr bool FEAT::Analytic::ParsedScalarFunction< dim_ >::can_value = true
staticconstexpr

we can compute function values

Definition at line 116 of file parsed_function.hpp.

◆ domain_dim

template<int dim_>
constexpr int FEAT::Analytic::ParsedScalarFunction< dim_ >::domain_dim = dim_
staticconstexpr

validate our dimension

specify our domain dimension

Definition at line 110 of file parsed_function.hpp.


The documentation for this class was generated from the following file: