OGS
MaterialPropertyLib::Function Class Referencefinal

Detailed Description

A function property defined by mathematical expression. For the evaluation of the expressions the exprtk library is used. In the expressions all variables defined in MaterialPropertyLib::Variable enum can be used.

Warning
The evaluation calls are not to be used in parallel (openMP), because the values' updates are using the same space.

Definition at line 26 of file Function.h.

#include <Function.h>

Inheritance diagram for MaterialPropertyLib::Function:
[legend]
Collaboration diagram for MaterialPropertyLib::Function:
[legend]

Public Member Functions

 Function (std::string name, std::vector< std::string > const &value_string_expressions, std::vector< std::pair< std::string, std::vector< std::string >>> const &dvalue_string_expressions)
 
PropertyDataType value (VariableArray const &variable_array, ParameterLib::SpatialPosition const &pos, double const t, double const dt) const override
 
PropertyDataType dValue (VariableArray const &variable_array, Variable const primary_variable, ParameterLib::SpatialPosition const &pos, double const t, double const dt) const override
 
- Public Member Functions inherited from MaterialPropertyLib::Property
virtual ~Property ()
 
virtual PropertyDataType initialValue (ParameterLib::SpatialPosition const &pos, double const t) const
 
virtual PropertyDataType value () const
 
virtual PropertyDataType value (VariableArray const &variable_array, VariableArray const &variable_array_prev, ParameterLib::SpatialPosition const &pos, double const t, double const dt) const
 
virtual PropertyDataType dValue (VariableArray const &variable_array, VariableArray const &variable_array_prev, Variable const variable, ParameterLib::SpatialPosition const &pos, double const t, double const dt) const
 
virtual PropertyDataType d2Value (VariableArray const &variable_array, Variable const variable1, Variable const variable2, ParameterLib::SpatialPosition const &pos, double const t, double const dt) const
 Default implementation: 2nd derivative of any constant property is zero. More...
 
void setScale (std::variant< Medium *, Phase *, Component * > scale)
 
template<typename T >
initialValue (ParameterLib::SpatialPosition const &pos, double const t) const
 
template<typename T >
value () const
 
template<typename T >
value (VariableArray const &variable_array, VariableArray const &variable_array_prev, ParameterLib::SpatialPosition const &pos, double const t, double const dt) const
 
template<typename T >
value (VariableArray const &variable_array, ParameterLib::SpatialPosition const &pos, double const t, double const dt) const
 
template<typename T >
dValue (VariableArray const &variable_array, VariableArray const &variable_array_prev, Variable const variable, ParameterLib::SpatialPosition const &pos, double const t, double const dt) const
 
template<typename T >
dValue (VariableArray const &variable_array, Variable const variable, ParameterLib::SpatialPosition const &pos, double const t, double const dt) const
 
template<typename T >
d2Value (VariableArray const &variable_array, Variable const &variable1, Variable const &variable2, ParameterLib::SpatialPosition const &pos, double const t, double const dt) const
 

Private Types

using Expression = exprtk::expression< double >
 

Private Attributes

std::vector< std::pair< int, double * > > symbol_values_
 Mapping from variable array index to symbol table values. More...
 
std::vector< Expressionvalue_expressions_
 
std::vector< std::pair< Variable, std::vector< Expression > > > dvalue_expressions_
 

Additional Inherited Members

- Protected Attributes inherited from MaterialPropertyLib::Property
std::string name_
 
PropertyDataType value_
 The single value of a property. More...
 
PropertyDataType dvalue_
 
std::variant< Medium *, Phase *, Component * > scale_
 

Member Typedef Documentation

◆ Expression

using MaterialPropertyLib::Function::Expression = exprtk::expression<double>
private

Definition at line 47 of file Function.h.

Constructor & Destructor Documentation

◆ Function()

MaterialPropertyLib::Function::Function ( std::string  name,
std::vector< std::string > const &  value_string_expressions,
std::vector< std::pair< std::string, std::vector< std::string >>> const &  dvalue_string_expressions 
)

Definition at line 151 of file Function.cpp.

156 {
157  name_ = std::move(name);
158 
159  // Create symbol table for used variables.
160  exprtk::symbol_table<double> symbol_table;
161 
162  for (auto const& v :
163  collectVariables(value_string_expressions, dvalue_string_expressions))
164  {
165  symbol_table.create_variable(v);
166  // Store variables index in the variable array and the pointer to the
167  // value in the symbol table for fast access later.
168  int const variable_array_index =
169  static_cast<int>(convertStringToVariable(v));
170  symbol_values_.emplace_back(variable_array_index,
171  &symbol_table.get_variable(v)->ref());
172  }
173 
174  // value expressions.
176  compileExpressions(symbol_table, value_string_expressions);
177 
178  // dValue expressions.
179  for (auto const& [variable_name, string_expressions] :
180  dvalue_string_expressions)
181  {
182  dvalue_expressions_.emplace_back(
183  convertStringToVariable(variable_name),
184  compileExpressions(symbol_table, string_expressions));
185  }
186 }
std::vector< std::pair< int, double * > > symbol_values_
Mapping from variable array index to symbol table values.
Definition: Function.h:50
std::vector< Expression > value_expressions_
Definition: Function.h:53
std::vector< std::pair< Variable, std::vector< Expression > > > dvalue_expressions_
Definition: Function.h:57
static std::vector< exprtk::expression< T > > compileExpressions(exprtk::symbol_table< T > &symbol_table, std::vector< std::string > const &string_expressions)
Definition: Function.cpp:21
static std::vector< std::string > collectVariables(std::vector< std::string > const &value_string_expressions, std::vector< std::pair< std::string, std::vector< std::string >>> const &dvalue_string_expressions)
Definition: Function.cpp:123
Variable convertStringToVariable(std::string const &string)

References MaterialPropertyLib::collectVariables(), MaterialPropertyLib::compileExpressions(), MaterialPropertyLib::convertStringToVariable(), dvalue_expressions_, MaterialPropertyLib::name, MaterialPropertyLib::Property::name_, symbol_values_, and value_expressions_.

Member Function Documentation

◆ dValue()

PropertyDataType MaterialPropertyLib::Function::dValue ( VariableArray const &  variable_array,
Variable const  variable,
ParameterLib::SpatialPosition const &  pos,
double const  t,
double const  dt 
) const
overridevirtual

This virtual method will compute the property derivative value based on the variables that are passed as arguments with the default implementation using empty variables array for the previous time step.

The default implementation of this method only returns the property value derivative without altering it.

Reimplemented from MaterialPropertyLib::Property.

Definition at line 196 of file Function.cpp.

200 {
201  auto const it = std::find_if(begin(dvalue_expressions_),
202  end(dvalue_expressions_),
203  [&primary_variable](auto const& v)
204  { return v.first == primary_variable; });
205 
206  if (it == end(dvalue_expressions_))
207  {
208  OGS_FATAL(
209  "Requested derivative with respect to the variable {:s} not "
210  "provided for Function-type property {:s}.",
211  variable_enum_to_string[static_cast<int>(primary_variable)], name_);
212  }
213 
214  return evaluateExpressions(symbol_values_, variable_array, it->second);
215 }
#define OGS_FATAL(...)
Definition: Error.h:26
static PropertyDataType evaluateExpressions(std::vector< std::pair< int, double * >> const &symbol_values, VariableArray const &variable_array, std::vector< exprtk::expression< double >> const &expressions)
Definition: Function.cpp:79
static const std::array< std::string, static_cast< int >Variable::number_of_variables)> variable_enum_to_string
Definition: VariableType.h:74

References dvalue_expressions_, MaterialPropertyLib::evaluateExpressions(), MaterialPropertyLib::Property::name_, OGS_FATAL, symbol_values_, and MaterialPropertyLib::variable_enum_to_string.

◆ value()

PropertyDataType MaterialPropertyLib::Function::value ( VariableArray const &  variable_array,
ParameterLib::SpatialPosition const &  pos,
double const  t,
double const  dt 
) const
overridevirtual

This virtual method will compute the property value based on the variables that are passed as arguments with the default implementation using empty variables array for the previous time step.

Reimplemented from MaterialPropertyLib::Property.

Definition at line 188 of file Function.cpp.

191 {
192  return evaluateExpressions(symbol_values_, variable_array,
194 }

References MaterialPropertyLib::evaluateExpressions(), symbol_values_, and value_expressions_.

Member Data Documentation

◆ dvalue_expressions_

std::vector<std::pair<Variable, std::vector<Expression> > > MaterialPropertyLib::Function::dvalue_expressions_
private

Derivative expressions with respect to the variable. Multiple expressions are representing vector-valued functions.

Definition at line 57 of file Function.h.

Referenced by Function(), and dValue().

◆ symbol_values_

std::vector<std::pair<int, double*> > MaterialPropertyLib::Function::symbol_values_
private

Mapping from variable array index to symbol table values.

Definition at line 50 of file Function.h.

Referenced by Function(), dValue(), and value().

◆ value_expressions_

std::vector<Expression> MaterialPropertyLib::Function::value_expressions_
private

Value expressions. Multiple expressions are representing vector-valued functions.

Definition at line 53 of file Function.h.

Referenced by Function(), and value().


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