https://mooseframework.inl.gov
ArrayDiffusion.C
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 #include "ArrayDiffusion.h"
11 
13 
16 {
18  params.addRequiredParam<MaterialPropertyName>(
19  "diffusion_coefficient",
20  "The name of the diffusivity, can be scalar, vector, or matrix material property.");
21  params.addClassDescription(
22  "The array Laplacian operator ($-\\nabla \\cdot \\nabla u$), with the weak "
23  "form of $(\\nabla \\phi_i, \\nabla u_h)$.");
24  return params;
25 }
26 
28  : ArrayKernel(parameters),
29  _d(hasMaterialProperty<Real>("diffusion_coefficient")
30  ? &getMaterialProperty<Real>("diffusion_coefficient")
31  : nullptr),
32  _d_array(hasMaterialProperty<RealEigenVector>("diffusion_coefficient")
33  ? &getMaterialProperty<RealEigenVector>("diffusion_coefficient")
34  : nullptr),
35  _d_2d_array(hasMaterialProperty<RealEigenMatrix>("diffusion_coefficient")
36  ? &getMaterialProperty<RealEigenMatrix>("diffusion_coefficient")
37  : nullptr)
38 {
39  if (!_d && !_d_array && !_d_2d_array)
40  {
41  MaterialPropertyName mat = getParam<MaterialPropertyName>("diffusion_coefficient");
42  mooseError("Property " + mat + " is of unsupported type for ArrayDiffusion");
43  }
44 }
45 
46 void
48 {
49  if (_d_array)
50  {
51  mooseAssert((*_d_array)[_qp].size() == _var.count(),
52  "diffusion_coefficient size is inconsistent with the number of components of array "
53  "variable");
54  }
55  else if (_d_2d_array)
56  {
57  mooseAssert((*_d_2d_array)[_qp].cols() == _var.count(),
58  "diffusion_coefficient size is inconsistent with the number of components of array "
59  "variable");
60  mooseAssert((*_d_2d_array)[_qp].rows() == _var.count(),
61  "diffusion_coefficient size is inconsistent with the number of components of array "
62  "variable");
63  }
64 }
65 
66 void
68 {
69  // WARNING: the noalias() syntax is an Eigen optimization tactic, it avoids creating
70  // a temporary object for the matrix multiplication on the right-hand-side. However,
71  // it should be used with caution because it could cause unintended results,
72  // developers should NOT use it if the vector on the left-hand-side appears on the
73  // right-hand-side, for instance:
74  // vector = matrix * vector;
75  // See http://eigen.tuxfamily.org/dox/group__TopicAliasing.html for more details.
76  if (_d)
77  residual.noalias() = (*_d)[_qp] * _grad_u[_qp] * _array_grad_test[_i][_qp];
78  else if (_d_array)
79  residual.noalias() = (*_d_array)[_qp].asDiagonal() * _grad_u[_qp] * _array_grad_test[_i][_qp];
80  else
81  residual.noalias() = (*_d_2d_array)[_qp] * _grad_u[_qp] * _array_grad_test[_i][_qp];
82 }
83 
86 {
87  if (_d)
88  return RealEigenVector::Constant(_var.count(),
89  _grad_phi[_j][_qp] * _grad_test[_i][_qp] * (*_d)[_qp]);
90  else if (_d_array)
91  return _grad_phi[_j][_qp] * _grad_test[_i][_qp] * (*_d_array)[_qp];
92  else
93  return _grad_phi[_j][_qp] * _grad_test[_i][_qp] * (*_d_2d_array)[_qp].diagonal();
94 }
95 
98 {
99  if (jvar.number() == _var.number() && _d_2d_array)
100  return _grad_phi[_j][_qp] * _grad_test[_i][_qp] * (*_d_2d_array)[_qp];
101  else
103 }
unsigned int number() const
Get variable number coming from libMesh.
const MappedArrayVariablePhiGradient & _array_grad_test
Definition: ArrayKernel.h:92
unsigned int count() const
Get the number of components Note: For standard and vector variables, the number is one...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
This class provides an interface for common operations on field variables of both FE and FV types wit...
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...
static InputParameters validParams()
Definition: ArrayKernel.C:23
const MaterialProperty< RealEigenMatrix > *const _d_2d_array
matrix diffusion coefficient
static InputParameters validParams()
const ArrayVariablePhiGradient & _grad_phi
gradient of the shape function
Definition: ArrayKernel.h:98
const MaterialProperty< Real > *const _d
scalar diffusion coefficient
const MaterialProperty< RealEigenVector > *const _d_array
array diffusion coefficient
const ArrayVariableTestGradient & _grad_test
gradient of the test function
Definition: ArrayKernel.h:91
unsigned int _i
current index for the test function
Definition: KernelBase.h:58
const ArrayVariableGradient & _grad_u
Holds the solution gradient at current quadrature points.
Definition: ArrayKernel.h:104
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic > RealEigenMatrix
Definition: MooseTypes.h:149
ArrayDiffusion(const InputParameters &parameters)
virtual RealEigenMatrix computeQpOffDiagJacobian(const MooseVariableFEBase &jvar)
This is the virtual that derived classes should override for computing a full Jacobian component...
Definition: ArrayKernel.C:215
unsigned int _j
current index for the shape function
Definition: KernelBase.h:61
registerMooseObject("MooseApp", ArrayDiffusion)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void computeQpResidual(RealEigenVector &residual) override
Compute this Kernel&#39;s contribution to the residual at the current quadrature point, to be filled in residual.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
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...
Eigen::Matrix< Real, Eigen::Dynamic, 1 > RealEigenVector
Definition: MooseTypes.h:146
virtual RealEigenMatrix computeQpOffDiagJacobian(const MooseVariableFEBase &jvar) override
This is the virtual that derived classes should override for computing a full Jacobian component...
virtual RealEigenVector computeQpJacobian() override
Compute this Kernel&#39;s contribution to the diagonal Jacobian at the current quadrature point...
virtual void initQpResidual() override
Put necessary evaluations depending on qp but independent on test functions here. ...
ArrayMooseVariable & _var
This is an array kernel so we cast to a ArrayMooseVariable.
Definition: ArrayKernel.h:85
unsigned int _qp
The current quadrature point index.
Definition: KernelBase.h:43