www.mooseframework.org
DerivativeFunctionMaterialBase.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 
12 #include "libmesh/quadrature.h"
13 
14 template <>
17 {
19  params.addClassDescription("Material to provide a function (such as a free energy) and its "
20  "derivatives w.r.t. the coupled variables");
21  params.addDeprecatedParam<bool>("third_derivatives",
22  "Flag to indicate if third derivatives are needed",
23  "Use derivative_order instead.");
24  params.addRangeCheckedParam<unsigned int>("derivative_order",
25  3,
26  "derivative_order>=2 & derivative_order<=3",
27  "Maximum order of derivatives taken (2 or 3)");
28  return params;
29 }
30 
32  : FunctionMaterialBase(parameters),
33  _third_derivatives(getParam<unsigned int>("derivative_order") == 3)
34 {
35  // reserve space for material properties and explicitly initialize to NULL
36  _prop_dF.resize(_nargs, NULL);
37  _prop_d2F.resize(_nargs);
38  _prop_d3F.resize(_nargs);
39  for (unsigned int i = 0; i < _nargs; ++i)
40  {
41  _prop_d2F[i].resize(_nargs, NULL);
42 
44  {
45  _prop_d3F[i].resize(_nargs);
46 
47  for (unsigned int j = 0; j < _nargs; ++j)
48  _prop_d3F[i][j].resize(_nargs, NULL);
49  }
50  }
51 
52  // initialize derivatives
53  for (unsigned int i = 0; i < _nargs; ++i)
54  {
55  // first derivatives
56  _prop_dF[i] = &declarePropertyDerivative<Real>(_F_name, _arg_names[i]);
57 
58  // second derivatives
59  for (unsigned int j = i; j < _nargs; ++j)
60  {
61  _prop_d2F[i][j] = _prop_d2F[j][i] =
62  &declarePropertyDerivative<Real>(_F_name, _arg_names[i], _arg_names[j]);
63 
64  // third derivatives
66  {
67  for (unsigned int k = j; k < _nargs; ++k)
68  {
69  // filling all permutations does not cost us much and simplifies access
70  // (no need to check i<=j<=k)
71  _prop_d3F[i][j][k] = _prop_d3F[k][i][j] = _prop_d3F[j][k][i] = _prop_d3F[k][j][i] =
72  _prop_d3F[j][i][k] = _prop_d3F[i][k][j] = &declarePropertyDerivative<Real>(
74  }
75  }
76  }
77  }
78 }
79 
80 void
82 {
83  // set the _prop_* pointers of all material properties that are not beeing used back to NULL
84  bool needs_third_derivatives = false;
85 
87  _prop_F = NULL;
88 
89  for (unsigned int i = 0; i < _nargs; ++i)
90  {
92  _prop_dF[i] = NULL;
93 
94  // second derivatives
95  for (unsigned int j = i; j < _nargs; ++j)
96  {
99  _prop_d2F[i][j] = _prop_d2F[j][i] = NULL;
100 
101  // third derivatives
102  if (_third_derivatives)
103  {
104  for (unsigned int k = j; k < _nargs; ++k)
105  {
107  _F_name, _arg_names[i], _arg_names[j], _arg_names[k])))
108  _prop_d3F[i][j][k] = _prop_d3F[k][i][j] = _prop_d3F[j][k][i] = _prop_d3F[k][j][i] =
109  _prop_d3F[j][i][k] = _prop_d3F[i][k][j] = NULL;
110  else
111  needs_third_derivatives = true;
112  }
113 
114  if (!needs_third_derivatives)
115  mooseWarning("This simulation does not actually need the third derivatives of "
116  "DerivativeFunctionMaterialBase " +
117  name());
118  }
119  }
120  }
121 }
122 
123 void
125 {
126  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
127  {
128  // set function value
129  if (_prop_F)
130  (*_prop_F)[_qp] = computeF();
131 
132  for (unsigned int i = 0; i < _nargs; ++i)
133  {
134  // set first derivatives
135  if (_prop_dF[i])
136  (*_prop_dF[i])[_qp] = computeDF(_arg_numbers[i]);
137 
138  // second derivatives
139  for (unsigned int j = i; j < _nargs; ++j)
140  {
141  if (_prop_d2F[i][j])
142  (*_prop_d2F[i][j])[_qp] = computeD2F(_arg_numbers[i], _arg_numbers[j]);
143 
144  // third derivatives
145  if (_third_derivatives)
146  {
147  for (unsigned int k = j; k < _nargs; ++k)
148  if (_prop_d3F[i][j][k])
149  (*_prop_d3F[i][j][k])[_qp] =
151  }
152  }
153  }
154  }
155 }
std::vector< std::vector< MaterialProperty< Real > * > > _prop_d2F
Material properties to store the second derivatives.
const MaterialPropertyName derivativePropertyNameSecond(const MaterialPropertyName &base, const VariableName &c1, const VariableName &c2) const
Helper functions to generate the material property names for the second derivatives.
const QBase *const & _qrule
Definition: Material.h:224
DerivativeFunctionMaterialBase(const InputParameters &parameters)
void addDeprecatedParam(const std::string &name, const T &value, const std::string &doc_string, const std::string &deprecation_message)
virtual Real computeD2F(unsigned int arg1, unsigned int arg2)
Override this method to calculate the second derivatives.
void mooseWarning(Args &&... args) const
Definition: MooseObject.h:155
FEProblemBase & _fe_problem
Definition: Material.h:215
Material base class central for all Materials that provide a Function as a material property value...
std::vector< std::vector< std::vector< MaterialProperty< Real > * > > > _prop_d3F
Material properties to store the third derivatives.
virtual void computeProperties()
Performs the quadrature point loop, calling computeQpProperties.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
MaterialProperty< Real > * _prop_F
Material property to store the function value.
unsigned int _qp
Definition: Material.h:222
virtual Real computeD3F(unsigned int, unsigned int, unsigned int)
Override this method to calculate the third derivatives.
virtual Real computeF()
Override this method to provide the free energy function.
virtual bool isMatPropRequested(const std::string &prop_name) const
Find out if a material property has been requested by any object.
Definition: SubProblem.C:552
bool _third_derivatives
Calculate (and allocate memory for) the third derivatives of the free energy.
InputParameters validParams< DerivativeFunctionMaterialBase >()
unsigned int _nargs
Number of coupled arguments.
InputParameters validParams< FunctionMaterialBase >()
std::vector< MaterialProperty< Real > * > _prop_dF
Material properties to store the derivatives of f with respect to arg[i].
virtual Real computeDF(unsigned int arg)
Override this method for calculating the first derivatives.
std::string _F_name
Name of the function value material property and used as a base name to concatenate the material prop...
const MaterialPropertyName derivativePropertyNameThird(const MaterialPropertyName &base, const VariableName &c1, const VariableName &c2, const VariableName &c3) const
Helper functions to generate the material property names for the third derivatives.
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...
virtual void initialSetup()
Check if we got the right number of components in the &#39;args&#39; coupled variable vector.
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
const MaterialPropertyName derivativePropertyNameFirst(const MaterialPropertyName &base, const VariableName &c1) const
Helper functions to generate the material property names for the first derivatives.
std::vector< unsigned int > _arg_numbers
Vector of all argument MOOSE variable numbers.