https://mooseframework.inl.gov
AuxKernel.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 "AuxKernelBase.h"
13 #include "MooseVariableInterface.h"
14 
15 // forward declarations
16 template <typename ComputeValueType>
18 
22 
26 template <typename ComputeValueType>
27 class AuxKernelTempl : public AuxKernelBase, public MooseVariableInterface<ComputeValueType>
28 {
29 public:
31 
33 
37  virtual void compute() override;
38 
43  bool isNodal() const { return _nodal; }
44 
48  bool isMortar();
49 
55 
59  template <typename T>
60  const MaterialProperty<T> & getMaterialProperty(const std::string & name);
61  template <typename T, bool is_ad>
63  template <typename T>
64  const MaterialProperty<T> & getMaterialPropertyOld(const std::string & name);
65  template <typename T>
66  const MaterialProperty<T> & getMaterialPropertyOlder(const std::string & name);
67 
71  void insert();
72 
73 protected:
77  virtual ComputeValueType computeValue() = 0;
78 
79  virtual const VariableValue & coupledDot(const std::string & var_name,
80  unsigned int comp = 0) const override;
81 
82  virtual const VariableValue & coupledDotDu(const std::string & var_name,
83  unsigned int comp = 0) const override;
84 
86  virtual void precalculateValue() {}
87 
93  const typename OutputTools<ComputeValueType>::VariableValue & uOld() const;
94 
100  const typename OutputTools<ComputeValueType>::VariableValue & uOlder() const;
101 
104 
106  const bool _nodal;
107 
110 
113 
117  const QBase * const & _qrule;
121 
123  const Elem * const & _current_elem;
125  const unsigned int & _current_side;
126 
131 
133  const Node * const & _current_node;
134 
137 
140 
142  const Elem * const & _current_lower_d_elem;
143 
145  unsigned int _qp;
146 
148  unsigned int _n_local_dofs;
149 
151 
153  DenseVector<OutputData> _local_re;
155  DenseVector<OutputData> _local_sol;
158 
160 
161 private:
169  void setDofValueHelper(const ComputeValueType & dof_value);
170 };
171 
172 template <typename ComputeValueType>
173 template <typename T>
174 const MaterialProperty<T> &
176 {
177  if (isNodal())
178  mooseError("Nodal AuxKernel '",
180  "' attempted to reference material property '",
181  name,
182  "'\nConsider using an elemental auxiliary variable for '",
183  _var.name(),
184  "'.");
185 
186  return MaterialPropertyInterface::getMaterialProperty<T>(name);
187 }
188 
189 template <typename ComputeValueType>
190 template <typename T, bool is_ad>
193 {
194  if (isNodal())
195  mooseError("Nodal AuxKernel '",
197  "' attempted to reference material property '",
198  name,
199  "'\nConsider using an elemental auxiliary variable for '",
200  _var.name(),
201  "'.");
202 
203  return MaterialPropertyInterface::getGenericMaterialProperty<T, is_ad>(name);
204 }
205 
206 template <typename ComputeValueType>
207 template <typename T>
208 const MaterialProperty<T> &
210 {
211  if (isNodal())
212  mooseError("Nodal AuxKernel '",
214  "' attempted to reference material property '",
215  name,
216  "'\nConsider using an elemental auxiliary variable for '",
217  _var.name(),
218  "'.");
219 
220  return MaterialPropertyInterface::getMaterialPropertyOld<T>(name);
221 }
222 
223 template <typename ComputeValueType>
224 template <typename T>
225 const MaterialProperty<T> &
227 {
228  if (isNodal())
229  mooseError("Nodal AuxKernel '",
231  "' attempted to reference material property '",
232  name,
233  "'\nConsider using an elemental auxiliary variable for '",
234  _var.name(),
235  "'.");
236 
237  return MaterialPropertyInterface::getMaterialPropertyOlder<T>(name);
238 }
239 
240 // Declare all the specializations, as the template specialization declaration below must know
241 template <>
242 void AuxKernelTempl<Real>::setDofValueHelper(const Real & value);
243 template <>
245 template <>
247 
248 // Prevent implicit instantiation in other translation units where these classes are used
249 extern template class AuxKernelTempl<Real>;
250 extern template class AuxKernelTempl<RealVectorValue>;
251 extern template class AuxKernelTempl<RealEigenVector>;
std::string name(const ElemQuality q)
const OutputTools< ComputeValueType >::VariableValue & _u
Holds the solution at current quadrature points.
Definition: AuxKernel.h:109
AuxKernelTempl< RealVectorValue > VectorAuxKernel
Definition: AuxKernel.h:20
Base class for auxiliary kernels.
Definition: AuxKernelBase.h:42
const MooseArray< Real > & _coord
Definition: AuxKernel.h:120
const unsigned int & _current_side
current side of the current element
Definition: AuxKernel.h:125
MooseVariableField< ComputeValueType > & variable()
Get a reference to a variable this kernel is action on.
Definition: AuxKernel.h:54
const OutputTools< ComputeValueType >::VariableValue & uOlder() const
Retrieves the older value of the variable that this AuxKernel operates on.
Definition: AuxKernel.C:311
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
OutputType type
Definition: MooseTypes.h:269
const Real & _current_side_volume
Volume of the current side.
Definition: AuxKernel.h:130
const Node *const & _current_node
Current node (valid only for nodal kernels)
Definition: AuxKernel.h:133
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
virtual void compute() override
Computes the value and stores it in the solution vector.
Definition: AuxKernel.C:136
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const BoundaryID & _current_boundary_id
The current boundary ID.
Definition: AuxKernel.h:136
DenseVector< OutputData > _local_sol
for holding local solution
Definition: AuxKernel.h:155
AuxKernelTempl< Real > AuxKernel
Definition: AuxKernel.h:17
const MooseArray< Real > & _JxW
Transformed Jacobian weights.
Definition: AuxKernel.h:119
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:103
virtual ComputeValueType computeValue()=0
Compute and return the value of the aux variable.
DenseVector< OutputData > _local_re
for holding local load
Definition: AuxKernel.h:153
virtual void precalculateValue()
This callback is used for AuxKernelTempls that need to perform a per-element calculation.
Definition: AuxKernel.h:86
boundary_id_type BoundaryID
typename GenericMaterialPropertyStruct< T, is_ad >::type GenericMaterialProperty
bool isMortar()
Definition: AuxKernel.C:324
AuxKernelTempl(const InputParameters &parameters)
Definition: AuxKernel.C:41
const Real & _current_elem_volume
Volume of the current element.
Definition: AuxKernel.h:128
virtual const VariableValue & coupledDot(const std::string &var_name, unsigned int comp=0) const override
Time derivative of a coupled variable.
Definition: AuxKernel.C:83
const Elem *const & _current_lower_d_elem
The current lower dimensional element.
Definition: AuxKernel.h:142
OutputTools< Real >::VariableValue VariableValue
Definition: MooseTypes.h:315
NumericVector< Number > & _solution
reference to the solution vector of auxiliary system
Definition: AuxKernel.h:139
const MaterialProperty< T > & getMaterialPropertyOld(const std::string &name)
Definition: AuxKernel.h:209
const OutputTools< ComputeValueType >::VariableValue & uOld() const
Retrieves the old value of the variable that this AuxKernel operates on.
Definition: AuxKernel.C:298
void insert()
Insert the just computed values into the auxiliary solution vector.
Definition: AuxKernel.C:126
MooseVariableField< ComputeValueType > & _var
This is a regular kernel so we cast to a regular MooseVariable, hides base _var.
Definition: AuxKernel.h:103
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const QBase *const & _qrule
Quadrature rule being used.
Definition: AuxKernel.h:117
const bool _nodal
Flag indicating if the AuxKernel is nodal.
Definition: AuxKernel.h:106
const MaterialProperty< T > & getMaterialPropertyOlder(const std::string &name)
Definition: AuxKernel.h:226
Moose::DOFType< ComputeValueType >::type OutputData
Definition: AuxKernel.h:150
Interface for objects that need to get values of MooseVariables.
const MaterialProperty< T > & getMaterialProperty(const std::string &name)
Override functions from MaterialPropertyInterface for error checking.
Definition: AuxKernel.h:175
const Elem *const & _current_elem
Current element (valid only for elemental kernels)
Definition: AuxKernel.h:123
unsigned int _qp
Quadrature point index.
Definition: AuxKernel.h:145
DenseMatrix< Number > _local_ke
for holding local mass matrix
Definition: AuxKernel.h:157
const OutputTools< ComputeValueType >::VariableTestValue & _test
Holds the the test functions.
Definition: AuxKernel.h:112
static InputParameters validParams()
Definition: AuxKernel.C:27
Base class for creating new auxiliary kernels and auxiliary boundary conditions.
Definition: AuxKernel.h:17
virtual const VariableValue & coupledDotDu(const std::string &var_name, unsigned int comp=0) const override
Time derivative of a coupled variable with respect to the coefficients.
Definition: AuxKernel.C:96
void setDofValueHelper(const ComputeValueType &dof_value)
Currently only used when the auxiliary variable is a finite volume variable, this helps call through ...
const MooseArray< Point > & _q_point
Active quadrature points.
Definition: AuxKernel.h:115
AuxKernelTempl< RealEigenVector > ArrayAuxKernel
Definition: AuxKernel.h:21
bool isNodal() const
Nodal or elemental kernel?
Definition: AuxKernel.h:43
unsigned int _n_local_dofs
number of local dofs for elemental variables
Definition: AuxKernel.h:148
const GenericMaterialProperty< T, is_ad > & getGenericMaterialProperty(const std::string &name)
Definition: AuxKernel.h:192