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...
 
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 ()
 

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 22 of file FunctionMaterialPropertyDescriptor.h.

Constructor & Destructor Documentation

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

Definition at line 7 of file FunctionMaterialPropertyDescriptor.C.

10 {
11  size_t define = expression.find_last_of(":=");
12 
13  // expression contains a ':='
14  if (define != std::string::npos)
15  {
16  // section before ':=' is the name used in the function expression
17  _fparser_name = expression.substr(0, define - 1);
18 
19  // parse right hand side
20  parseDerivative(expression.substr(define + 1));
21  }
22  else
23  {
24  // parse entire expression and use natural material property base name
25  // for D(x(t),t,t) this would simply be 'x'!
26  parseDerivative(expression);
28  }
29 
30  _value = NULL;
31 }
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::FunctionMaterialPropertyDescriptor ( )

default constructor

Definition at line 33 of file FunctionMaterialPropertyDescriptor.C.

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

copy constructor

Definition at line 35 of file FunctionMaterialPropertyDescriptor.C.

41  _value(NULL),
42  _parent(rhs._parent)
43 {
44 }
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

void FunctionMaterialPropertyDescriptor::addDerivative ( const VariableName &  var)

take another derivative

Definition at line 59 of file FunctionMaterialPropertyDescriptor.C.

Referenced by DerivativeParsedMaterialHelper::assembleDerivatives(), and getPropertyName().

60 {
61  _derivative_vars.push_back(var);
62  _value = NULL;
63 }
const MaterialProperty< Real > * _value
material property value (this is lazily updated and cached when read through value()) ...
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 66 of file FunctionMaterialPropertyDescriptor.C.

Referenced by DerivativeParsedMaterialHelper::assembleDerivatives(), and getPropertyName().

67 {
68  return std::find(_dependent_vars.begin(), _dependent_vars.end(), var) != _dependent_vars.end() ||
69  std::find(_derivative_vars.begin(), _derivative_vars.end(), var) != _derivative_vars.end();
70 }
std::vector< VariableName > FunctionMaterialPropertyDescriptor::getDependentVariables ( )

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

Definition at line 73 of file FunctionMaterialPropertyDescriptor.C.

Referenced by getPropertyName().

74 {
75  std::set<VariableName> all;
76  all.insert(_dependent_vars.begin(), _dependent_vars.end());
77  all.insert(_derivative_vars.begin(), _derivative_vars.end());
78 
79  return std::vector<VariableName>(all.begin(), all.end());
80 }
const std::string FunctionMaterialPropertyDescriptor::getPropertyName ( ) const
inline

get the property name

Definition at line 56 of file FunctionMaterialPropertyDescriptor.h.

Referenced by DerivativeParsedMaterialHelper::findMatPropDerivative(), and printDebug().

56 { return propertyName(_base_name, _derivative_vars); };
std::string _base_name
function material property base name
const std::string& FunctionMaterialPropertyDescriptor::getSymbolName ( ) const
inline

get the fparser symbol name

Definition at line 50 of file FunctionMaterialPropertyDescriptor.h.

Referenced by DerivativeParsedMaterialHelper::assembleDerivatives().

50 { return _fparser_name; };
std::string _fparser_name
name used in function expression
void FunctionMaterialPropertyDescriptor::parseDependentVariables ( const std::string &  expression)
private

Definition at line 133 of file FunctionMaterialPropertyDescriptor.C.

Referenced by getPropertyName(), and parseDerivative().

134 {
135  size_t open = expression.find_first_of("(");
136  size_t close = expression.find_last_of(")");
137 
138  if (open == std::string::npos && close == std::string::npos)
139  {
140  // material property name without arguments
141  _base_name = expression;
142  }
143  else if (open != std::string::npos && close != std::string::npos)
144  {
145  // take material property name before bracket
146  _base_name = expression.substr(0, open);
147 
148  // parse argument list
149  MooseUtils::tokenize(expression.substr(open + 1, close - open - 1), _dependent_vars, 0, ",");
150 
151  // cremove duplicates from dependent variable list
152  std::sort(_dependent_vars.begin(), _dependent_vars.end());
153  _dependent_vars.erase(std::unique(_dependent_vars.begin(), _dependent_vars.end()),
154  _dependent_vars.end());
155  }
156  else
157  mooseError("Malformed material_properties expression '", expression, "'");
158 }
std::string _base_name
function material property base name
void FunctionMaterialPropertyDescriptor::parseDerivative ( const std::string &  expression)
private

Definition at line 83 of file FunctionMaterialPropertyDescriptor.C.

Referenced by FunctionMaterialPropertyDescriptor(), and getPropertyName().

84 {
85  size_t open = expression.find_first_of("[");
86  size_t close = expression.find_last_of("]");
87 
88  if (open == std::string::npos && close == std::string::npos)
89  {
90  // no derivative requested
91  parseDependentVariables(expression);
92 
93  return;
94  }
95  else if (open != std::string::npos && close != std::string::npos &&
96  expression.substr(0, open) == "D")
97  {
98  // tokenize splits the arguments in d2h2:=D[h2(eta1,eta2),eta1] into 'h2(eta1' 'eta2)' 'eta1'
99  // DAMN!!
100  std::string arguments = expression.substr(open + 1, close - open - 1);
101  size_t close2 = arguments.find_last_of(")");
102 
103  if (close2 == std::string::npos)
104  {
105  // rest of argument list 0 is the function and 1,.. are the variable to take the derivative
106  // w.r.t.
107  MooseUtils::tokenize(arguments, _derivative_vars, 0, ",");
108 
109  // check for empty [] brackets
110  if (_derivative_vars.size() > 0)
111  {
112  // parse argument zero of D[] as the function material property
114 
115  // remove function from the _derivative_vars vector
116  _derivative_vars.erase(_derivative_vars.begin());
117 
118  return;
119  }
120  }
121  else
122  {
123  parseDependentVariables(arguments.substr(0, close2 + 1));
124  MooseUtils::tokenize(arguments.substr(close2 + 2), _derivative_vars, 0, ",");
125  return;
126  }
127  }
128 
129  mooseError("Malformed material_properties expression '", expression, "'");
130 }
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 47 of file FunctionMaterialPropertyDescriptor.C.

49 {
50  std::vector<FunctionMaterialPropertyDescriptor> fmpds;
51  for (std::vector<std::string>::const_iterator i = expression_list.begin();
52  i != expression_list.end();
53  ++i)
54  fmpds.push_back(FunctionMaterialPropertyDescriptor(*i, parent));
55  return fmpds;
56 }
Material properties get fully described using this structure, including their dependent variables and...
void FunctionMaterialPropertyDescriptor::printDebug ( )

Definition at line 161 of file FunctionMaterialPropertyDescriptor.C.

Referenced by getPropertyName().

162 {
163  Moose::out << "MPD: " << _fparser_name << ' ' << _base_name << " deriv = [";
164  for (unsigned int i = 0; i < _derivative_vars.size(); ++i)
165  Moose::out << _derivative_vars[i] << ' ';
166  Moose::out << "] dep = [";
167  for (unsigned int i = 0; i < _dependent_vars.size(); ++i)
168  Moose::out << _dependent_vars[i] << ' ';
169  Moose::out << "] " << getPropertyName() << '\n';
170 }
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
void FunctionMaterialPropertyDescriptor::setSymbolName ( const std::string &  n)
inline

set the fparser symbol name

Definition at line 53 of file FunctionMaterialPropertyDescriptor.h.

Referenced by DerivativeParsedMaterialHelper::assembleDerivatives().

53 { _fparser_name = n; };
std::string _fparser_name
name used in function expression
const MaterialProperty< Real > & FunctionMaterialPropertyDescriptor::value ( ) const

get the property reference

Definition at line 173 of file FunctionMaterialPropertyDescriptor.C.

Referenced by getPropertyName().

174 {
175  if (_value == NULL)
176  {
177  DerivativeMaterialInterface<Material> * _material_parent =
178  dynamic_cast<DerivativeMaterialInterface<Material> *>(_parent);
179  DerivativeMaterialInterface<Kernel> * _kernel_parent =
180  dynamic_cast<DerivativeMaterialInterface<Kernel> *>(_parent);
181 
182  // get the material property reference
183  if (_material_parent)
184  _value =
185  &(_material_parent->getMaterialPropertyDerivative<Real>(_base_name, _derivative_vars));
186  else if (_kernel_parent)
187  _value = &(_kernel_parent->getMaterialPropertyDerivative<Real>(_base_name, _derivative_vars));
188  else
189  mooseError("A FunctionMaterialPropertyDescriptor must be owned by either a Material or a "
190  "Kernel object.");
191  }
192 
193  return *_value;
194 }
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

std::string FunctionMaterialPropertyDescriptor::_base_name
private

function material property base name

Definition at line 85 of file FunctionMaterialPropertyDescriptor.h.

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

std::vector<VariableName> FunctionMaterialPropertyDescriptor::_dependent_vars
private
std::vector<VariableName> FunctionMaterialPropertyDescriptor::_derivative_vars
private
std::string FunctionMaterialPropertyDescriptor::_fparser_name
private

name used in function expression

Definition at line 82 of file FunctionMaterialPropertyDescriptor.h.

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

MooseObject* FunctionMaterialPropertyDescriptor::_parent
private

material object that owns this descriptor

Definition at line 94 of file FunctionMaterialPropertyDescriptor.h.

Referenced by value().

const MaterialProperty<Real>* FunctionMaterialPropertyDescriptor::_value
mutableprivate

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

Definition at line 91 of file FunctionMaterialPropertyDescriptor.h.

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


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