Reference documentation for deal.II version 9.3.3
|
#include <deal.II/base/tensor_function_parser.h>
Public Types | |
using | ConstMap = std::map< std::string, double > |
using | value_type = Tensor< rank, dim, double > |
using | gradient_type = Tensor< rank+1, dim, double > |
using | time_type = typename FunctionTime< typename numbers::NumberTraits< double >::real_type >::time_type |
Public Member Functions | |
TensorFunctionParser (const double initial_time=0.0) | |
TensorFunctionParser (const std::string &expression, const std::string &constants="", const std::string &variable_names=default_variable_names()+",t") | |
TensorFunctionParser (const TensorFunctionParser &)=delete | |
TensorFunctionParser (TensorFunctionParser &&)=delete | |
virtual | ~TensorFunctionParser () override |
TensorFunctionParser & | operator= (const TensorFunctionParser &)=delete |
TensorFunctionParser & | operator= (TensorFunctionParser &&)=delete |
void | initialize (const std::string &vars, const std::vector< std::string > &expressions, const ConstMap &constants, const bool time_dependent=false) |
void | initialize (const std::string &vars, const std::string &expression, const ConstMap &constants, const bool time_dependent=false) |
virtual Tensor< rank, dim, Number > | value (const Point< dim > &p) const override |
virtual void | value_list (const std::vector< Point< dim > > &p, std::vector< Tensor< rank, dim, Number > > &values) const override |
const std::vector< std::string > & | get_expressions () const |
virtual void | value_list (const std::vector< Point< dim > > &points, std::vector< value_type > &values) const |
virtual gradient_type | gradient (const Point< dim > &p) const |
virtual void | gradient_list (const std::vector< Point< dim > > &points, std::vector< gradient_type > &gradients) const |
numbers::NumberTraits< double >::real_type | get_time () const |
virtual void | set_time (const numbers::NumberTraits< double >::real_type new_time) |
virtual void | advance_time (const numbers::NumberTraits< double >::real_type delta_t) |
Static Public Member Functions | |
static std::string | default_variable_names () |
static ::ExceptionBase & | ExcParseError (int arg1, std::string arg2) |
static ::ExceptionBase & | ExcInvalidExpressionSize (int arg1, int arg2) |
Private Member Functions | |
void | init_muparser () const |
Private Attributes | |
Threads::ThreadLocalStorage< std::vector< double > > | vars |
Threads::ThreadLocalStorage< std::vector< std::unique_ptr< mu::Parser > > > | tfp |
std::map< std::string, double > | constants |
std::vector< std::string > | var_names |
std::vector< std::string > | expressions |
bool | initialized |
unsigned int | n_vars |
unsigned int | n_components |
numbers::NumberTraits< double >::real_type | time |
Subscriptor functionality | |
Classes derived from Subscriptor provide a facility to subscribe to this object. This is mostly used by the SmartPointer class. | |
std::atomic< unsigned int > | counter |
std::map< std::string, unsigned int > | counter_map |
std::vector< std::atomic< bool > * > | validity_pointers |
const std::type_info * | object_info |
void | subscribe (std::atomic< bool > *const validity, const std::string &identifier="") const |
void | unsubscribe (std::atomic< bool > *const validity, const std::string &identifier="") const |
unsigned int | n_subscriptions () const |
template<typename StreamType > | |
void | list_subscribers (StreamType &stream) const |
void | list_subscribers () const |
template<class Archive > | |
void | serialize (Archive &ar, const unsigned int version) |
static ::ExceptionBase & | ExcInUse (int arg1, std::string arg2, std::string arg3) |
static ::ExceptionBase & | ExcNoSubscriber (std::string arg1, std::string arg2) |
void | check_no_subscribers () const noexcept |
using | map_value_type = decltype(counter_map)::value_type |
using | map_iterator = decltype(counter_map)::iterator |
static std::mutex | mutex |
This class implements a tensor function object that gets its value by parsing a string describing this function. It is a wrapper class for the muparser library (see http://muparser.beltoforion.de/). This class is essentially an extension of the FunctionParser class to read in a TensorFunction. The class reads in an expression of length dimrank (separated by a semicolon) where the components of the tensor function are filled according to the C++ convention (fastest index is the most right one).
A minimal example for the usage of the class would be:
See also the documentation of the FunctionParser class.
This class overloads the virtual method value() and value_list() of the TensorFunction base class with the byte compiled versions of the expressions given to the initialize() methods. Note that the class will not work unless you first call the initialize() method that accepts the text description of the function as an argument (among other things).
The syntax to describe a function follows usual programming practice, and is explained in detail at the homepage of the underlying muparser library at http://muparser.beltoforion.de/ .
Vector-valued functions can either be declared using strings where the function components are separated by semicolons, or using a vector of strings each defining one vector component.
Definition at line 111 of file tensor_function_parser.h.
using TensorFunctionParser< rank, dim, Number >::ConstMap = std::map<std::string, double> |
Type for the constant map. Used by the initialize() method.
Definition at line 169 of file tensor_function_parser.h.
|
inherited |
Alias for the return types of the value
function.
Definition at line 64 of file tensor_function.h.
|
inherited |
Alias for the return types of the gradient
functions.
Definition at line 69 of file tensor_function.h.
|
inherited |
The scalar-valued real type used for representing time.
Definition at line 74 of file tensor_function.h.
TensorFunctionParser< rank, dim, Number >::TensorFunctionParser | ( | const double | initial_time = 0.0 | ) |
Standard constructor. Only set initial time. This object needs to be initialized with the initialize() method before you can use it. If an attempt to use this function is made before the initialize() method has been called, then an exception is thrown.
Definition at line 45 of file tensor_function_parser.cc.
TensorFunctionParser< rank, dim, Number >::TensorFunctionParser | ( | const std::string & | expression, |
const std::string & | constants = "" , |
||
const std::string & | variable_names = default_variable_names() + ",t" |
||
) |
Constructor for parsed functions. This object needs to be initialized with the initialize() method before you can use it. If an attempt to use this function is made before the initialize() method has been called, then an exception is thrown. Takes a semicolon separated list of expressions (one for each component of the tensor function), an optional comma-separated list of constants.
Definition at line 55 of file tensor_function_parser.cc.
|
delete |
Copy constructor. Objects of this type can not be copied, and consequently this constructor is deleted.
|
delete |
Move constructor. Objects of this type can not be moved, and consequently this constructor is deleted.
|
overridevirtualdefault |
Destructor.
|
delete |
Copy operator. Objects of this type can not be copied, and consequently this operator is deleted.
|
delete |
Move operator. Objects of this type can not be moved, and consequently this operator is deleted.
void TensorFunctionParser< rank, dim, Number >::initialize | ( | const std::string & | vars, |
const std::vector< std::string > & | expressions, | ||
const ConstMap & | constants, | ||
const bool | time_dependent = false |
||
) |
Initialize the tensor function. This method accepts the following parameters:
[in] | vars | A string with the variables that will be used by the expressions to be evaluated. Note that the variables can have any name (of course different from the function names defined above!), but the order IS important. The first variable will correspond to the first component of the point in which the function is evaluated, the second variable to the second component and so forth. If this function is also time dependent, then it is necessary to specify it by setting the time_dependent parameter to true. An exception is thrown if the number of variables specified here is different from dim (if this function is not time-dependent) or from dim+1 (if it is time-dependent). |
[in] | expressions | A vector of strings containing the expressions that will be byte compiled by the internal parser (TensorFunctionParser). Note that the size of this vector must match exactly the number of components of the TensorFunctionParser, as declared in the constructor. If this is not the case, an exception is thrown. |
[in] | constants | A map of constants used to pass any necessary constant that we want to specify in our expressions (in the example above the number pi). An expression is valid if and only if it contains only defined variables and defined constants (other than the functions specified above). If a constant is given whose name is not valid (eg: constants["sin"] = 1.5; ) an exception is thrown. |
[in] | time_dependent | If this is a time dependent function, then the last variable declared in vars is assumed to be the time variable, and this->get_time() is used to initialize it when evaluating the function. Naturally the number of variables parsed by the initialize() method in this case is dim+1. The value of this parameter defaults to false, i.e. do not consider time. |
Definition at line 91 of file tensor_function_parser.cc.
void TensorFunctionParser< rank, dim, Number >::initialize | ( | const std::string & | vars, |
const std::string & | expression, | ||
const ConstMap & | constants, | ||
const bool | time_dependent = false |
||
) |
Initialize the function. Same as above, but accepts a string rather than a vector of strings. If this is a vector valued function, its components are expected to be separated by a semicolon. An exception is thrown if this method is called and the number of components successfully parsed does not match the number of components of the base function.
Definition at line 272 of file tensor_function_parser.cc.
|
static |
A function that returns default names for variables, to be used in the first argument of the initialize() functions: it returns "x" in 1d, "x,y" in 2d, and "x,y,z" in 3d.
Definition at line 340 of file tensor_function_parser.h.
|
overridevirtual |
Return the value of the tensor function at the given point.
Reimplemented from TensorFunction< rank, dim, double >.
Definition at line 288 of file tensor_function_parser.cc.
|
overridevirtual |
Return the value of the tensor function at the given point.
Definition at line 333 of file tensor_function_parser.cc.
const std::vector< std::string > & TensorFunctionParser< rank, dim, Number >::get_expressions |
Return an array of function expressions (one per component), used to initialize this function.
Definition at line 37 of file tensor_function_parser.cc.
|
virtualinherited |
Set values
to the point values of the function at the points
. It is assumed that values
already has the right size, i.e. the same size as the points
array.
|
virtualinherited |
Return the gradient of the function at the given point.
Reimplemented in ConstantTensorFunction< rank, dim, Number >, and ConstantTensorFunction< rank, dim, double >.
|
virtualinherited |
Set gradients
to the gradients of the function at the points
. It is assumed that values
already has the right size, i.e. the same size as the points
array.
|
inherited |
Return the value of the time variable.
|
virtualinherited |
Set the time to new_time
, overwriting the old value.
|
virtualinherited |
Advance the time by the given time step delta_t
.
|
privateinherited |
Store the present time.
Definition at line 113 of file function_time.h.