OGS
ParameterLib::FunctionParameter< T > Struct Template Referencefinal

Detailed Description

template<typename T>
struct ParameterLib::FunctionParameter< T >

A parameter class evaluating functions defined by user-provided mathematical expressions.

Currently, x, y, z, and t are supported as variables of the functions.

Definition at line 22 of file FunctionParameter.h.

#include <FunctionParameter.h>

Inheritance diagram for ParameterLib::FunctionParameter< T >:
[legend]
Collaboration diagram for ParameterLib::FunctionParameter< T >:
[legend]

Classes

class  CurveWrapper

Public Types

using symbol_table_t = exprtk::symbol_table<T>
using expression_t = exprtk::expression<T>
using parser_t = exprtk::parser<T>

Public Member Functions

 FunctionParameter (std::string const &name, std::vector< std::string > const &vec_expression_str, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const &curves)
bool isTimeDependent () const override
int getNumberOfGlobalComponents () const override
std::vector< T > operator() (double const t, SpatialPosition const &pos) const override
 Returns the parameter value at the given time and position.
Public Member Functions inherited from ParameterLib::Parameter< T >
 ~Parameter () override=default
virtual Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > getNodalValuesOnElement (MeshLib::Element const &element, double const t) const
 Returns a matrix of values for all nodes of the given element.
 ParameterBase (std::string name_, MeshLib::Mesh const *mesh=nullptr)
Public Member Functions inherited from ParameterLib::ParameterBase
 ParameterBase (std::string name_, MeshLib::Mesh const *mesh=nullptr)
virtual ~ParameterBase ()=default
void setCoordinateSystem (CoordinateSystem const &coordinate_system)
virtual void initialize (std::vector< std::unique_ptr< ParameterBase > > const &)
MeshLib::Mesh const * mesh () const

Private Attributes

symbol_table_t _symbol_table
std::vector< expression_t_vec_expression
std::vector< std::pair< std::string, CurveWrapper > > _curves
std::mutex _mutex

Additional Inherited Members

Public Attributes inherited from ParameterLib::ParameterBase
std::string const name
Protected Member Functions inherited from ParameterLib::ParameterBase
std::vector< double > rotateWithCoordinateSystem (std::vector< double > const &values, SpatialPosition const &pos) const
Protected Attributes inherited from ParameterLib::ParameterBase
std::optional< CoordinateSystem_coordinate_system
MeshLib::Mesh const * _mesh

Member Typedef Documentation

◆ expression_t

template<typename T>
using ParameterLib::FunctionParameter< T >::expression_t = exprtk::expression<T>

Definition at line 43 of file FunctionParameter.h.

◆ parser_t

template<typename T>
using ParameterLib::FunctionParameter< T >::parser_t = exprtk::parser<T>

Definition at line 44 of file FunctionParameter.h.

◆ symbol_table_t

template<typename T>
using ParameterLib::FunctionParameter< T >::symbol_table_t = exprtk::symbol_table<T>

Definition at line 42 of file FunctionParameter.h.

Constructor & Destructor Documentation

◆ FunctionParameter()

template<typename T>
ParameterLib::FunctionParameter< T >::FunctionParameter ( std::string const & name,
std::vector< std::string > const & vec_expression_str,
std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const & curves )
inline

Constructing from a vector of expressions

Parameters
namethe parameter's name
vec_expression_stra vector of mathematical expressions
curvesnamed list of curves used by expressions. The vector size specifies the number of components of the parameter.

Definition at line 54 of file FunctionParameter.h.

60 : Parameter<T>(name, nullptr)
61 {
62 // Convert curves to function objects callable by the exprtk.
63 _curves.reserve(curves.size());
67 return {curve.first, CurveWrapper(*curve.second)};
68 });
69
70 // Create symbol table for variables and functions.
71 _symbol_table.add_constants();
72 _symbol_table.create_variable("x");
73 _symbol_table.create_variable("y");
74 _symbol_table.create_variable("z");
75 _symbol_table.create_variable("t");
76 for (auto& curve : _curves)
77 {
78 _symbol_table.add_function(curve.first, curve.second);
79 }
80
81 // Compile expressions.
83 for (unsigned i = 0; i < vec_expression_str.size(); i++)
84 {
85 _vec_expression[i].register_symbol_table(_symbol_table);
88 {
89 OGS_FATAL("Error: {:s}\tExpression: {:s}\n",
90 parser.error(),
92 }
93 }
94 }
#define OGS_FATAL(...)
Definition Error.h:19
std::vector< std::pair< std::string, CurveWrapper > > _curves
std::vector< expression_t > _vec_expression

References _curves, _symbol_table, _vec_expression, ParameterLib::ParameterBase::name, and OGS_FATAL.

Member Function Documentation

◆ getNumberOfGlobalComponents()

template<typename T>
int ParameterLib::FunctionParameter< T >::getNumberOfGlobalComponents ( ) const
inlineoverridevirtual

Returns the number of components this Parameter has at every position and point in time.

Implements ParameterLib::Parameter< T >.

Definition at line 98 of file FunctionParameter.h.

99 {
100 return _vec_expression.size();
101 }

References _vec_expression.

Referenced by operator()().

◆ isTimeDependent()

template<typename T>
bool ParameterLib::FunctionParameter< T >::isTimeDependent ( ) const
inlineoverridevirtual

Implements ParameterLib::ParameterBase.

Definition at line 96 of file FunctionParameter.h.

96{ return true; }

◆ operator()()

template<typename T>
std::vector< T > ParameterLib::FunctionParameter< T >::operator() ( double const t,
SpatialPosition const & pos ) const
inlineoverridevirtual

Returns the parameter value at the given time and position.

Implements ParameterLib::Parameter< T >.

Definition at line 103 of file FunctionParameter.h.

105 {
107 auto& x = _symbol_table.get_variable("x")->ref();
108 auto& y = _symbol_table.get_variable("y")->ref();
109 auto& z = _symbol_table.get_variable("z")->ref();
110 auto& time = _symbol_table.get_variable("t")->ref();
111 if (!pos.getCoordinates())
112 {
113 OGS_FATAL(
114 "FunctionParameter: The spatial position has to be set by "
115 "coordinates.");
116 }
117 auto const coords = pos.getCoordinates().value();
118
119 {
121 x = coords[0];
122 y = coords[1];
123 z = coords[2];
124 time = t;
125
126 {
127 for (unsigned i = 0; i < _vec_expression.size(); i++)
128 {
129 cache[i] = _vec_expression[i].value();
130 }
131 }
132 }
133
134 if (!this->_coordinate_system)
135 {
136 return cache;
137 }
138
139 return this->rotateWithCoordinateSystem(cache, pos);
140 }
int getNumberOfGlobalComponents() const override
std::vector< double > rotateWithCoordinateSystem(std::vector< double > const &values, SpatialPosition const &pos) const
std::optional< CoordinateSystem > _coordinate_system

References ParameterLib::ParameterBase::_coordinate_system, _mutex, _symbol_table, _vec_expression, ParameterLib::SpatialPosition::getCoordinates(), getNumberOfGlobalComponents(), OGS_FATAL, and ParameterLib::ParameterBase::rotateWithCoordinateSystem().

Member Data Documentation

◆ _curves

template<typename T>
std::vector<std::pair<std::string, CurveWrapper> > ParameterLib::FunctionParameter< T >::_curves
private

Definition at line 145 of file FunctionParameter.h.

Referenced by FunctionParameter().

◆ _mutex

template<typename T>
std::mutex ParameterLib::FunctionParameter< T >::_mutex
mutableprivate

Definition at line 146 of file FunctionParameter.h.

Referenced by operator()().

◆ _symbol_table

template<typename T>
symbol_table_t ParameterLib::FunctionParameter< T >::_symbol_table
private

Definition at line 143 of file FunctionParameter.h.

Referenced by FunctionParameter(), and operator()().

◆ _vec_expression

template<typename T>
std::vector<expression_t> ParameterLib::FunctionParameter< T >::_vec_expression
private

Definition at line 144 of file FunctionParameter.h.

Referenced by FunctionParameter(), getNumberOfGlobalComponents(), and operator()().


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