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

DerivativeMaterial child class to evaluate a parsed function for the free energy and automatically provide all derivatives. More...

#include <DerivativeMultiPhaseBase.h>

Inheritance diagram for DerivativeMultiPhaseBase:
[legend]

Public Member Functions

 DerivativeMultiPhaseBase (const InputParameters &parameters)
 
virtual void initialSetup ()
 Check if we got the right number of components in the 'args' coupled variable vector. More...
 

Protected Member Functions

virtual Real computeF ()
 Override this method to provide the free energy function. More...
 
virtual void computeProperties ()
 
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

std::vector< int > _eta_index
 If the variable a non-conserved OP this array holds the index into the etas parameter vector for a given arg index, otherwise it holds -1. More...
 
std::vector< VariableValue * > _etas
 Phase parameter (0=A-phase, 1=B-phase) More...
 
unsigned int _num_etas
 name of the order parameter variable More...
 
std::vector< VariableName > _eta_names
 
std::vector< unsigned int > _eta_vars
 
std::vector< MaterialPropertyName > _fi_names
 phase derivative material names More...
 
unsigned int _num_fi
 
std::vector< const MaterialProperty< Real > * > _prop_Fi
 Function value of the i phase. More...
 
std::vector< std::vector< const MaterialProperty< Real > * > > _prop_dFi
 Derivatives of Fi w.r.t. arg[i]. More...
 
std::vector< std::vector< std::vector< const MaterialProperty< Real > * > > > _prop_d2Fi
 Second derivatives of Fi. More...
 
std::vector< std::vector< std::vector< std::vector< const MaterialProperty< Real > * > > > > _prop_d3Fi
 Third derivatives of Fi. More...
 
std::vector< MaterialPropertyName > _hi_names
 phase switching function names More...
 
unsigned int _num_hi
 
std::vector< const MaterialProperty< Real > * > _hi
 Switching functions. More...
 
MaterialPropertyName _g_name
 Barrier function name. More...
 
const MaterialProperty< Real > & _g
 Barrier function \( g(\eta_0, \eta_1, \dots, \eta_{n-1}) \). More...
 
std::vector< const MaterialProperty< Real > * > _dg
 Barrier function derivatives. More...
 
std::vector< std::vector< const MaterialProperty< Real > * > > _d2g
 
std::vector< std::vector< std::vector< const MaterialProperty< Real > * > > > _d3g
 
Real _W
 Phase transformation energy barrier. More...
 
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

DerivativeMaterial child class to evaluate a parsed function for the free energy and automatically provide all derivatives.

This requires the autodiff patch (https://github.com/libMesh/libmesh/pull/238) to Function Parser in libmesh.

Definition at line 24 of file DerivativeMultiPhaseBase.h.

Constructor & Destructor Documentation

DerivativeMultiPhaseBase::DerivativeMultiPhaseBase ( const InputParameters &  parameters)

Definition at line 36 of file DerivativeMultiPhaseBase.C.

37  : DerivativeFunctionMaterialBase(parameters),
38  _eta_index(_nargs, -1),
39  _num_etas(coupledComponents("etas")),
42  _fi_names(getParam<std::vector<MaterialPropertyName>>("fi_names")),
43  _num_fi(_fi_names.size()),
48  _hi_names(getParam<std::vector<MaterialPropertyName>>("hi_names")),
49  _num_hi(_hi_names.size()),
50  _hi(_num_hi),
51  _g(getMaterialProperty<Real>("g")),
52  _dg(_num_etas),
53  _d2g(_num_etas),
54  _d3g(_num_etas),
55  _W(getParam<Real>("W"))
56 {
57  // check passed in parameter vectors
58  if (_num_fi != _num_hi)
59  mooseError("Need to pass in as many hi_names as fi_names in DerivativeMultiPhaseBase ", name());
60 
61  // get order parameter names and libmesh variable names, set barrier function derivatives
62  for (unsigned int i = 0; i < _num_etas; ++i)
63  {
64  _eta_names[i] = getVar("etas", i)->name();
65  _eta_vars[i] = coupled("etas", i);
66 
67  // for each coupled variable we need to know if it was coupled through "etas"
68  // and - if so - which coupled component of "etas" it comes from
69  _eta_index[argIndex(_eta_vars[i])] = i;
70 
71  // barrier function derivatives
72  _dg[i] = &getMaterialPropertyDerivative<Real>("g", _eta_names[i]);
73  _d2g[i].resize(_num_etas);
75  _d3g[i].resize(_num_etas);
76 
77  for (unsigned int j = 0; j < _num_etas; ++j)
78  {
79  _d2g[i][j] = &getMaterialPropertyDerivative<Real>("g", _eta_names[i], _eta_names[j]);
80 
82  {
83  _d3g[i][j].resize(_num_etas);
84  for (unsigned int k = 0; k < _num_etas; ++k)
85  _d3g[i][j][k] = &getMaterialPropertyDerivative<Real>(
86  "g", _eta_names[i], _eta_names[j], _eta_names[k]);
87  }
88  }
89  }
90 
91  // reserve space and set phase material properties
92  for (unsigned int n = 0; n < _num_fi; ++n)
93  {
94  // get phase free energy
95  _prop_Fi[n] = &getMaterialPropertyByName<Real>(_fi_names[n]);
96  _prop_dFi[n].resize(_nargs);
97  _prop_d2Fi[n].resize(_nargs);
98  _prop_d3Fi[n].resize(_nargs);
99 
100  // get switching function
101  _hi[n] = &getMaterialPropertyByName<Real>(_hi_names[n]);
102 
103  for (unsigned int i = 0; i < _nargs; ++i)
104  {
105  _prop_dFi[n][i] = &getMaterialPropertyDerivative<Real>(_fi_names[n], _arg_names[i]);
106  _prop_d2Fi[n][i].resize(_nargs);
107 
108  if (_third_derivatives)
109  _prop_d3Fi[n][i].resize(_nargs);
110 
111  for (unsigned int j = 0; j < _nargs; ++j)
112  {
113  _prop_d2Fi[n][i][j] =
114  &getMaterialPropertyDerivative<Real>(_fi_names[n], _arg_names[i], _arg_names[j]);
115 
116  if (_third_derivatives)
117  {
118  _prop_d3Fi[n][i][j].resize(_nargs);
119 
120  for (unsigned int k = 0; k < _nargs; ++k)
121  _prop_d3Fi[n][i][j][k] = &getMaterialPropertyDerivative<Real>(
122  _fi_names[n], _arg_names[i], _arg_names[j], _arg_names[k]);
123  }
124  }
125  }
126  }
127 }
DerivativeFunctionMaterialBase(const InputParameters &parameters)
std::vector< std::vector< std::vector< const MaterialProperty< Real > * > > > _prop_d2Fi
Second derivatives of Fi.
std::vector< std::vector< std::vector< const MaterialProperty< Real > * > > > _d3g
std::vector< const MaterialProperty< Real > * > _dg
Barrier function derivatives.
const MaterialProperty< Real > & _g
Barrier function .
std::vector< MaterialPropertyName > _hi_names
phase switching function names
unsigned int _num_etas
name of the order parameter variable
std::vector< std::vector< std::vector< std::vector< const MaterialProperty< Real > * > > > > _prop_d3Fi
Third derivatives of Fi.
Real _W
Phase transformation energy barrier.
std::vector< MaterialPropertyName > _fi_names
phase derivative material names
std::vector< const MaterialProperty< Real > * > _hi
Switching functions.
bool _third_derivatives
Calculate (and allocate memory for) the third derivatives of the free energy.
unsigned int _nargs
Number of coupled arguments.
std::vector< VariableName > _eta_names
std::vector< std::vector< const MaterialProperty< Real > * > > _d2g
std::vector< std::string > _arg_names
String vector of all argument names.
std::vector< int > _eta_index
If the variable a non-conserved OP this array holds the index into the etas parameter vector for a gi...
std::vector< const MaterialProperty< Real > * > _prop_Fi
Function value of the i phase.
std::vector< std::vector< const MaterialProperty< Real > * > > _prop_dFi
Derivatives of Fi w.r.t. arg[i].
std::vector< unsigned int > _eta_vars
unsigned int argIndex(unsigned int i_var) const
FunctionMaterialBase keeps an internal list of all the variables the derivatives are taken w...

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(), 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 
)
inlineprotectedvirtualinherited

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 DerivativeFunctionMaterialBase::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   
)
inlineprotectedvirtualinherited

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 DerivativeFunctionMaterialBase::computeProperties().

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

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 DerivativeFunctionMaterialBase::computeProperties().

69  {
70  libmesh_ignore(arg);
71  return 0.0;
72  }
Real DerivativeMultiPhaseBase::computeF ( )
protectedvirtual

Override this method to provide the free energy function.

Reimplemented from DerivativeFunctionMaterialBase.

Definition at line 137 of file DerivativeMultiPhaseBase.C.

138 {
139  Real F = 0.0;
140  for (unsigned n = 0; n < _num_fi; ++n)
141  F += (*_hi[n])[_qp] * (*_prop_Fi[n])[_qp];
142  return F + _W * _g[_qp];
143 }
const MaterialProperty< Real > & _g
Barrier function .
Real _W
Phase transformation energy barrier.
std::vector< const MaterialProperty< Real > * > _hi
Switching functions.
std::vector< const MaterialProperty< Real > * > _prop_Fi
Function value of the i phase.
void DerivativeFunctionMaterialBase::computeProperties ( )
protectedvirtualinherited

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 DerivativeMultiPhaseBase::initialSetup ( )
virtual

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

Reimplemented from DerivativeFunctionMaterialBase.

Definition at line 130 of file DerivativeMultiPhaseBase.C.

131 {
132  for (unsigned int n = 0; n < _num_fi; ++n)
133  validateCoupling<Real>(_fi_names[n]);
134 }
std::vector< MaterialPropertyName > _fi_names
phase derivative material 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(), DerivativeFunctionMaterialBase::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::vector<std::vector<const MaterialProperty<Real> *> > DerivativeMultiPhaseBase::_d2g
protected
std::vector<std::vector<std::vector<const MaterialProperty<Real> *> > > DerivativeMultiPhaseBase::_d3g
protected
std::vector<const MaterialProperty<Real> *> DerivativeMultiPhaseBase::_dg
protected

Barrier function derivatives.

Definition at line 78 of file DerivativeMultiPhaseBase.h.

Referenced by DerivativeMultiPhaseMaterial::computeDF(), and DerivativeMultiPhaseBase().

std::vector<int> DerivativeMultiPhaseBase::_eta_index
protected

If the variable a non-conserved OP this array holds the index into the etas parameter vector for a given arg index, otherwise it holds -1.

Definition at line 38 of file DerivativeMultiPhaseBase.h.

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

std::vector<VariableName> DerivativeMultiPhaseBase::_eta_names
protected
std::vector<unsigned int> DerivativeMultiPhaseBase::_eta_vars
protected

Definition at line 46 of file DerivativeMultiPhaseBase.h.

Referenced by DerivativeMultiPhaseBase().

std::vector<VariableValue *> DerivativeMultiPhaseBase::_etas
protected

Phase parameter (0=A-phase, 1=B-phase)

Definition at line 41 of file DerivativeMultiPhaseBase.h.

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::DerivativeFunctionMaterialBase(), and DerivativeFunctionMaterialBase::initialSetup().

std::vector<MaterialPropertyName> DerivativeMultiPhaseBase::_fi_names
protected

phase derivative material names

Definition at line 49 of file DerivativeMultiPhaseBase.h.

Referenced by DerivativeMultiPhaseBase(), and initialSetup().

const MaterialProperty<Real>& DerivativeMultiPhaseBase::_g
protected

Barrier function \( g(\eta_0, \eta_1, \dots, \eta_{n-1}) \).

Definition at line 75 of file DerivativeMultiPhaseBase.h.

Referenced by computeF().

MaterialPropertyName DerivativeMultiPhaseBase::_g_name
protected

Barrier function name.

Definition at line 72 of file DerivativeMultiPhaseBase.h.

std::vector<const MaterialProperty<Real> *> DerivativeMultiPhaseBase::_hi
protected
std::vector<MaterialPropertyName> DerivativeMultiPhaseBase::_hi_names
protected

phase switching function names

Definition at line 65 of file DerivativeMultiPhaseBase.h.

Referenced by DerivativeMultiPhaseBase(), and DerivativeMultiPhaseMaterial::DerivativeMultiPhaseMaterial().

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
unsigned int DerivativeMultiPhaseBase::_num_etas
protected

name of the order parameter variable

Definition at line 44 of file DerivativeMultiPhaseBase.h.

Referenced by DerivativeMultiPhaseBase(), and DerivativeMultiPhaseMaterial::DerivativeMultiPhaseMaterial().

unsigned int DerivativeMultiPhaseBase::_num_fi
protected
unsigned int DerivativeMultiPhaseBase::_num_hi
protected
std::vector<std::vector<MaterialProperty<Real> *> > DerivativeFunctionMaterialBase::_prop_d2F
protectedinherited
std::vector<std::vector<std::vector<const MaterialProperty<Real> *> > > DerivativeMultiPhaseBase::_prop_d2Fi
protected
std::vector<std::vector<std::vector<MaterialProperty<Real> *> > > DerivativeFunctionMaterialBase::_prop_d3F
protectedinherited
std::vector<std::vector<std::vector<std::vector<const MaterialProperty<Real> *> > > > DerivativeMultiPhaseBase::_prop_d3Fi
protected

Third derivatives of Fi.

Definition at line 62 of file DerivativeMultiPhaseBase.h.

Referenced by DerivativeMultiPhaseMaterial::computeD3F(), and DerivativeMultiPhaseBase().

std::vector<MaterialProperty<Real> *> DerivativeFunctionMaterialBase::_prop_dF
protectedinherited
std::vector<std::vector<const MaterialProperty<Real> *> > DerivativeMultiPhaseBase::_prop_dFi
protected
MaterialProperty<Real>* FunctionMaterialBase::_prop_F
protectedinherited
std::vector<const MaterialProperty<Real> *> DerivativeMultiPhaseBase::_prop_Fi
protected
bool DerivativeFunctionMaterialBase::_third_derivatives
protectedinherited
Real DerivativeMultiPhaseBase::_W
protected

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