DerivativeSumMaterial.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7
9
11
12 template <>
13 InputParameters
15 {
16  InputParameters params = validParams<DerivativeFunctionMaterialBase>();
17  params.addClassDescription("Meta-material to sum up multiple derivative materials");
19  "sum_materials",
20  "Base name of the free energy function (used to name the material properties)");
21  // params.addParam<bool>("third_derivatives", true, "Calculate third derivatoves of the free
22  // energy");
23
24  // All arguments of the free energies being summed
26  "args", "Arguments of the free energy functions being summed - use vector coupling");
28  "Vector of displacement gradient variables (see "
30  "action)");
31
32  // Advanced arguments to construct a sum of the form \f$c+\gamma\sum_iF_i \f$
33  params.addParam<std::vector<Real>>("prefactor", "Prefactor to multiply the sum term with.");
34  params.addParam<Real>("constant", 0.0, "Constant to be added to the prefactor multiplied sum.");
36
37  return params;
38 }
39
40 DerivativeSumMaterial::DerivativeSumMaterial(const InputParameters & parameters)
41  : DerivativeFunctionMaterialBase(parameters),
42  _sum_materials(getParam<std::vector<std::string>>("sum_materials")),
43  _num_materials(_sum_materials.size()),
44  _prefactor(_num_materials, 1.0),
45  _constant(getParam<Real>("constant"))
46 {
47  // we need at least one material in the sum
48  if (_num_materials == 0)
49  mooseError("Please supply at least one material to sum in DerivativeSumMaterial ", name());
50
51  // get prefactor values if not 1.0
52  std::vector<Real> p = getParam<std::vector<Real>>("prefactor");
53
54  // if prefactor is used we need the same number of prefactors as sum materials
55  if (_num_materials == p.size())
56  _prefactor = p;
57  else if (p.size() != 0)
58  mooseError("Supply the same nummber of sum materials and prefactors.");
59
60  // reserve space for summand material properties
61  _summand_F.resize(_num_materials);
65
66  for (unsigned int n = 0; n < _num_materials; ++n)
67  {
68  _summand_F[n] = &getMaterialProperty<Real>(_sum_materials[n]);
69  _summand_dF[n].resize(_nargs);
70  _summand_d2F[n].resize(_nargs);
71  _summand_d3F[n].resize(_nargs);
72
73  for (unsigned int i = 0; i < _nargs; ++i)
74  {
75  _summand_dF[n][i] = &getMaterialPropertyDerivative<Real>(_sum_materials[n], _arg_names[i]);
76  _summand_d2F[n][i].resize(_nargs);
77
79  _summand_d3F[n][i].resize(_nargs);
80
81  for (unsigned int j = 0; j < _nargs; ++j)
82  {
83  _summand_d2F[n][i][j] =
84  &getMaterialPropertyDerivative<Real>(_sum_materials[n], _arg_names[i], _arg_names[j]);
85
87  {
88  _summand_d3F[n][i][j].resize(_nargs);
89
90  for (unsigned int k = 0; k < _nargs; ++k)
91  _summand_d3F[n][i][j][k] = &getMaterialPropertyDerivative<Real>(
92  _sum_materials[n], _arg_names[i], _arg_names[j], _arg_names[k]);
93  }
94  }
95  }
96  }
97 }
98
99 void
101 {
102  for (unsigned int n = 0; n < _num_materials; ++n)
103  validateCoupling<Real>(_sum_materials[n]);
104 }
105
106 void
108 {
109  unsigned int i, j, k;
110
111  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
112  {
113  // set function value
114  if (_prop_F)
115  {
116  (*_prop_F)[_qp] = (*_summand_F[0])[_qp] * _prefactor[0];
117  for (unsigned int n = 1; n < _num_materials; ++n)
118  (*_prop_F)[_qp] += (*_summand_F[n])[_qp] * _prefactor[n];
119  }
120
121  for (i = 0; i < _nargs; ++i)
122  {
123  // set first derivatives
124  if (_prop_dF[i])
125  {
126  (*_prop_dF[i])[_qp] = (*_summand_dF[0][i])[_qp] * _prefactor[0];
127  for (unsigned int n = 1; n < _num_materials; ++n)
128  (*_prop_dF[i])[_qp] += (*_summand_dF[n][i])[_qp] * _prefactor[n];
129  }
130
131  // second derivatives
132  for (j = i; j < _nargs; ++j)
133  {
134  if (_prop_d2F[i][j])
135  {
136  (*_prop_d2F[i][j])[_qp] = (*_summand_d2F[0][i][j])[_qp] * _prefactor[0];
137  for (unsigned int n = 1; n < _num_materials; ++n)
138  (*_prop_d2F[i][j])[_qp] += (*_summand_d2F[n][i][j])[_qp] * _prefactor[n];
139  }
140
141  // third derivatives
142  if (_third_derivatives)
143  {
144  for (k = j; k < _nargs; ++k)
145  if (_prop_d3F[i][j][k])
146  {
147  (*_prop_d3F[i][j][k])[_qp] = (*_summand_d3F[0][i][j][k])[_qp] * _prefactor[0];
148  for (unsigned int n = 1; n < _num_materials; ++n)
149  (*_prop_d3F[i][j][k])[_qp] += (*_summand_d3F[n][i][j][k])[_qp] * _prefactor[n];
150  }
151  }
152  }
153  }
154  }
155 }
std::vector< std::vector< MaterialProperty< Real > * > > _prop_d2F
Material properties to store the second derivatives.
std::vector< std::vector< std::vector< const MaterialProperty< Real > * > > > _summand_d2F
Second derivatives of the summands.
InputParameters validParams< DerivativeFunctionMaterialBase >()
std::vector< std::vector< std::vector< MaterialProperty< Real > * > > > _prop_d3F
Material properties to store the third derivatives.
std::vector< std::vector< std::vector< std::vector< const MaterialProperty< Real > * > > > > _summand_d3F
Third derivatives of the summands.
MaterialProperty< Real > * _prop_F
Material property to store the function value.
InputParameters validParams< DerivativeSumMaterial >()
Material base class central to compute the a phase free energy and its derivatives.
bool _third_derivatives
Calculate (and allocate memory for) the third derivatives of the free energy.
virtual void initialSetup()
Check if we got the right number of components in the &#39;args&#39; coupled variable vector.
std::vector< Real > _prefactor
arguments to construct a sum of the form
unsigned int _nargs
Number of coupled arguments.
DerivativeSumMaterial(const InputParameters &parameters)
std::vector< MaterialProperty< Real > * > _prop_dF
Material properties to store the derivatives of f with respect to arg[i].
std::vector< std::vector< const MaterialProperty< Real > * > > _summand_dF
Derivatives of the summands with respect to arg[i].
std::vector< std::string > _sum_materials
std::vector< std::string > _arg_names
String vector of all argument names.
std::vector< const MaterialProperty< Real > * > _summand_F
Function values of the summands.