https://mooseframework.inl.gov
CompositeTensorBase.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
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 #pragma once
11 
12 #include "Material.h"
14 
26 template <class T, class U>
28 {
29 public:
31 
32  CompositeTensorBase(const InputParameters & parameters);
33 
34 protected:
39  void initializeDerivativeProperties(const std::string name);
40 
50  virtual void computeQpTensorProperties(MaterialProperty<T> & M, Real derivative_prefactor = 1.0);
51 
53  std::vector<MaterialPropertyName> _tensor_names;
55  std::vector<MaterialPropertyName> _weight_names;
56 
58  unsigned int _num_args;
60  unsigned int _num_comp;
61 
63  std::vector<MaterialProperty<T> *> _dM;
64  std::vector<std::vector<MaterialProperty<T> *>> _d2M;
66 
68  std::vector<const MaterialProperty<T> *> _tensors;
69  std::vector<std::vector<const MaterialProperty<T> *>> _dtensors;
70  std::vector<std::vector<std::vector<const MaterialProperty<T> *>>> _d2tensors;
72 
74  std::vector<const MaterialProperty<Real> *> _weights;
75  std::vector<std::vector<const MaterialProperty<Real> *>> _dweights;
76  std::vector<std::vector<std::vector<const MaterialProperty<Real> *>>> _d2weights;
78 };
79 
80 template <class T, class U>
82  : DerivativeMaterialInterface<U>(parameters),
83  _tensor_names(this->template getParam<std::vector<MaterialPropertyName>>("tensors")),
84  _weight_names(this->template getParam<std::vector<MaterialPropertyName>>("weights")),
85  _num_args(this->DerivativeMaterialInterface<U>::coupledComponents("coupled_variables")),
86  _num_comp(_tensor_names.size()),
87  _dM(_num_args),
88  _d2M(_num_args),
89  _tensors(_num_comp),
90  _dtensors(_num_comp),
91  _d2tensors(_num_comp),
92  _weights(_num_comp),
93  _dweights(_num_comp),
94  _d2weights(_num_comp)
95 {
96  if (_num_comp != _weight_names.size())
97  mooseError("The number of supplied 'tensors' and 'weights' must match.");
98 }
99 
100 template <class T, class U>
103 {
104  InputParameters params = U::validParams();
105  params.addRequiredParam<std::vector<MaterialPropertyName>>("tensors", "Component tensors");
106  params.addRequiredParam<std::vector<MaterialPropertyName>>("weights", "Component weights");
107  params.addRequiredCoupledVar("coupled_variables", "variable dependencies for the prefactor");
108  return params;
109 }
110 
111 template <class T, class U>
112 void
114 {
115  // setup output composite tensor and derivatives
116  for (unsigned int j = 0; j < _num_args; ++j)
117  {
118  const VariableName & jname =
119  this->DerivativeMaterialInterface<U>::getVar("coupled_variables", j)->name();
120  _dM[j] = &this->template declarePropertyDerivative<T>(name, jname);
121  _d2M[j].resize(j + 1);
122 
123  for (unsigned int k = 0; k <= j; ++k)
124  {
125  const VariableName & kname =
126  this->DerivativeMaterialInterface<U>::getVar("coupled_variables", k)->name();
127 
128  _d2M[j][k] = &this->template declarePropertyDerivative<T>(name, jname, kname);
129  }
130  }
131 
132  // setup input components and its derivatives
133  for (unsigned int i = 0; i < _num_comp; ++i)
134  {
135  _tensors[i] = &this->template getMaterialPropertyByName<T>(_tensor_names[i]);
136  _weights[i] = &this->template getMaterialPropertyByName<Real>(_weight_names[i]);
137 
138  _dtensors[i].resize(_num_args);
139  _dweights[i].resize(_num_args);
140  _d2tensors[i].resize(_num_args);
141  _d2weights[i].resize(_num_args);
142 
143  for (unsigned int j = 0; j < _num_args; ++j)
144  {
145  const VariableName & jname =
146  this->DerivativeMaterialInterface<U>::getVar("coupled_variables", j)->name();
147 
148  _dtensors[i][j] =
149  &this->template getMaterialPropertyDerivativeByName<T>(_tensor_names[i], jname);
150  _dweights[i][j] =
151  &this->template getMaterialPropertyDerivativeByName<Real>(_weight_names[i], jname);
152 
153  _d2tensors[i][j].resize(j + 1);
154  _d2weights[i][j].resize(j + 1);
155 
156  for (unsigned int k = 0; k <= j; ++k)
157  {
158  const VariableName & kname =
159  this->DerivativeMaterialInterface<U>::getVar("coupled_variables", k)->name();
160 
161  _d2tensors[i][j][k] =
162  &this->template getMaterialPropertyDerivativeByName<T>(_tensor_names[i], jname, kname);
163  _d2weights[i][j][k] = &this->template getMaterialPropertyDerivativeByName<Real>(
164  _weight_names[i], jname, kname);
165  }
166  }
167  }
168 }
169 
170 template <class T, class U>
171 void
173  Real derivative_prefactor)
174 {
175  const unsigned int qp = this->DerivativeMaterialInterface<U>::_qp;
176 
177  M[qp].zero();
178  for (unsigned int i = 0; i < _num_comp; ++i)
179  {
180  M[qp] += (*_tensors[i])[qp] * (*_weights[i])[qp];
181 
182  for (unsigned int j = 0; j < _num_args; ++j)
183  {
184  if (i == 0)
185  (*_dM[j])[qp].zero();
186 
187  (*_dM[j])[qp] += derivative_prefactor * ((*_tensors[i])[qp] * (*_dweights[i][j])[qp] +
188  (*_dtensors[i][j])[qp] * (*_weights[i])[qp]);
189 
190  for (unsigned int k = 0; k <= j; ++k)
191  {
192  if (i == 0)
193  (*_d2M[j][k])[qp].zero();
194 
195  (*_d2M[j][k])[qp] +=
196  derivative_prefactor * (2.0 * (*_dtensors[i][j])[qp] * (*_dweights[i][j])[qp] +
197  (*_tensors[i])[qp] * (*_d2weights[i][j][k])[qp] +
198  (*_d2tensors[i][j][k])[qp] * (*_weights[i])[qp]);
199  }
200  }
201  }
202 }
std::string name(const ElemQuality q)
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()
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
std::vector< MaterialPropertyName > _weight_names
component weight names
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.
const Number zero
std::vector< std::vector< std::vector< const MaterialProperty< Real > * > > > _d2weights
InputParameters validParams()
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
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Interface class ("Veneer") to provide generator methods for derivative material property names...
std::vector< std::vector< const MaterialProperty< Real > * > > _dweights
unsigned int _num_args
number of dependent variables
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