https://mooseframework.inl.gov
DerivativeTwoPhaseMaterial.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
11 
13 
16 {
18  params.addClassDescription(
19  "Two phase material that combines two single phase materials using a switching function.");
20 
21  // Two base materials
22  params.addRequiredParam<MaterialPropertyName>("fa_name", "Phase A material (at eta=0)");
23  params.addRequiredParam<MaterialPropertyName>("fb_name", "Phase A material (at eta=1)");
24  params.addParam<MaterialPropertyName>(
25  "h", "h", "Switching Function Material that provides h(eta)");
26  params.addParam<MaterialPropertyName>("g", "g", "Barrier Function Material that provides g(eta)");
27 
28  // All arguments of the phase free energies
29  params.addCoupledVar("args", "Vector of variable arguments of fa and fb");
30  params.deprecateCoupledVar("args", "coupled_variables", "02/27/2024");
31  params.addCoupledVar("displacement_gradients",
32  "Vector of displacement gradient variables (see "
33  "Modules/PhaseField/DisplacementGradients "
34  "action)");
35 
36  // Order parameter which determines the phase
37  params.addRequiredCoupledVar("eta", "Order parameter");
38 
39  // Variables with applied tolerances and their tolerance values
40  params.addParam<Real>("W", 0.0, "Energy barrier for the phase transformation from A to B");
41 
42  return params;
43 }
44 
46  : DerivativeFunctionMaterialBase(parameters),
47  _eta(coupledValue("eta")),
48  _eta_name(coupledName("eta", 0)),
49  _eta_var(coupled("eta")),
50  _h(getMaterialProperty<Real>("h")),
51  _dh(getMaterialPropertyDerivative<Real>("h", _eta_name)),
52  _d2h(getMaterialPropertyDerivative<Real>("h", _eta_name, _eta_name)),
53  _d3h(getMaterialPropertyDerivative<Real>("h", _eta_name, _eta_name, _eta_name)),
54  _g(getMaterialProperty<Real>("g")),
55  _dg(getMaterialPropertyDerivative<Real>("g", _eta_name)),
56  _d2g(getMaterialPropertyDerivative<Real>("g", _eta_name, _eta_name)),
57  _d3g(getMaterialPropertyDerivative<Real>("g", _eta_name, _eta_name, _eta_name)),
58  _W(getParam<Real>("W")),
59  _prop_Fa(getMaterialProperty<Real>("fa_name")),
60  _prop_Fb(getMaterialProperty<Real>("fb_name"))
61 {
62  // reserve space for phase A and B material properties
63  _prop_dFa.resize(_nargs);
64  _prop_d2Fa.resize(_nargs);
65  _prop_d3Fa.resize(_nargs);
66  _prop_dFb.resize(_nargs);
67  _prop_d2Fb.resize(_nargs);
68  _prop_d3Fb.resize(_nargs);
69  for (unsigned int i = 0; i < _nargs; ++i)
70  {
71  _prop_dFa[i] = &getMaterialPropertyDerivative<Real>("fa_name", _arg_names[i]);
72  _prop_dFb[i] = &getMaterialPropertyDerivative<Real>("fb_name", _arg_names[i]);
73 
74  _prop_d2Fa[i].resize(_nargs);
75  _prop_d2Fb[i].resize(_nargs);
76 
77  // TODO: maybe we should reserve and initialize to NULL...
79  {
80  _prop_d3Fa[i].resize(_nargs);
81  _prop_d3Fb[i].resize(_nargs);
82  }
83 
84  for (unsigned int j = 0; j < _nargs; ++j)
85  {
86  _prop_d2Fa[i][j] =
87  &getMaterialPropertyDerivative<Real>("fa_name", _arg_names[i], _arg_names[j]);
88  _prop_d2Fb[i][j] =
89  &getMaterialPropertyDerivative<Real>("fb_name", _arg_names[i], _arg_names[j]);
90 
92  {
93  _prop_d3Fa[i][j].resize(_nargs);
94  _prop_d3Fb[i][j].resize(_nargs);
95 
96  for (unsigned int k = 0; k < _nargs; ++k)
97  {
98  _prop_d3Fa[i][j][k] = &getMaterialPropertyDerivative<Real>(
99  "fa_name", _arg_names[i], _arg_names[j], _arg_names[k]);
100  _prop_d3Fb[i][j][k] = &getMaterialPropertyDerivative<Real>(
101  "fb_name", _arg_names[i], _arg_names[j], _arg_names[k]);
102  }
103  }
104  }
105  }
106 }
107 
108 void
110 {
111  validateCoupling<Real>("fa_name");
112  validateCoupling<Real>("fb_name");
113 }
114 
115 Real
117 {
118  return _h[_qp] * _prop_Fb[_qp] + (1.0 - _h[_qp]) * _prop_Fa[_qp] + _W * _g[_qp];
119 }
120 
121 Real
123 {
124  if (i_var == _eta_var)
125  return _dh[_qp] * (_prop_Fb[_qp] - _prop_Fa[_qp]) + _W * _dg[_qp];
126  else
127  {
128  unsigned int i = argIndex(i_var);
129  return _h[_qp] * (*_prop_dFb[i])[_qp] + (1.0 - _h[_qp]) * (*_prop_dFa[i])[_qp];
130  }
131 }
132 
133 Real
134 DerivativeTwoPhaseMaterial::computeD2F(unsigned int i_var, unsigned int j_var)
135 {
136  if (i_var == _eta_var && j_var == _eta_var)
137  return _d2h[_qp] * (_prop_Fb[_qp] - _prop_Fa[_qp]) + _W * _d2g[_qp];
138 
139  unsigned int i = argIndex(i_var);
140  unsigned int j = argIndex(j_var);
141 
142  if (i_var == _eta_var)
143  return _dh[_qp] * ((*_prop_dFb[j])[_qp] - (*_prop_dFa[j])[_qp]);
144  if (j_var == _eta_var)
145  return _dh[_qp] * ((*_prop_dFb[i])[_qp] - (*_prop_dFa[i])[_qp]);
146 
147  return _h[_qp] * (*_prop_d2Fb[i][j])[_qp] + (1.0 - _h[_qp]) * (*_prop_d2Fa[i][j])[_qp];
148 }
149 
150 Real
151 DerivativeTwoPhaseMaterial::computeD3F(unsigned int i_var, unsigned int j_var, unsigned int k_var)
152 {
153  if (i_var == _eta_var && j_var == _eta_var && k_var == _eta_var)
154  return _d3h[_qp] * (_prop_Fb[_qp] - _prop_Fa[_qp]) + _W * _d3g[_qp];
155 
156  unsigned int i = argIndex(i_var);
157  unsigned int j = argIndex(j_var);
158  unsigned int k = argIndex(k_var);
159 
160  if (j_var == _eta_var && k_var == _eta_var)
161  return _d2h[_qp] * ((*_prop_dFb[i])[_qp] - (*_prop_dFa[i])[_qp]);
162  if (i_var == _eta_var && k_var == _eta_var)
163  return _d2h[_qp] * ((*_prop_dFb[j])[_qp] - (*_prop_dFa[j])[_qp]);
164  if (i_var == _eta_var && j_var == _eta_var)
165  return _d2h[_qp] * ((*_prop_dFb[k])[_qp] - (*_prop_dFa[k])[_qp]);
166 
167  if (i_var == _eta_var)
168  return _dh[_qp] * (*_prop_d2Fb[j][k])[_qp] + (1.0 - _dh[_qp]) * (*_prop_d2Fa[j][k])[_qp];
169  if (j_var == _eta_var)
170  return _dh[_qp] * (*_prop_d2Fb[i][k])[_qp] + (1.0 - _dh[_qp]) * (*_prop_d2Fa[i][k])[_qp];
171  if (k_var == _eta_var)
172  return _dh[_qp] * (*_prop_d2Fb[i][j])[_qp] + (1.0 - _dh[_qp]) * (*_prop_d2Fa[i][j])[_qp];
173 
174  return _h[_qp] * (*_prop_d3Fb[i][j][k])[_qp] + (1.0 - _h[_qp]) * (*_prop_d3Fa[i][j][k])[_qp];
175 }
virtual Real computeDF(unsigned int i_var) override
DerivativeTwoPhaseMaterial(const InputParameters &parameters)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
const MaterialProperty< Real > & _dh
const MaterialProperty< Real > & _d3g
const MaterialProperty< Real > & _prop_Fa
Function value of the A and B phase.
std::vector< std::vector< const MaterialProperty< Real > * > > _prop_d2Fa
Second derivatives of Fa and Fb.
const MaterialProperty< Real > & _g
std::vector< const MaterialProperty< Real > * > _prop_dFb
virtual Real computeD3F(unsigned int i_var, unsigned int j_var, unsigned int k_var) override
void addRequiredParam(const std::string &name, const std::string &doc_string)
std::vector< std::string > _arg_names
std::vector< std::vector< std::vector< const MaterialProperty< Real > * > > > _prop_d3Fb
DerivativeMaterial child class to evaluate a parsed function for the free energy and automatically pr...
static InputParameters validParams()
const MaterialProperty< Real > & _d2h
std::vector< std::vector< std::vector< const MaterialProperty< Real > * > > > _prop_d3Fa
Third derivatives of Fa and Fb.
registerMooseObject("PhaseFieldApp", DerivativeTwoPhaseMaterial)
Real _W
Phase transformatuion energy barrier.
const MaterialProperty< Real > & _d3h
void deprecateCoupledVar(const std::string &old_name, const std::string &new_name, const std::string &removal_date)
unsigned int argIndex(unsigned int i_var) const
virtual void initialSetup() override
void addCoupledVar(const std::string &name, const std::string &doc_string)
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
const MaterialProperty< Real > & _h
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const MaterialProperty< Real > & _d2g
const MaterialProperty< Real > & _dg
void addClassDescription(const std::string &doc_string)
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
std::vector< const MaterialProperty< Real > * > _prop_dFa
Derivatives of Fa and Fb with respect to arg[i].
static const std::string k
Definition: NS.h:130
const MaterialProperty< Real > & _prop_Fb
unsigned int _eta_var
libMesh variable number for eta
virtual Real computeD2F(unsigned int i_var, unsigned int j_var) override
static InputParameters validParams()
std::vector< std::vector< const MaterialProperty< Real > * > > _prop_d2Fb