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>::isCoupled("args")
86  ? this->DerivativeMaterialInterface<U>::coupledComponents("args")
87  : this->DerivativeMaterialInterface<U>::coupledComponents("coupled_variables")),
88  _num_comp(_tensor_names.size()),
89  _dM(_num_args),
90  _d2M(_num_args),
91  _tensors(_num_comp),
92  _dtensors(_num_comp),
93  _d2tensors(_num_comp),
94  _weights(_num_comp),
95  _dweights(_num_comp),
96  _d2weights(_num_comp)
97 {
98  if (_num_comp != _weight_names.size())
99  mooseError("The number of supplied 'tensors' and 'weights' must match.");
100 }
101 
102 template <class T, class U>
105 {
106  InputParameters params = U::validParams();
107  params.addRequiredParam<std::vector<MaterialPropertyName>>("tensors", "Component tensors");
108  params.addRequiredParam<std::vector<MaterialPropertyName>>("weights", "Component weights");
109  params.addRequiredCoupledVar("args", "variable dependencies for the prefactor");
110  params.deprecateCoupledVar("args", "coupled_variables", "02/07/2024");
111  return params;
112 }
113 
114 template <class T, class U>
115 void
117 {
118  // setup output composite tensor and derivatives
119  for (unsigned int j = 0; j < _num_args; ++j)
120  {
121  const VariableName & jname =
122  this->DerivativeMaterialInterface<U>::getVar("coupled_variables", j)->name();
123  _dM[j] = &this->template declarePropertyDerivative<T>(name, jname);
124  _d2M[j].resize(j + 1);
125 
126  for (unsigned int k = 0; k <= j; ++k)
127  {
128  const VariableName & kname =
129  this->DerivativeMaterialInterface<U>::getVar("coupled_variables", k)->name();
130 
131  _d2M[j][k] = &this->template declarePropertyDerivative<T>(name, jname, kname);
132  }
133  }
134 
135  // setup input components and its derivatives
136  for (unsigned int i = 0; i < _num_comp; ++i)
137  {
138  _tensors[i] = &this->template getMaterialPropertyByName<T>(_tensor_names[i]);
139  _weights[i] = &this->template getMaterialPropertyByName<Real>(_weight_names[i]);
140 
141  _dtensors[i].resize(_num_args);
142  _dweights[i].resize(_num_args);
143  _d2tensors[i].resize(_num_args);
144  _d2weights[i].resize(_num_args);
145 
146  for (unsigned int j = 0; j < _num_args; ++j)
147  {
148  const VariableName & jname =
149  this->DerivativeMaterialInterface<U>::getVar("coupled_variables", j)->name();
150 
151  _dtensors[i][j] =
152  &this->template getMaterialPropertyDerivativeByName<T>(_tensor_names[i], jname);
153  _dweights[i][j] =
154  &this->template getMaterialPropertyDerivativeByName<Real>(_weight_names[i], jname);
155 
156  _d2tensors[i][j].resize(j + 1);
157  _d2weights[i][j].resize(j + 1);
158 
159  for (unsigned int k = 0; k <= j; ++k)
160  {
161  const VariableName & kname =
162  this->DerivativeMaterialInterface<U>::getVar("coupled_variables", k)->name();
163 
164  _d2tensors[i][j][k] =
165  &this->template getMaterialPropertyDerivativeByName<T>(_tensor_names[i], jname, kname);
166  _d2weights[i][j][k] = &this->template getMaterialPropertyDerivativeByName<Real>(
167  _weight_names[i], jname, kname);
168  }
169  }
170  }
171 }
172 
173 template <class T, class U>
174 void
176  Real derivative_prefactor)
177 {
178  const unsigned int qp = this->DerivativeMaterialInterface<U>::_qp;
179 
180  M[qp].zero();
181  for (unsigned int i = 0; i < _num_comp; ++i)
182  {
183  M[qp] += (*_tensors[i])[qp] * (*_weights[i])[qp];
184 
185  for (unsigned int j = 0; j < _num_args; ++j)
186  {
187  if (i == 0)
188  (*_dM[j])[qp].zero();
189 
190  (*_dM[j])[qp] += derivative_prefactor * ((*_tensors[i])[qp] * (*_dweights[i][j])[qp] +
191  (*_dtensors[i][j])[qp] * (*_weights[i])[qp]);
192 
193  for (unsigned int k = 0; k <= j; ++k)
194  {
195  if (i == 0)
196  (*_d2M[j][k])[qp].zero();
197 
198  (*_d2M[j][k])[qp] +=
199  derivative_prefactor * (2.0 * (*_dtensors[i][j])[qp] * (*_dweights[i][j])[qp] +
200  (*_tensors[i])[qp] * (*_d2weights[i][j][k])[qp] +
201  (*_d2tensors[i][j][k])[qp] * (*_weights[i])[qp]);
202  }
203  }
204  }
205 }
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:302
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 deprecateCoupledVar(const std::string &old_name, const std::string &new_name, const std::string &removal_date)
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