www.mooseframework.org
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
DerivativeFunctionMaterialBase Class Reference

Material base class central to compute the a phase free energy and its derivatives. More...

#include <DerivativeFunctionMaterialBase.h>

Inheritance diagram for DerivativeFunctionMaterialBase:
[legend]

Public Member Functions

 DerivativeFunctionMaterialBase (const InputParameters &parameters)
 

Protected Member Functions

virtual void computeProperties ()
 
virtual void initialSetup ()
 Check if we got the right number of components in the 'args' coupled variable vector. More...
 
virtual Real computeF ()
 Override this method to provide the free energy function. More...
 
virtual Real computeDF (unsigned int arg)
 Override this method for calculating the first derivatives. More...
 
virtual Real computeD2F (unsigned int arg1, unsigned int arg2)
 Override this method to calculate the second derivatives. More...
 
virtual Real computeD3F (unsigned int, unsigned int, unsigned int)
 Override this method to calculate the third derivatives. More...
 
unsigned int argIndex (unsigned int i_var) const
 FunctionMaterialBase keeps an internal list of all the variables the derivatives are taken w.r.t. More...
 

Protected Attributes

bool _third_derivatives
 Calculate (and allocate memory for) the third derivatives of the free energy. More...
 
std::vector< MaterialProperty< Real > * > _prop_dF
 Material properties to store the derivatives of f with respect to arg[i]. More...
 
std::vector< std::vector< MaterialProperty< Real > * > > _prop_d2F
 Material properties to store the second derivatives. More...
 
std::vector< std::vector< std::vector< MaterialProperty< Real > * > > > _prop_d3F
 Material properties to store the third derivatives. More...
 
std::vector< const VariableValue * > _args
 Coupled variables for function arguments. More...
 
std::string _F_name
 Name of the function value material property and used as a base name to concatenate the material property names for the derivatives. More...
 
bool _mapping_is_unique
 Flag that indicates if exactly one linear variable is coupled per input file coupling parameter. More...
 
unsigned int _nargs
 Number of coupled arguments. More...
 
std::vector< std::string > _arg_names
 String vector of all argument names. More...
 
std::vector< unsigned int > _arg_numbers
 Vector of all argument MOOSE variable numbers. More...
 
std::vector< std::string > _arg_param_names
 String vector of the input file coupling parameter name for each argument. More...
 
std::vector< std::string > _arg_constant_defaults
 coupled variables with default values More...
 
MaterialProperty< Real > * _prop_F
 Material property to store the function value. More...
 

Detailed Description

Material base class central to compute the a phase free energy and its derivatives.

Classes derived from this base class are central to the KKS system. The calculation of free energies is centralized here as the results are used in multiple kernels (KKSPhaseChemicalPotential and KKSCHBulk).

A DerivativeFunctionMaterialBase provides numerous material properties which contain the free energy and its derivatives. The material property names are constructed dynamically by the helper functions propertyNameFirst(), propertyNameSecond(), and propertyNameThird() in DerivativeMaterialInterface.

A derived class needs to implement the computeF(), computeDF(), computeD2F(), and (optionally) computeD3F() methods.

Note that DerivativeParsedMaterial provides a material for which a mathematical free energy expression can be provided in the input file (with the derivatives being calculated automatically).

See also
KKSPhaseChemicalPotential
KKSCHBulk
DerivativeParsedMaterial
DerivativeMaterialInterface

Definition at line 42 of file DerivativeFunctionMaterialBase.h.

Constructor & Destructor Documentation

DerivativeFunctionMaterialBase::DerivativeFunctionMaterialBase ( const InputParameters &  parameters)

Definition at line 29 of file DerivativeFunctionMaterialBase.C.

30  : FunctionMaterialBase(parameters),
31  _third_derivatives(isParamValid("third_derivatives")
32  ? getParam<bool>("third_derivatives")
33  : (getParam<unsigned int>("derivative_order") == 3))
34 {
35  // reserve space for material properties and explicitly initialize to NULL
36  _prop_dF.resize(_nargs, NULL);
37  _prop_d2F.resize(_nargs);
38  _prop_d3F.resize(_nargs);
39  for (unsigned int i = 0; i < _nargs; ++i)
40  {
41  _prop_d2F[i].resize(_nargs, NULL);
42 
44  {
45  _prop_d3F[i].resize(_nargs);
46 
47  for (unsigned int j = 0; j < _nargs; ++j)
48  _prop_d3F[i][j].resize(_nargs, NULL);
49  }
50  }
51 
52  // initialize derivatives
53  for (unsigned int i = 0; i < _nargs; ++i)
54  {
55  // first derivatives
56  _prop_dF[i] = &declarePropertyDerivative<Real>(_F_name, _arg_names[i]);
57 
58  // second derivatives
59  for (unsigned int j = i; j < _nargs; ++j)
60  {
61  _prop_d2F[i][j] = _prop_d2F[j][i] =
62  &declarePropertyDerivative<Real>(_F_name, _arg_names[i], _arg_names[j]);
63 
64  // third derivatives
66  {
67  for (unsigned int k = j; k < _nargs; ++k)
68  {
69  // filling all permutations does not cost us much and simplifies access
70  // (no need to check i<=j<=k)
71  _prop_d3F[i][j][k] = _prop_d3F[k][i][j] = _prop_d3F[j][k][i] = _prop_d3F[k][j][i] =
72  _prop_d3F[j][i][k] = _prop_d3F[i][k][j] = &declarePropertyDerivative<Real>(
73  _F_name, _arg_names[i], _arg_names[j], _arg_names[k]);
74  }
75  }
76  }
77  }
78 }
std::vector< std::vector< MaterialProperty< Real > * > > _prop_d2F
Material properties to store the second derivatives.
FunctionMaterialBase(const InputParameters &parameters)
std::vector< std::vector< std::vector< MaterialProperty< Real > * > > > _prop_d3F
Material properties to store the third derivatives.
bool _third_derivatives
Calculate (and allocate memory for) the third derivatives of the free energy.
unsigned int _nargs
Number of coupled arguments.
std::vector< MaterialProperty< Real > * > _prop_dF
Material properties to store the derivatives of f with respect to arg[i].
std::string _F_name
Name of the function value material property and used as a base name to concatenate the material prop...
std::vector< std::string > _arg_names
String vector of all argument names.

Member Function Documentation

unsigned int FunctionMaterialBase::argIndex ( unsigned int  i_var) const
inlineprotectedinherited

FunctionMaterialBase keeps an internal list of all the variables the derivatives are taken w.r.t.

We provide the MOOSE variable bames in _arg_names, the libMesh variable numbers in _arg_numbers, and the input file parameter names in _arg_param_names. All are indexed by the argument index. This method returns the argument index for a given the libMesh variable number.

This mapping is necessary for internal classes which maintain lists of derivatives indexed by argument index and need to pull from those lists from the computeDF, computeD2F, and computeD3F methods, which receive libMesh variable numbers as parameters.

Definition at line 43 of file FunctionMaterialBase.h.

Referenced by DerivativeMultiPhaseMaterial::computeD2F(), ElasticEnergyMaterial::computeD2F(), DerivativeTwoPhaseMaterial::computeD2F(), DerivativeMultiPhaseMaterial::computeD3F(), DerivativeTwoPhaseMaterial::computeD3F(), DerivativeMultiPhaseMaterial::computeDF(), ElasticEnergyMaterial::computeDF(), DerivativeTwoPhaseMaterial::computeDF(), DerivativeMultiPhaseBase::DerivativeMultiPhaseBase(), and DiscreteNucleation::DiscreteNucleation().

44  {
45  const unsigned int idx = libMeshVarNumberRemap(i_var);
46  mooseAssert(idx < _arg_index.size() && _arg_numbers[_arg_index[idx]] == i_var,
47  "Requesting argIndex() for a derivative w.r.t. a variable not coupled to.");
48  return _arg_index[idx];
49  }
std::vector< unsigned int > _arg_index
Vector to look up the internal coupled variable index into arg* through the libMesh variable number...
unsigned int libMeshVarNumberRemap(unsigned int var) const
map the variable numbers to an even/odd interspersed pattern
std::vector< unsigned int > _arg_numbers
Vector of all argument MOOSE variable numbers.
virtual Real DerivativeFunctionMaterialBase::computeD2F ( unsigned int  arg1,
unsigned int  arg2 
)
inlineprotectedvirtual

Override this method to calculate the second derivatives.

\( \frac{d^2F}{dc_{arg1} dc_{arg2}} \)

Parameters
arg1The variable the first derivative is taken of
arg2The variable the second derivative is taken of

Reimplemented in DerivativeTwoPhaseMaterial, ElasticEnergyMaterial, MathFreeEnergy, DerivativeMultiPhaseMaterial, and KKSXeVacSolidMaterial.

Definition at line 82 of file DerivativeFunctionMaterialBase.h.

Referenced by computeProperties().

83  {
84  libmesh_ignore(arg1);
85  libmesh_ignore(arg2);
86  return 0.0;
87  }
virtual Real DerivativeFunctionMaterialBase::computeD3F ( unsigned int  ,
unsigned int  ,
unsigned int   
)
inlineprotectedvirtual

Override this method to calculate the third derivatives.

Note
The implementation of this method is optional. It is only evaluated when the 'third_derivatives' parameter is set to true.

Reimplemented in DerivativeTwoPhaseMaterial, MathFreeEnergy, and DerivativeMultiPhaseMaterial.

Definition at line 95 of file DerivativeFunctionMaterialBase.h.

Referenced by computeProperties().

95 { return 0.0; }
virtual Real DerivativeFunctionMaterialBase::computeDF ( unsigned int  arg)
inlineprotectedvirtual

Override this method for calculating the first derivatives.

The parameter is the libMesh variable number of the coupled variable. These numbers can be obtained using the coupled() method for each coupled variable.

Parameters
argThe index of the function argument the derivative is taken of

Reimplemented in DerivativeTwoPhaseMaterial, ElasticEnergyMaterial, MathFreeEnergy, DerivativeMultiPhaseMaterial, and KKSXeVacSolidMaterial.

Definition at line 68 of file DerivativeFunctionMaterialBase.h.

Referenced by computeProperties().

69  {
70  libmesh_ignore(arg);
71  return 0.0;
72  }
virtual Real DerivativeFunctionMaterialBase::computeF ( )
inlineprotectedvirtual

Override this method to provide the free energy function.

Reimplemented in DerivativeMultiPhaseBase, DerivativeTwoPhaseMaterial, ElasticEnergyMaterial, MathFreeEnergy, and KKSXeVacSolidMaterial.

Definition at line 59 of file DerivativeFunctionMaterialBase.h.

Referenced by computeProperties().

59 { return 0.0; }
void DerivativeFunctionMaterialBase::computeProperties ( )
protectedvirtual

Reimplemented in DiscreteNucleation, and DerivativeSumMaterial.

Definition at line 124 of file DerivativeFunctionMaterialBase.C.

125 {
126  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
127  {
128  // set function value
129  if (_prop_F)
130  (*_prop_F)[_qp] = computeF();
131 
132  for (unsigned int i = 0; i < _nargs; ++i)
133  {
134  // set first derivatives
135  if (_prop_dF[i])
136  (*_prop_dF[i])[_qp] = computeDF(_arg_numbers[i]);
137 
138  // second derivatives
139  for (unsigned int j = i; j < _nargs; ++j)
140  {
141  if (_prop_d2F[i][j])
142  (*_prop_d2F[i][j])[_qp] = computeD2F(_arg_numbers[i], _arg_numbers[j]);
143 
144  // third derivatives
145  if (_third_derivatives)
146  {
147  for (unsigned int k = j; k < _nargs; ++k)
148  if (_prop_d3F[i][j][k])
149  (*_prop_d3F[i][j][k])[_qp] =
151  }
152  }
153  }
154  }
155 }
std::vector< std::vector< MaterialProperty< Real > * > > _prop_d2F
Material properties to store the second derivatives.
virtual Real computeD2F(unsigned int arg1, unsigned int arg2)
Override this method to calculate the second derivatives.
std::vector< std::vector< std::vector< MaterialProperty< Real > * > > > _prop_d3F
Material properties to store the third derivatives.
MaterialProperty< Real > * _prop_F
Material property to store the function value.
virtual Real computeD3F(unsigned int, unsigned int, unsigned int)
Override this method to calculate the third derivatives.
virtual Real computeF()
Override this method to provide the free energy function.
bool _third_derivatives
Calculate (and allocate memory for) the third derivatives of the free energy.
unsigned int _nargs
Number of coupled arguments.
std::vector< MaterialProperty< Real > * > _prop_dF
Material properties to store the derivatives of f with respect to arg[i].
virtual Real computeDF(unsigned int arg)
Override this method for calculating the first derivatives.
std::vector< unsigned int > _arg_numbers
Vector of all argument MOOSE variable numbers.
void DerivativeFunctionMaterialBase::initialSetup ( )
protectedvirtual

Check if we got the right number of components in the 'args' coupled variable vector.

Reimplemented in DerivativeMultiPhaseBase, DerivativeTwoPhaseMaterial, ElasticEnergyMaterial, and DerivativeSumMaterial.

Definition at line 81 of file DerivativeFunctionMaterialBase.C.

82 {
83  // set the _prop_* pointers of all material properties that are not beeing used back to NULL
84  bool needs_third_derivatives = false;
85 
86  if (!_fe_problem.isMatPropRequested(_F_name))
87  _prop_F = NULL;
88 
89  for (unsigned int i = 0; i < _nargs; ++i)
90  {
91  if (!_fe_problem.isMatPropRequested(propertyNameFirst(_F_name, _arg_names[i])))
92  _prop_dF[i] = NULL;
93 
94  // second derivatives
95  for (unsigned int j = i; j < _nargs; ++j)
96  {
97  if (!_fe_problem.isMatPropRequested(
98  propertyNameSecond(_F_name, _arg_names[i], _arg_names[j])))
99  _prop_d2F[i][j] = _prop_d2F[j][i] = NULL;
100 
101  // third derivatives
102  if (_third_derivatives)
103  {
104  for (unsigned int k = j; k < _nargs; ++k)
105  {
106  if (!_fe_problem.isMatPropRequested(
107  propertyNameThird(_F_name, _arg_names[i], _arg_names[j], _arg_names[k])))
108  _prop_d3F[i][j][k] = _prop_d3F[k][i][j] = _prop_d3F[j][k][i] = _prop_d3F[k][j][i] =
109  _prop_d3F[j][i][k] = _prop_d3F[i][k][j] = NULL;
110  else
111  needs_third_derivatives = true;
112  }
113 
114  if (!needs_third_derivatives)
115  mooseWarning("This simulation does not actually need the third derivatives of "
116  "DerivativeFunctionMaterialBase " +
117  name());
118  }
119  }
120  }
121 }
std::vector< std::vector< MaterialProperty< Real > * > > _prop_d2F
Material properties to store the second derivatives.
std::vector< std::vector< std::vector< MaterialProperty< Real > * > > > _prop_d3F
Material properties to store the third derivatives.
MaterialProperty< Real > * _prop_F
Material property to store the function value.
bool _third_derivatives
Calculate (and allocate memory for) the third derivatives of the free energy.
unsigned int _nargs
Number of coupled arguments.
std::vector< MaterialProperty< Real > * > _prop_dF
Material properties to store the derivatives of f with respect to arg[i].
std::string _F_name
Name of the function value material property and used as a base name to concatenate the material prop...
std::vector< std::string > _arg_names
String vector of all argument names.

Member Data Documentation

std::vector<std::string> FunctionMaterialBase::_arg_constant_defaults
protectedinherited

coupled variables with default values

Definition at line 76 of file FunctionMaterialBase.h.

Referenced by FunctionMaterialBase::FunctionMaterialBase(), and ParsedMaterialHelper::functionParse().

std::vector<std::string> FunctionMaterialBase::_arg_names
protectedinherited
std::vector<unsigned int> FunctionMaterialBase::_arg_numbers
protectedinherited

Vector of all argument MOOSE variable numbers.

Definition at line 70 of file FunctionMaterialBase.h.

Referenced by FunctionMaterialBase::argIndex(), computeProperties(), and FunctionMaterialBase::FunctionMaterialBase().

std::vector<std::string> FunctionMaterialBase::_arg_param_names
protectedinherited

String vector of the input file coupling parameter name for each argument.

Definition at line 73 of file FunctionMaterialBase.h.

Referenced by FunctionMaterialBase::FunctionMaterialBase(), and ParsedMaterialHelper::functionParse().

std::vector<const VariableValue *> FunctionMaterialBase::_args
protectedinherited
std::string FunctionMaterialBase::_F_name
protectedinherited

Name of the function value material property and used as a base name to concatenate the material property names for the derivatives.

Definition at line 58 of file FunctionMaterialBase.h.

Referenced by DerivativeParsedMaterialHelper::assembleDerivatives(), DerivativeFunctionMaterialBase(), and initialSetup().

bool FunctionMaterialBase::_mapping_is_unique
protectedinherited

Flag that indicates if exactly one linear variable is coupled per input file coupling parameter.

Definition at line 61 of file FunctionMaterialBase.h.

Referenced by FunctionMaterialBase::FunctionMaterialBase(), and ParsedMaterialHelper::functionParse().

unsigned int FunctionMaterialBase::_nargs
protectedinherited
std::vector<std::vector<MaterialProperty<Real> *> > DerivativeFunctionMaterialBase::_prop_d2F
protected
std::vector<std::vector<std::vector<MaterialProperty<Real> *> > > DerivativeFunctionMaterialBase::_prop_d3F
protected
std::vector<MaterialProperty<Real> *> DerivativeFunctionMaterialBase::_prop_dF
protected

Material properties to store the derivatives of f with respect to arg[i].

Definition at line 101 of file DerivativeFunctionMaterialBase.h.

Referenced by DerivativeSumMaterial::computeProperties(), DiscreteNucleation::computeProperties(), computeProperties(), DerivativeFunctionMaterialBase(), and initialSetup().

MaterialProperty<Real>* FunctionMaterialBase::_prop_F
protectedinherited
bool DerivativeFunctionMaterialBase::_third_derivatives
protected

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