www.mooseframework.org
DerivativeSumMaterial.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 
10 #include "DerivativeSumMaterial.h"
11 
12 #include "libmesh/quadrature.h"
13 
15 
16 template <>
19 {
21  params.addClassDescription("Meta-material to sum up multiple derivative materials");
22  params.addParam<std::vector<std::string>>(
23  "sum_materials",
24  "Base name of the free energy function (used to name the material properties)");
25  // params.addParam<bool>("third_derivatives", true, "Calculate third derivatoves of the free
26  // energy");
27 
28  // All arguments of the free energies being summed
29  params.addRequiredCoupledVar(
30  "args", "Arguments of the free energy functions being summed - use vector coupling");
31  params.addCoupledVar("displacement_gradients",
32  "Vector of displacement gradient variables (see "
33  "Modules/PhaseField/DisplacementGradients "
34  "action)");
35 
36  // Advanced arguments to construct a sum of the form \f$ c+\gamma\sum_iF_i \f$
37  params.addParam<std::vector<Real>>("prefactor", "Prefactor to multiply the sum term with.");
38  params.addParam<Real>("constant", 0.0, "Constant to be added to the prefactor multiplied sum.");
39  params.addParamNamesToGroup("prefactor constant", "Advanced");
40 
41  return params;
42 }
43 
45  : DerivativeFunctionMaterialBase(parameters),
46  _sum_materials(getParam<std::vector<std::string>>("sum_materials")),
47  _num_materials(_sum_materials.size()),
48  _prefactor(_num_materials, 1.0),
49  _constant(getParam<Real>("constant"))
50 {
51  // we need at least one material in the sum
52  if (_num_materials == 0)
53  mooseError("Please supply at least one material to sum in DerivativeSumMaterial ", name());
54 
55  // get prefactor values if not 1.0
56  std::vector<Real> p = getParam<std::vector<Real>>("prefactor");
57 
58  // if prefactor is used we need the same number of prefactors as sum materials
59  if (_num_materials == p.size())
60  _prefactor = p;
61  else if (p.size() != 0)
62  mooseError("Supply the same nummber of sum materials and prefactors.");
63 
64  // reserve space for summand material properties
65  _summand_F.resize(_num_materials);
69 
70  for (unsigned int n = 0; n < _num_materials; ++n)
71  {
72  _summand_F[n] = &getMaterialProperty<Real>(_sum_materials[n]);
73  _summand_dF[n].resize(_nargs);
74  _summand_d2F[n].resize(_nargs);
75  _summand_d3F[n].resize(_nargs);
76 
77  for (unsigned int i = 0; i < _nargs; ++i)
78  {
79  _summand_dF[n][i] = &getMaterialPropertyDerivative<Real>(_sum_materials[n], _arg_names[i]);
80  _summand_d2F[n][i].resize(_nargs);
81 
83  _summand_d3F[n][i].resize(_nargs);
84 
85  for (unsigned int j = 0; j < _nargs; ++j)
86  {
87  _summand_d2F[n][i][j] =
88  &getMaterialPropertyDerivative<Real>(_sum_materials[n], _arg_names[i], _arg_names[j]);
89 
91  {
92  _summand_d3F[n][i][j].resize(_nargs);
93 
94  for (unsigned int k = 0; k < _nargs; ++k)
95  _summand_d3F[n][i][j][k] = &getMaterialPropertyDerivative<Real>(
97  }
98  }
99  }
100  }
101 }
102 
103 void
105 {
106  for (unsigned int n = 0; n < _num_materials; ++n)
107  validateCoupling<Real>(_sum_materials[n]);
108 }
109 
110 void
112 {
113  unsigned int i, j, k;
114 
115  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
116  {
117  // set function value
118  if (_prop_F)
119  {
120  (*_prop_F)[_qp] = (*_summand_F[0])[_qp] * _prefactor[0];
121  for (unsigned int n = 1; n < _num_materials; ++n)
122  (*_prop_F)[_qp] += (*_summand_F[n])[_qp] * _prefactor[n];
123  }
124 
125  for (i = 0; i < _nargs; ++i)
126  {
127  // set first derivatives
128  if (_prop_dF[i])
129  {
130  (*_prop_dF[i])[_qp] = (*_summand_dF[0][i])[_qp] * _prefactor[0];
131  for (unsigned int n = 1; n < _num_materials; ++n)
132  (*_prop_dF[i])[_qp] += (*_summand_dF[n][i])[_qp] * _prefactor[n];
133  }
134 
135  // second derivatives
136  for (j = i; j < _nargs; ++j)
137  {
138  if (_prop_d2F[i][j])
139  {
140  (*_prop_d2F[i][j])[_qp] = (*_summand_d2F[0][i][j])[_qp] * _prefactor[0];
141  for (unsigned int n = 1; n < _num_materials; ++n)
142  (*_prop_d2F[i][j])[_qp] += (*_summand_d2F[n][i][j])[_qp] * _prefactor[n];
143  }
144 
145  // third derivatives
146  if (_third_derivatives)
147  {
148  for (k = j; k < _nargs; ++k)
149  if (_prop_d3F[i][j][k])
150  {
151  (*_prop_d3F[i][j][k])[_qp] = (*_summand_d3F[0][i][j][k])[_qp] * _prefactor[0];
152  for (unsigned int n = 1; n < _num_materials; ++n)
153  (*_prop_d3F[i][j][k])[_qp] += (*_summand_d3F[n][i][j][k])[_qp] * _prefactor[n];
154  }
155  }
156  }
157  }
158  }
159 }
std::vector< std::vector< MaterialProperty< Real > * > > _prop_d2F
Material properties to store the second derivatives.
const QBase *const & _qrule
Definition: Material.h:224
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.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
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.
unsigned int _qp
Definition: Material.h:222
InputParameters validParams< DerivativeSumMaterial >()
Material base class to compute a function 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
virtual void computeProperties()
Performs the quadrature point loop, calling computeQpProperties.
unsigned int _nargs
Number of coupled arguments.
registerMooseObject("MooseApp", DerivativeSumMaterial)
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].
void addCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
std::vector< std::string > _sum_materials
PetscInt n
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:59
std::vector< std::string > _arg_names
String vector of all argument names.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
std::vector< const MaterialProperty< Real > * > _summand_F
Function values of the summands.
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...