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