www.mooseframework.org
DerivativeMultiPhaseBase.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
14 {
16 
17  // Phase materials 1-n
18  params.addRequiredParam<std::vector<MaterialPropertyName>>(
19  "fi_names", "List of free energies for the n phases");
20  params.addParam<std::vector<MaterialPropertyName>>(
21  "hi_names", "Switching Function Materials that provide h(eta_i)");
22 
23  // All arguments of the phase free energies
24  params.addCoupledVar("args", "Vector of variable arguments of the fi free energies");
25  params.deprecateCoupledVar("args", "coupled_variables", "02/27/2024");
26  params.addCoupledVar("displacement_gradients",
27  "Vector of displacement gradient variables (see "
28  "Modules/PhaseField/DisplacementGradients "
29  "action)");
30 
31  // Barrier
32  params.addParam<MaterialPropertyName>(
33  "g", "g", "Barrier Function Material that provides g(eta_i)");
34  params.addParam<Real>("W", 0.0, "Energy barrier for the phase transformation from A to B");
35 
36  return params;
37 }
38 
40  : DerivativeFunctionMaterialBase(parameters),
41  _eta_index(_nargs, -1),
42  _num_etas(coupledComponents("etas")),
43  _eta_names(_num_etas),
44  _eta_vars(_num_etas),
45  _fi_names(getParam<std::vector<MaterialPropertyName>>("fi_names")),
46  _num_fi(_fi_names.size()),
47  _prop_Fi(_num_fi),
48  _prop_dFi(_num_fi),
49  _prop_d2Fi(_num_fi),
50  _prop_d3Fi(_num_fi),
51  _hi_names(getParam<std::vector<MaterialPropertyName>>("hi_names")),
52  _num_hi(_hi_names.size()),
53  _hi(_num_hi),
54  _g(getMaterialProperty<Real>("g")),
55  _dg(_num_etas),
56  _d2g(_num_etas),
57  _d3g(_num_etas),
58  _W(getParam<Real>("W"))
59 {
60  // check passed in parameter vectors
61  if (_num_fi != _num_hi)
62  mooseError("Need to pass in as many hi_names as fi_names in DerivativeMultiPhaseBase ", name());
63 
64  // get order parameter names and libmesh variable names, set barrier function derivatives
65  for (unsigned int i = 0; i < _num_etas; ++i)
66  {
67  _eta_names[i] = coupledName("etas", i);
68  _eta_vars[i] = coupled("etas", i);
69 
70  // for each coupled variable we need to know if it was coupled through "etas"
71  // and - if so - which coupled component of "etas" it comes from
72  _eta_index[argIndex(_eta_vars[i])] = i;
73 
74  // barrier function derivatives
75  _dg[i] = &getMaterialPropertyDerivative<Real>("g", _eta_names[i]);
76  _d2g[i].resize(_num_etas);
78  _d3g[i].resize(_num_etas);
79 
80  for (unsigned int j = 0; j < _num_etas; ++j)
81  {
82  _d2g[i][j] = &getMaterialPropertyDerivative<Real>("g", _eta_names[i], _eta_names[j]);
83 
85  {
86  _d3g[i][j].resize(_num_etas);
87  for (unsigned int k = 0; k < _num_etas; ++k)
88  _d3g[i][j][k] = &getMaterialPropertyDerivative<Real>(
89  "g", _eta_names[i], _eta_names[j], _eta_names[k]);
90  }
91  }
92  }
93 
94  // reserve space and set phase material properties
95  for (unsigned int n = 0; n < _num_fi; ++n)
96  {
97  // get phase free energy
98  _prop_Fi[n] = &getMaterialPropertyByName<Real>(_fi_names[n]);
99  _prop_dFi[n].resize(_nargs);
100  _prop_d2Fi[n].resize(_nargs);
101  _prop_d3Fi[n].resize(_nargs);
102 
103  // get switching function
104  _hi[n] = &getMaterialPropertyByName<Real>(_hi_names[n]);
105 
106  for (unsigned int i = 0; i < _nargs; ++i)
107  {
108  _prop_dFi[n][i] = &getMaterialPropertyDerivative<Real>(_fi_names[n], _arg_names[i]);
109  _prop_d2Fi[n][i].resize(_nargs);
110 
111  if (_third_derivatives)
112  _prop_d3Fi[n][i].resize(_nargs);
113 
114  for (unsigned int j = 0; j < _nargs; ++j)
115  {
116  _prop_d2Fi[n][i][j] =
117  &getMaterialPropertyDerivative<Real>(_fi_names[n], _arg_names[i], _arg_names[j]);
118 
119  if (_third_derivatives)
120  {
121  _prop_d3Fi[n][i][j].resize(_nargs);
122 
123  for (unsigned int k = 0; k < _nargs; ++k)
124  _prop_d3Fi[n][i][j][k] = &getMaterialPropertyDerivative<Real>(
126  }
127  }
128  }
129  }
130 }
131 
132 void
134 {
135  for (unsigned int n = 0; n < _num_fi; ++n)
136  validateCoupling<Real>(_fi_names[n]);
137 }
138 
139 Real
141 {
142  Real F = 0.0;
143  for (unsigned n = 0; n < _num_fi; ++n)
144  F += (*_hi[n])[_qp] * (*_prop_Fi[n])[_qp];
145  return F + _W * _g[_qp];
146 }
virtual unsigned int coupled(const std::string &var_name, unsigned int comp=0) const
std::vector< std::vector< std::vector< const MaterialProperty< Real > * > > > _prop_d2Fi
Second derivatives of Fi.
VariableName coupledName(const std::string &var_name, unsigned int comp=0) const
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
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
virtual const std::string & name() const
void addRequiredParam(const std::string &name, const std::string &doc_string)
std::vector< std::string > _arg_names
static const std::string F
Definition: NS.h:150
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.
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
void addCoupledVar(const std::string &name, const std::string &doc_string)
std::vector< VariableName > _eta_names
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
DerivativeMultiPhaseBase(const InputParameters &parameters)
std::vector< std::vector< const MaterialProperty< Real > * > > _d2g
void mooseError(Args &&... args) const
static InputParameters validParams()
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...
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
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].
static const std::string k
Definition: NS.h:124
std::vector< unsigned int > _eta_vars
static InputParameters validParams()