https://mooseframework.inl.gov
DerivativeMultiPhaseBase.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 
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("coupled_variables", "Vector of variable arguments of the fi free energies");
25  params.addCoupledVar("displacement_gradients",
26  "Vector of displacement gradient variables (see "
27  "Modules/PhaseField/DisplacementGradients "
28  "action)");
29 
30  // Barrier
31  params.addParam<MaterialPropertyName>(
32  "g", "g", "Barrier Function Material that provides g(eta_i)");
33  params.addParam<Real>("W", 0.0, "Energy barrier for the phase transformation from A to B");
34 
35  return params;
36 }
37 
39  : DerivativeFunctionMaterialBase(parameters),
40  _eta_index(_nargs, -1),
41  _num_etas(coupledComponents("etas")),
42  _eta_names(_num_etas),
43  _eta_vars(_num_etas),
44  _fi_names(getParam<std::vector<MaterialPropertyName>>("fi_names")),
45  _num_fi(_fi_names.size()),
46  _prop_Fi(_num_fi),
47  _prop_dFi(_num_fi),
48  _prop_d2Fi(_num_fi),
49  _prop_d3Fi(_num_fi),
50  _hi_names(getParam<std::vector<MaterialPropertyName>>("hi_names")),
51  _num_hi(_hi_names.size()),
52  _hi(_num_hi),
53  _g(getMaterialProperty<Real>("g")),
54  _dg(_num_etas),
55  _d2g(_num_etas),
56  _d3g(_num_etas),
57  _W(getParam<Real>("W"))
58 {
59  // check passed in parameter vectors
60  if (_num_fi != _num_hi)
61  mooseError("Need to pass in as many hi_names as fi_names in DerivativeMultiPhaseBase ", name());
62 
63  // get order parameter names and libmesh variable names, set barrier function derivatives
64  for (unsigned int i = 0; i < _num_etas; ++i)
65  {
66  _eta_names[i] = coupledName("etas", i);
67  _eta_vars[i] = coupled("etas", i);
68 
69  // for each coupled variable we need to know if it was coupled through "etas"
70  // and - if so - which coupled component of "etas" it comes from
71  _eta_index[argIndex(_eta_vars[i])] = i;
72 
73  // barrier function derivatives
74  _dg[i] = &getMaterialPropertyDerivative<Real>("g", _eta_names[i]);
75  _d2g[i].resize(_num_etas);
77  _d3g[i].resize(_num_etas);
78 
79  for (unsigned int j = 0; j < _num_etas; ++j)
80  {
81  _d2g[i][j] = &getMaterialPropertyDerivative<Real>("g", _eta_names[i], _eta_names[j]);
82 
84  {
85  _d3g[i][j].resize(_num_etas);
86  for (unsigned int k = 0; k < _num_etas; ++k)
87  _d3g[i][j][k] = &getMaterialPropertyDerivative<Real>(
88  "g", _eta_names[i], _eta_names[j], _eta_names[k]);
89  }
90  }
91  }
92 
93  // reserve space and set phase material properties
94  for (unsigned int n = 0; n < _num_fi; ++n)
95  {
96  // get phase free energy
97  _prop_Fi[n] = &getMaterialPropertyByName<Real>(_fi_names[n]);
98  _prop_dFi[n].resize(_nargs);
99  _prop_d2Fi[n].resize(_nargs);
100  _prop_d3Fi[n].resize(_nargs);
101 
102  // get switching function
103  _hi[n] = &getMaterialPropertyByName<Real>(_hi_names[n]);
104 
105  for (unsigned int i = 0; i < _nargs; ++i)
106  {
107  _prop_dFi[n][i] = &getMaterialPropertyDerivative<Real>(_fi_names[n], _arg_names[i]);
108  _prop_d2Fi[n][i].resize(_nargs);
109 
110  if (_third_derivatives)
111  _prop_d3Fi[n][i].resize(_nargs);
112 
113  for (unsigned int j = 0; j < _nargs; ++j)
114  {
115  _prop_d2Fi[n][i][j] =
116  &getMaterialPropertyDerivative<Real>(_fi_names[n], _arg_names[i], _arg_names[j]);
117 
118  if (_third_derivatives)
119  {
120  _prop_d3Fi[n][i][j].resize(_nargs);
121 
122  for (unsigned int k = 0; k < _nargs; ++k)
123  _prop_d3Fi[n][i][j][k] = &getMaterialPropertyDerivative<Real>(
125  }
126  }
127  }
128  }
129 }
130 
131 void
133 {
134  for (unsigned int n = 0; n < _num_fi; ++n)
135  validateCoupling<Real>(_fi_names[n]);
136 }
137 
138 Real
140 {
141  Real F = 0.0;
142  for (unsigned n = 0; n < _num_fi; ++n)
143  F += (*_hi[n])[_qp] * (*_prop_Fi[n])[_qp];
144  return F + _W * _g[_qp];
145 }
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
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:165
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
const std::string & name() const
std::vector< const MaterialProperty< Real > * > _hi
Switching functions.
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:130
std::vector< unsigned int > _eta_vars
static InputParameters validParams()