www.mooseframework.org
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
FunctionMaterialPropertyDescriptor Class Reference

Material properties get fully described using this structure, including their dependent variables and derivation state. More...

#include <FunctionMaterialPropertyDescriptor.h>

Inheritance diagram for FunctionMaterialPropertyDescriptor:
[legend]

Public Member Functions

 FunctionMaterialPropertyDescriptor (const std::string &, MooseObject *)
 
 FunctionMaterialPropertyDescriptor ()
 default constructor More...
 
 FunctionMaterialPropertyDescriptor (const FunctionMaterialPropertyDescriptor &)
 copy constructor More...
 
 FunctionMaterialPropertyDescriptor (const FunctionMaterialPropertyDescriptor &, MooseObject *)
 copy constructor assigning new parent More...
 
const std::string & getSymbolName () const
 get the fparser symbol name More...
 
void setSymbolName (const std::string &n)
 set the fparser symbol name More...
 
const std::string getPropertyName () const
 get the property name More...
 
const MaterialProperty< Real > & value () const
 get the property reference More...
 
void addDerivative (const VariableName &var)
 take another derivative More...
 
bool dependsOn (const std::string &var) const
 Check if a material property depends on a given variable. More...
 
std::vector< VariableName > getDependentVariables ()
 builds a list of dependent variables (exactly all variabled for which depends on returns true) More...
 
void printDebug ()
 
const MaterialPropertyName propertyName (const MaterialPropertyName &base, const std::vector< VariableName > &c) const
 Helper functions to generate the material property names for the arbitrary derivatives. More...
 
const MaterialPropertyName propertyNameFirst (const MaterialPropertyName &base, const VariableName &c1) const
 Helper functions to generate the material property names for the first derivatives. More...
 
const MaterialPropertyName propertyNameSecond (const MaterialPropertyName &base, const VariableName &c1, const VariableName &c2) const
 Helper functions to generate the material property names for the second derivatives. More...
 
const MaterialPropertyName propertyNameThird (const MaterialPropertyName &base, const VariableName &c1, const VariableName &c2, const VariableName &c3) const
 Helper functions to generate the material property names for the third derivatives. More...
 

Static Public Member Functions

static std::vector< FunctionMaterialPropertyDescriptorparseVector (const std::vector< std::string > &, MooseObject *)
 construct a vector of FunctionMaterialPropertyDescriptors from a vector of strings More...
 

Private Member Functions

void parseDerivative (const std::string &)
 
void parseDependentVariables (const std::string &)
 

Private Attributes

std::string _fparser_name
 name used in function expression More...
 
std::string _base_name
 function material property base name More...
 
std::vector< VariableName > _dependent_vars
 
std::vector< VariableName > _derivative_vars
 
const MaterialProperty< Real > * _value
 material property value (this is lazily updated and cached when read through value()) More...
 
MooseObject_parent
 material object that owns this descriptor More...
 

Detailed Description

Material properties get fully described using this structure, including their dependent variables and derivation state.

Definition at line 25 of file FunctionMaterialPropertyDescriptor.h.

Constructor & Destructor Documentation

◆ FunctionMaterialPropertyDescriptor() [1/4]

FunctionMaterialPropertyDescriptor::FunctionMaterialPropertyDescriptor ( const std::string &  expression,
MooseObject parent 
)

Definition at line 16 of file FunctionMaterialPropertyDescriptor.C.

19 {
20  auto define = expression.find_last_of(":=");
21 
22  // expression contains a ':='
23  if (define != std::string::npos)
24  {
25  // section before ':=' is the name used in the function expression
26  _fparser_name = expression.substr(0, define - 1);
27 
28  // parse right hand side
29  parseDerivative(expression.substr(define + 1));
30  }
31  else
32  {
33  // parse entire expression and use natural material property base name
34  // for D(x(t),t,t) this would simply be 'x'!
35  parseDerivative(expression);
37  }
38 
39  _value = nullptr;
40 }
std::string _base_name
function material property base name
MooseObject * _parent
material object that owns this descriptor
std::string _fparser_name
name used in function expression
const MaterialProperty< Real > * _value
material property value (this is lazily updated and cached when read through value()) ...

◆ FunctionMaterialPropertyDescriptor() [2/4]

FunctionMaterialPropertyDescriptor::FunctionMaterialPropertyDescriptor ( )

default constructor

Definition at line 42 of file FunctionMaterialPropertyDescriptor.C.

Referenced by parseVector().

42 : _value(nullptr) {}
const MaterialProperty< Real > * _value
material property value (this is lazily updated and cached when read through value()) ...

◆ FunctionMaterialPropertyDescriptor() [3/4]

FunctionMaterialPropertyDescriptor::FunctionMaterialPropertyDescriptor ( const FunctionMaterialPropertyDescriptor rhs)

copy constructor

Definition at line 44 of file FunctionMaterialPropertyDescriptor.C.

50  _value(nullptr),
51  _parent(rhs._parent)
52 {
53 }
std::string _base_name
function material property base name
MooseObject * _parent
material object that owns this descriptor
std::string _fparser_name
name used in function expression
const MaterialProperty< Real > * _value
material property value (this is lazily updated and cached when read through value()) ...

◆ FunctionMaterialPropertyDescriptor() [4/4]

FunctionMaterialPropertyDescriptor::FunctionMaterialPropertyDescriptor ( const FunctionMaterialPropertyDescriptor rhs,
MooseObject parent 
)

copy constructor assigning new parent

Definition at line 55 of file FunctionMaterialPropertyDescriptor.C.

61  _value(nullptr),
62  _parent(parent)
63 {
64 }
std::string _base_name
function material property base name
MooseObject * _parent
material object that owns this descriptor
std::string _fparser_name
name used in function expression
const MaterialProperty< Real > * _value
material property value (this is lazily updated and cached when read through value()) ...

Member Function Documentation

◆ addDerivative()

void FunctionMaterialPropertyDescriptor::addDerivative ( const VariableName &  var)

take another derivative

Definition at line 77 of file FunctionMaterialPropertyDescriptor.C.

Referenced by DerivativeParsedMaterialHelper::assembleDerivatives().

78 {
79  _derivative_vars.push_back(var);
80  _value = nullptr;
81 }
const MaterialProperty< Real > * _value
material property value (this is lazily updated and cached when read through value()) ...

◆ dependsOn()

bool FunctionMaterialPropertyDescriptor::dependsOn ( const std::string &  var) const

Check if a material property depends on a given variable.

A dependency is indicated by either directly specifying it, or by requesting a derivative w.r.t. that variable using the D[x,a] syntax

Definition at line 84 of file FunctionMaterialPropertyDescriptor.C.

Referenced by DerivativeParsedMaterialHelper::assembleDerivatives().

85 {
86  return std::find(_dependent_vars.begin(), _dependent_vars.end(), var) != _dependent_vars.end() ||
87  std::find(_derivative_vars.begin(), _derivative_vars.end(), var) != _derivative_vars.end();
88 }

◆ getDependentVariables()

std::vector< VariableName > FunctionMaterialPropertyDescriptor::getDependentVariables ( )

builds a list of dependent variables (exactly all variabled for which depends on returns true)

Definition at line 91 of file FunctionMaterialPropertyDescriptor.C.

92 {
93  std::set<VariableName> all;
94  all.insert(_dependent_vars.begin(), _dependent_vars.end());
95  all.insert(_derivative_vars.begin(), _derivative_vars.end());
96 
97  return std::vector<VariableName>(all.begin(), all.end());
98 }

◆ getPropertyName()

const std::string FunctionMaterialPropertyDescriptor::getPropertyName ( ) const
inline

get the property name

Definition at line 62 of file FunctionMaterialPropertyDescriptor.h.

Referenced by printDebug().

const MaterialPropertyName propertyName(const MaterialPropertyName &base, const std::vector< VariableName > &c) const
Helper functions to generate the material property names for the arbitrary derivatives.
std::string _base_name
function material property base name

◆ getSymbolName()

const std::string& FunctionMaterialPropertyDescriptor::getSymbolName ( ) const
inline

get the fparser symbol name

Definition at line 56 of file FunctionMaterialPropertyDescriptor.h.

Referenced by DerivativeParsedMaterialHelper::assembleDerivatives().

56 { return _fparser_name; };
std::string _fparser_name
name used in function expression

◆ parseDependentVariables()

void FunctionMaterialPropertyDescriptor::parseDependentVariables ( const std::string &  expression)
private

Definition at line 151 of file FunctionMaterialPropertyDescriptor.C.

Referenced by parseDerivative().

152 {
153  auto open = expression.find_first_of("(");
154  auto close = expression.find_last_of(")");
155 
156  if (open == std::string::npos && close == std::string::npos)
157  {
158  // material property name without arguments
159  _base_name = expression;
160  }
161  else if (open != std::string::npos && close != std::string::npos)
162  {
163  // take material property name before bracket
164  _base_name = expression.substr(0, open);
165 
166  // parse argument list
167  MooseUtils::tokenize(expression.substr(open + 1, close - open - 1), _dependent_vars, 0, ",");
168 
169  // cremove duplicates from dependent variable list
170  std::sort(_dependent_vars.begin(), _dependent_vars.end());
171  _dependent_vars.erase(std::unique(_dependent_vars.begin(), _dependent_vars.end()),
172  _dependent_vars.end());
173  }
174  else
175  mooseError("Malformed material_properties expression '", expression, "'");
176 }
void tokenize(const std::string &str, std::vector< T > &elements, unsigned int min_len=1, const std::string &delims="/")
This function will split the passed in string on a set of delimiters appending the substrings to the ...
Definition: MooseUtils.h:377
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
std::string _base_name
function material property base name
the_pc close()

◆ parseDerivative()

void FunctionMaterialPropertyDescriptor::parseDerivative ( const std::string &  expression)
private

Definition at line 101 of file FunctionMaterialPropertyDescriptor.C.

Referenced by FunctionMaterialPropertyDescriptor().

102 {
103  auto open = expression.find_first_of("[");
104  auto close = expression.find_last_of("]");
105 
106  if (open == std::string::npos && close == std::string::npos)
107  {
108  // no derivative requested
109  parseDependentVariables(expression);
110 
111  return;
112  }
113  else if (open != std::string::npos && close != std::string::npos &&
114  expression.substr(0, open) == "D")
115  {
116  // tokenize splits the arguments in d2h2:=D[h2(eta1,eta2),eta1] into 'h2(eta1' 'eta2)' 'eta1'
117  // DAMN!!
118  auto arguments = expression.substr(open + 1, close - open - 1);
119  auto close2 = arguments.find_last_of(")");
120 
121  if (close2 == std::string::npos)
122  {
123  // rest of argument list 0 is the function and 1,.. are the variable to take the derivative
124  // w.r.t.
125  MooseUtils::tokenize(arguments, _derivative_vars, 0, ",");
126 
127  // check for empty [] brackets
128  if (_derivative_vars.size() > 0)
129  {
130  // parse argument zero of D[] as the function material property
132 
133  // remove function from the _derivative_vars vector
134  _derivative_vars.erase(_derivative_vars.begin());
135 
136  return;
137  }
138  }
139  else
140  {
141  parseDependentVariables(arguments.substr(0, close2 + 1));
142  MooseUtils::tokenize(arguments.substr(close2 + 2), _derivative_vars, 0, ",");
143  return;
144  }
145  }
146 
147  mooseError("Malformed material_properties expression '", expression, "'");
148 }
void tokenize(const std::string &str, std::vector< T > &elements, unsigned int min_len=1, const std::string &delims="/")
This function will split the passed in string on a set of delimiters appending the substrings to the ...
Definition: MooseUtils.h:377
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
the_pc close()

◆ parseVector()

std::vector< FunctionMaterialPropertyDescriptor > FunctionMaterialPropertyDescriptor::parseVector ( const std::vector< std::string > &  expression_list,
MooseObject parent 
)
static

construct a vector of FunctionMaterialPropertyDescriptors from a vector of strings

Definition at line 67 of file FunctionMaterialPropertyDescriptor.C.

69 {
70  std::vector<FunctionMaterialPropertyDescriptor> fmpds;
71  for (auto & ex : expression_list)
72  fmpds.push_back(FunctionMaterialPropertyDescriptor(ex, parent));
73  return fmpds;
74 }

◆ printDebug()

void FunctionMaterialPropertyDescriptor::printDebug ( )

Definition at line 179 of file FunctionMaterialPropertyDescriptor.C.

180 {
181  Moose::out << "MPD: " << _fparser_name << ' ' << _base_name << " deriv = [";
182  for (auto & dv : _derivative_vars)
183  Moose::out << dv << ' ';
184  Moose::out << "] dep = [";
185  for (auto & dv : _dependent_vars)
186  Moose::out << dv << ' ';
187  Moose::out << "] " << getPropertyName() << '\n';
188 }
const std::string getPropertyName() const
get the property name
std::string _base_name
function material property base name
std::string _fparser_name
name used in function expression

◆ propertyName()

const MaterialPropertyName DerivativeMaterialPropertyNameInterface::propertyName ( const MaterialPropertyName &  base,
const std::vector< VariableName > &  c 
) const
inherited

Helper functions to generate the material property names for the arbitrary derivatives.

Definition at line 15 of file DerivativeMaterialPropertyNameInterface.C.

Referenced by getPropertyName(), DerivativeMaterialPropertyNameInterface::propertyNameSecond(), and DerivativeMaterialPropertyNameInterface::propertyNameThird().

17 {
18  // to obtain well defined names we sort alphabetically
19  std::vector<VariableName> a(c);
20  std::sort(a.begin(), a.end());
21 
22  // derivative order
23  unsigned int order = a.size();
24  if (order == 0)
25  return base;
26 
27  // build the property name as a stringstream
28  std::stringstream name;
29 
30  // build numerator
31  name << 'd';
32  if (order > 1)
33  name << '^' << order;
34  name << base << '/';
35 
36  // build denominator with 'pretty' names using exponents rather than repeat multiplication
37  unsigned int exponent = 1;
38  for (unsigned i = 1; i <= order; ++i)
39  {
40  if (i == order || a[i - 1] != a[i])
41  {
42  name << 'd' << a[i - 1];
43  if (exponent > 1)
44  name << '^' << exponent;
45  exponent = 1;
46  }
47  else
48  exponent++;
49  }
50 
51  return name.str();
52 }

◆ propertyNameFirst()

const MaterialPropertyName DerivativeMaterialPropertyNameInterface::propertyNameFirst ( const MaterialPropertyName &  base,
const VariableName &  c1 
) const
inherited

Helper functions to generate the material property names for the first derivatives.

Definition at line 55 of file DerivativeMaterialPropertyNameInterface.C.

Referenced by DerivativeFunctionMaterialBase::initialSetup().

57 {
58  return "d" + base + "/d" + c1;
59 }

◆ propertyNameSecond()

const MaterialPropertyName DerivativeMaterialPropertyNameInterface::propertyNameSecond ( const MaterialPropertyName &  base,
const VariableName &  c1,
const VariableName &  c2 
) const
inherited

Helper functions to generate the material property names for the second derivatives.

Definition at line 62 of file DerivativeMaterialPropertyNameInterface.C.

Referenced by DerivativeFunctionMaterialBase::initialSetup().

65 {
66  return propertyName(base, {c1, c2});
67 }
const MaterialPropertyName propertyName(const MaterialPropertyName &base, const std::vector< VariableName > &c) const
Helper functions to generate the material property names for the arbitrary derivatives.

◆ propertyNameThird()

const MaterialPropertyName DerivativeMaterialPropertyNameInterface::propertyNameThird ( const MaterialPropertyName &  base,
const VariableName &  c1,
const VariableName &  c2,
const VariableName &  c3 
) const
inherited

Helper functions to generate the material property names for the third derivatives.

Definition at line 70 of file DerivativeMaterialPropertyNameInterface.C.

Referenced by DerivativeFunctionMaterialBase::initialSetup().

74 {
75  return propertyName(base, {c1, c2, c3});
76 }
const MaterialPropertyName propertyName(const MaterialPropertyName &base, const std::vector< VariableName > &c) const
Helper functions to generate the material property names for the arbitrary derivatives.

◆ setSymbolName()

void FunctionMaterialPropertyDescriptor::setSymbolName ( const std::string &  n)
inline

set the fparser symbol name

Definition at line 59 of file FunctionMaterialPropertyDescriptor.h.

Referenced by DerivativeParsedMaterialHelper::assembleDerivatives().

59 { _fparser_name = n; };
std::string _fparser_name
name used in function expression
PetscInt n

◆ value()

const MaterialProperty< Real > & FunctionMaterialPropertyDescriptor::value ( ) const

get the property reference

Definition at line 191 of file FunctionMaterialPropertyDescriptor.C.

192 {
193  if (_value == nullptr)
194  {
195  DerivativeMaterialInterface<Material> * _material_parent =
197  DerivativeMaterialInterface<Kernel> * _kernel_parent =
199 
200  // get the material property reference
201  if (_material_parent)
202  _value =
203  &(_material_parent->getMaterialPropertyDerivative<Real>(_base_name, _derivative_vars));
204  else if (_kernel_parent)
206  else
207  mooseError("A FunctionMaterialPropertyDescriptor must be owned by either a Material or a "
208  "Kernel object.");
209  }
210 
211  return *_value;
212 }
const MaterialProperty< U > & getMaterialPropertyDerivative(const std::string &base, const std::vector< VariableName > &c)
Methods for retreiving derivative material properties.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
std::string _base_name
function material property base name
MooseObject * _parent
material object that owns this descriptor
const MaterialProperty< Real > * _value
material property value (this is lazily updated and cached when read through value()) ...

Member Data Documentation

◆ _base_name

std::string FunctionMaterialPropertyDescriptor::_base_name
private

function material property base name

Definition at line 91 of file FunctionMaterialPropertyDescriptor.h.

Referenced by FunctionMaterialPropertyDescriptor(), getPropertyName(), parseDependentVariables(), printDebug(), and value().

◆ _dependent_vars

std::vector<VariableName> FunctionMaterialPropertyDescriptor::_dependent_vars
private

◆ _derivative_vars

std::vector<VariableName> FunctionMaterialPropertyDescriptor::_derivative_vars
private

◆ _fparser_name

std::string FunctionMaterialPropertyDescriptor::_fparser_name
private

name used in function expression

Definition at line 88 of file FunctionMaterialPropertyDescriptor.h.

Referenced by FunctionMaterialPropertyDescriptor(), getSymbolName(), printDebug(), and setSymbolName().

◆ _parent

MooseObject* FunctionMaterialPropertyDescriptor::_parent
private

material object that owns this descriptor

Definition at line 100 of file FunctionMaterialPropertyDescriptor.h.

Referenced by value().

◆ _value

const MaterialProperty<Real>* FunctionMaterialPropertyDescriptor::_value
mutableprivate

material property value (this is lazily updated and cached when read through value())

Definition at line 97 of file FunctionMaterialPropertyDescriptor.h.

Referenced by addDerivative(), FunctionMaterialPropertyDescriptor(), and value().


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