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 25 of file Function.h.

#include <Function.h>

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

Classes

class  Implementation
 

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 variable, ParameterLib::SpatialPosition const &pos, double const t, double const dt) const override
 
 ~Function ()
 
- 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.
 
virtual void setProperties (std::vector< std::unique_ptr< Phase > > const &phases)
 Default implementation:
 
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 Member Functions

std::variant< Function::Implementation< 2 > *, Function::Implementation< 3 > * > getImplementationForDimensionOfVariableArray (VariableArray const &variable_array) const
 

Private Attributes

std::unique_ptr< Implementation< 2 > > impl2_
 
std::unique_ptr< Implementation< 3 > > impl3_
 
std::vector< Variablevariables_
 Variables used in the exprtk expressions.
 
std::mutex mutex_
 

Additional Inherited Members

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

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 323 of file Function.cpp.

328{
329 name_ = std::move(name);
330
331 auto const variables =
332 collectVariables(value_string_expressions, dvalue_string_expressions);
333 variables_ =
334 variables |
335 ranges::views::transform([](std::string const& s)
336 { return convertStringToVariable(s); }) |
337 ranges::to<std::vector>;
338
339 impl2_ = std::make_unique<Implementation<2>>(
340 variables, value_string_expressions, dvalue_string_expressions);
341 impl3_ = std::make_unique<Implementation<3>>(
342 variables, value_string_expressions, dvalue_string_expressions);
343}
std::unique_ptr< Implementation< 3 > > impl3_
Definition Function.h:52
std::vector< Variable > variables_
Variables used in the exprtk expressions.
Definition Function.h:59
std::unique_ptr< Implementation< 2 > > impl2_
Definition Function.h:51
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:293
Variable convertStringToVariable(std::string const &string)

References MaterialPropertyLib::collectVariables(), MaterialPropertyLib::convertStringToVariable(), impl2_, impl3_, MaterialPropertyLib::name, MaterialPropertyLib::Property::name_, and variables_.

◆ ~Function()

MaterialPropertyLib::Function::~Function ( )
default

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 377 of file Function.cpp.

381{
382 return std::visit(
383 [&](auto&& impl_ptr)
384 {
385 auto const it = std::find_if(begin(impl_ptr->dvalue_expressions),
386 end(impl_ptr->dvalue_expressions),
387 [&variable](auto const& v)
388 { return v.first == variable; });
389
390 if (it == end(impl_ptr->dvalue_expressions))
391 {
392 OGS_FATAL(
393 "Requested derivative with respect to the variable {:s} "
394 "not "
395 "provided for Function-type property {:s}.",
396 variable_enum_to_string[static_cast<int>(variable)], name_);
397 }
398
399 return evaluateExpressions(variables_, variable_array, it->second,
400 impl_ptr->variable_array, mutex_);
401 },
403}
#define OGS_FATAL(...)
Definition Error.h:26
std::variant< Function::Implementation< 2 > *, Function::Implementation< 3 > * > getImplementationForDimensionOfVariableArray(VariableArray const &variable_array) const
Definition Function.cpp:346
static PropertyDataType evaluateExpressions(std::vector< Variable > const &variables, VariableArray const &new_variable_array, std::vector< exprtk::expression< double > > const &expressions, VariableArray &variable_array, std::mutex &mutex)
Definition Function.cpp:242
static const std::array< std::string, static_cast< int >(Variable::number_of_variables)> variable_enum_to_string

References MaterialPropertyLib::evaluateExpressions(), getImplementationForDimensionOfVariableArray(), mutex_, MaterialPropertyLib::Property::name_, OGS_FATAL, MaterialPropertyLib::variable_enum_to_string, and variables_.

◆ getImplementationForDimensionOfVariableArray()

std::variant< Function::Implementation< 2 > *, Function::Implementation< 3 > * > MaterialPropertyLib::Function::getImplementationForDimensionOfVariableArray ( VariableArray const & variable_array) const
private

Definition at line 346 of file Function.cpp.

348{
349 if (variable_array.is2D())
350 {
351 return impl2_.get();
352 }
353 if (variable_array.is3D())
354 {
355 return impl3_.get();
356 }
357
358 OGS_FATAL(
359 "Variable array has vectors for 2 and 3 dimensions simultaneously. "
360 "Mixed dimensions cannot be dealt within Function evaluation.");
361}

References impl2_, impl3_, MaterialPropertyLib::VariableArray::is2D(), MaterialPropertyLib::VariableArray::is3D(), and OGS_FATAL.

Referenced by dValue(), and value().

◆ 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 363 of file Function.cpp.

366{
367 return std::visit(
368 [&](auto&& impl_ptr)
369 {
370 return evaluateExpressions(variables_, variable_array,
371 impl_ptr->value_expressions,
372 impl_ptr->variable_array, mutex_);
373 },
375}

References MaterialPropertyLib::evaluateExpressions(), getImplementationForDimensionOfVariableArray(), mutex_, and variables_.

Member Data Documentation

◆ impl2_

std::unique_ptr<Implementation<2> > MaterialPropertyLib::Function::impl2_
private

Definition at line 51 of file Function.h.

Referenced by Function(), and getImplementationForDimensionOfVariableArray().

◆ impl3_

std::unique_ptr<Implementation<3> > MaterialPropertyLib::Function::impl3_
private

Definition at line 52 of file Function.h.

Referenced by Function(), and getImplementationForDimensionOfVariableArray().

◆ mutex_

std::mutex MaterialPropertyLib::Function::mutex_
mutableprivate

Definition at line 61 of file Function.h.

Referenced by dValue(), and value().

◆ variables_

std::vector<Variable> MaterialPropertyLib::Function::variables_
private

Variables used in the exprtk expressions.

Definition at line 59 of file Function.h.

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


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