www.mooseframework.org
CompositeTensorBase.h
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 #ifndef COMPOSITETENSORBASE_H
8 #define COMPOSITETENSORBASE_H
9 
10 #include "Material.h"
12 
24 template <class T, class U>
26 {
27 public:
28  CompositeTensorBase(const InputParameters & parameters);
29 
31 
32 protected:
37  void initializeDerivativeProperties(const std::string name);
38 
48  virtual void computeQpTensorProperties(MaterialProperty<T> & M, Real derivative_prefactor = 1.0);
49 
51  std::vector<MaterialPropertyName> _tensor_names;
53  std::vector<MaterialPropertyName> _weight_names;
54 
56  unsigned int _num_args;
58  unsigned int _num_comp;
59 
61  std::vector<MaterialProperty<T> *> _dM;
62  std::vector<std::vector<MaterialProperty<T> *>> _d2M;
64 
66  std::vector<const MaterialProperty<T> *> _tensors;
67  std::vector<std::vector<const MaterialProperty<T> *>> _dtensors;
68  std::vector<std::vector<std::vector<const MaterialProperty<T> *>>> _d2tensors;
70 
72  std::vector<const MaterialProperty<Real> *> _weights;
73  std::vector<std::vector<const MaterialProperty<Real> *>> _dweights;
74  std::vector<std::vector<std::vector<const MaterialProperty<Real> *>>> _d2weights;
76 };
77 
78 template <class T, class U>
80  : DerivativeMaterialInterface<U>(parameters),
81  _tensor_names(this->template getParam<std::vector<MaterialPropertyName>>("tensors")),
82  _weight_names(this->template getParam<std::vector<MaterialPropertyName>>("weights")),
83  _num_args(this->DerivativeMaterialInterface<U>::coupledComponents("args")),
84  _num_comp(_tensor_names.size()),
85  _dM(_num_args),
86  _d2M(_num_args),
93 {
94  if (_num_comp != _weight_names.size())
95  mooseError("The number of supplied 'tensors' and 'weights' must match.");
96 }
97 
98 template <class T, class U>
101 {
102  InputParameters params = ::validParams<U>();
103  params.addRequiredParam<std::vector<MaterialPropertyName>>("tensors", "Component tensors");
104  params.addRequiredParam<std::vector<MaterialPropertyName>>("weights", "Component weights");
105  params.addRequiredCoupledVar("args", "variable dependencies for the prefactor");
106  return params;
107 }
108 
109 template <class T, class U>
110 void
112 {
113  // setup output composite tensor and derivatives
114  for (unsigned int j = 0; j < _num_args; ++j)
115  {
116  const VariableName & jname = this->DerivativeMaterialInterface<U>::getVar("args", j)->name();
117  _dM[j] = &this->template declarePropertyDerivative<T>(name, jname);
118  _d2M[j].resize(j + 1);
119 
120  for (unsigned int k = 0; k <= j; ++k)
121  {
122  const VariableName & kname = this->DerivativeMaterialInterface<U>::getVar("args", k)->name();
123  _d2M[j][k] = &this->template declarePropertyDerivative<T>(name, jname, kname);
124  }
125  }
126 
127  // setup input components and its derivatives
128  for (unsigned int i = 0; i < _num_comp; ++i)
129  {
130  _tensors[i] = &this->template getMaterialPropertyByName<T>(_tensor_names[i]);
131  _weights[i] = &this->template getMaterialPropertyByName<Real>(_weight_names[i]);
132 
133  _dtensors[i].resize(_num_args);
134  _dweights[i].resize(_num_args);
135  _d2tensors[i].resize(_num_args);
136  _d2weights[i].resize(_num_args);
137 
138  for (unsigned int j = 0; j < _num_args; ++j)
139  {
140  const VariableName & jname = this->DerivativeMaterialInterface<U>::getVar("args", j)->name();
141 
142  _dtensors[i][j] =
143  &this->template getMaterialPropertyDerivativeByName<T>(_tensor_names[i], jname);
144  _dweights[i][j] =
145  &this->template getMaterialPropertyDerivativeByName<Real>(_weight_names[i], jname);
146 
147  _d2tensors[i][j].resize(j + 1);
148  _d2weights[i][j].resize(j + 1);
149 
150  for (unsigned int k = 0; k <= j; ++k)
151  {
152  const VariableName & kname =
153  this->DerivativeMaterialInterface<U>::getVar("args", k)->name();
154 
155  _d2tensors[i][j][k] =
156  &this->template getMaterialPropertyDerivativeByName<T>(_tensor_names[i], jname, kname);
157  _d2weights[i][j][k] = &this->template getMaterialPropertyDerivativeByName<Real>(
158  _weight_names[i], jname, kname);
159  }
160  }
161  }
162 }
163 
164 template <class T, class U>
165 void
167  Real derivative_prefactor)
168 {
169  const unsigned int qp = this->DerivativeMaterialInterface<U>::_qp;
170 
171  M[qp].zero();
172  for (unsigned int i = 0; i < _num_comp; ++i)
173  {
174  M[qp] += (*_tensors[i])[qp] * (*_weights[i])[qp];
175 
176  for (unsigned int j = 0; j < _num_args; ++j)
177  {
178  if (i == 0)
179  (*_dM[j])[qp].zero();
180 
181  (*_dM[j])[qp] += derivative_prefactor * ((*_tensors[i])[qp] * (*_dweights[i][j])[qp] +
182  (*_dtensors[i][j])[qp] * (*_weights[i])[qp]);
183 
184  for (unsigned int k = 0; k <= j; ++k)
185  {
186  if (i == 0)
187  (*_d2M[j][k])[qp].zero();
188 
189  (*_d2M[j][k])[qp] +=
190  derivative_prefactor * (2.0 * (*_dtensors[i][j])[qp] * (*_dweights[i][j])[qp] +
191  (*_tensors[i])[qp] * (*_d2weights[i][j][k])[qp] +
192  (*_d2tensors[i][j][k])[qp] * (*_weights[i])[qp]);
193  }
194  }
195  }
196 }
197 
198 #endif // COMPOSITETENSORBASE_H
CompositeTensorBase computes a simple T type MaterialProperty that is summed up from a list of other...
std::vector< const MaterialProperty< Real > * > _weights
component weights and their derivatives w.r.t. the args
std::vector< MaterialProperty< T > * > _dM
Composed tensor and its derivatives.
static InputParameters validParams()
std::vector< MaterialPropertyName > _weight_names
component weight names
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual void computeQpTensorProperties(MaterialProperty< T > &M, Real derivative_prefactor=1.0)
Fill in the.
std::vector< std::vector< std::vector< const MaterialProperty< Real > * > > > _d2weights
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
void initializeDerivativeProperties(const std::string name)
Output material properties are initialized here so that derived classes can modify the name...
std::vector< const MaterialProperty< T > * > _tensors
component tensors and their derivatives w.r.t. the args
CompositeTensorBase(const InputParameters &parameters)
std::vector< std::vector< const MaterialProperty< T > * > > _dtensors
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
unsigned int _num_comp
number of compomemt tensors and weights
Interface class ("Veneer") to provide generator methods for derivative material property names...
PetscInt M
std::vector< std::vector< const MaterialProperty< Real > * > > _dweights
unsigned int _num_args
number of dependent variables
Concrete definition of a parameter value for a specified type.
std::vector< std::vector< MaterialProperty< T > * > > _d2M
std::vector< MaterialPropertyName > _tensor_names
component tensor names
std::vector< std::vector< std::vector< const MaterialProperty< T > * > > > _d2tensors