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 
77 
78 protected:
82  virtual ComputeValueType computeValue() = 0;
83 
84  virtual const VariableValue & coupledDot(const std::string & var_name,
85  unsigned int comp = 0) const override;
86 
87  virtual const VariableValue & coupledDotDu(const std::string & var_name,
88  unsigned int comp = 0) const override;
89 
91  virtual void precalculateValue() {}
92 
98  const typename OutputTools<ComputeValueType>::VariableValue & uOld() const;
99 
105  const typename OutputTools<ComputeValueType>::VariableValue & uOlder() const;
106 
109 
111  const bool _nodal;
112 
115 
118 
122  const QBase * const & _qrule;
126 
128  const Elem * const & _current_elem;
130  const unsigned int & _current_side;
131 
136 
138  const Node * const & _current_node;
139 
142 
145 
147  const Elem * const & _current_lower_d_elem;
148 
150  unsigned int _qp;
151 
153  unsigned int _n_shapes;
154 
156 
158  DenseVector<OutputData> _local_re;
160  DenseVector<OutputData> _local_sol;
163 
166  std::optional<bool> _coincident_lower_d_calc;
167 
169 
170 private:
178  void setDofValueHelper(const ComputeValueType & dof_value);
179 };
180 
181 template <typename ComputeValueType>
182 template <typename T>
183 const MaterialProperty<T> &
185 {
186  if (isNodal())
187  mooseError("Nodal AuxKernel '",
189  "' attempted to reference material property '",
190  name,
191  "'\nConsider using an elemental auxiliary variable for '",
192  _var.name(),
193  "'.");
194 
195  return MaterialPropertyInterface::getMaterialProperty<T>(name);
196 }
197 
198 template <typename ComputeValueType>
199 template <typename T, bool is_ad>
202 {
203  if (isNodal())
204  mooseError("Nodal AuxKernel '",
206  "' attempted to reference material property '",
207  name,
208  "'\nConsider using an elemental auxiliary variable for '",
209  _var.name(),
210  "'.");
211 
212  return MaterialPropertyInterface::getGenericMaterialProperty<T, is_ad>(name);
213 }
214 
215 template <typename ComputeValueType>
216 template <typename T>
217 const MaterialProperty<T> &
219 {
220  if (isNodal())
221  mooseError("Nodal AuxKernel '",
223  "' attempted to reference material property '",
224  name,
225  "'\nConsider using an elemental auxiliary variable for '",
226  _var.name(),
227  "'.");
228 
229  return MaterialPropertyInterface::getMaterialPropertyOld<T>(name);
230 }
231 
232 template <typename ComputeValueType>
233 template <typename T>
234 const MaterialProperty<T> &
236 {
237  if (isNodal())
238  mooseError("Nodal AuxKernel '",
240  "' attempted to reference material property '",
241  name,
242  "'\nConsider using an elemental auxiliary variable for '",
243  _var.name(),
244  "'.");
245 
246  return MaterialPropertyInterface::getMaterialPropertyOlder<T>(name);
247 }
248 
249 // Declare all the specializations, as the template specialization declaration below must know
250 template <>
251 void AuxKernelTempl<Real>::setDofValueHelper(const Real & value);
252 template <>
254 template <>
256 
257 // Prevent implicit instantiation in other translation units where these classes are used
258 extern template class AuxKernelTempl<Real>;
259 extern template class AuxKernelTempl<RealVectorValue>;
260 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:114
AuxKernelTempl< RealVectorValue > VectorAuxKernel
Definition: AuxKernel.h:20
Base class for auxiliary kernels.
Definition: AuxKernelBase.h:42
const MooseArray< Real > & _coord
Definition: AuxKernel.h:125
const unsigned int & _current_side
current side of the current element
Definition: AuxKernel.h:130
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:310
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
OutputType type
Definition: MooseTypes.h:297
const Real & _current_side_volume
Volume of the current side.
Definition: AuxKernel.h:135
const Node *const & _current_node
Current node (valid only for nodal kernels)
Definition: AuxKernel.h:138
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:143
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:141
DenseVector< OutputData > _local_sol
for holding local solution
Definition: AuxKernel.h:160
AuxKernelTempl< Real > AuxKernel
Definition: AuxKernel.h:17
const MooseArray< Real > & _JxW
Transformed Jacobian weights.
Definition: AuxKernel.h:124
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:158
virtual void precalculateValue()
This callback is used for AuxKernelTempls that need to perform a per-element calculation.
Definition: AuxKernel.h:91
unsigned int _n_shapes
number of shape functions for the finite element type and current DofObject
Definition: AuxKernel.h:153
boundary_id_type BoundaryID
typename GenericMaterialPropertyStruct< T, is_ad >::type GenericMaterialProperty
bool isMortar()
Definition: AuxKernel.C:323
AuxKernelTempl(const InputParameters &parameters)
Definition: AuxKernel.C:42
const Real & _current_elem_volume
Volume of the current element.
Definition: AuxKernel.h:133
std::optional< bool > _coincident_lower_d_calc
Whether we are computing for a lower dimensional variable using boundary restriction, e.g.
Definition: AuxKernel.h:166
virtual const VariableValue & coupledDot(const std::string &var_name, unsigned int comp=0) const override
Time derivative of a coupled variable.
Definition: AuxKernel.C:88
const Elem *const & _current_lower_d_elem
The current lower dimensional element.
Definition: AuxKernel.h:147
OutputTools< Real >::VariableValue VariableValue
Definition: MooseTypes.h:343
NumericVector< Number > & _solution
reference to the solution vector of auxiliary system
Definition: AuxKernel.h:144
const MaterialProperty< T > & getMaterialPropertyOld(const std::string &name)
Definition: AuxKernel.h:218
const OutputTools< ComputeValueType >::VariableValue & uOld() const
Retrieves the old value of the variable that this AuxKernel operates on.
Definition: AuxKernel.C:297
void insert()
Insert the just computed values into the auxiliary solution vector.
Definition: AuxKernel.C:131
MooseVariableField< ComputeValueType > & _var
This is a regular kernel so we cast to a regular MooseVariable, hides base _var.
Definition: AuxKernel.h:108
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const QBase *const & _qrule
Quadrature rule being used.
Definition: AuxKernel.h:122
const bool _nodal
Flag indicating if the AuxKernel is nodal.
Definition: AuxKernel.h:111
const MaterialProperty< T > & getMaterialPropertyOlder(const std::string &name)
Definition: AuxKernel.h:235
Moose::DOFType< ComputeValueType >::type OutputData
Definition: AuxKernel.h:155
void determineWhetherCoincidentLowerDCalc()
Determines whether we&#39;re a coincident lower-d calculation.
Definition: AuxKernel.C:330
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:184
const Elem *const & _current_elem
Current element (valid only for elemental kernels)
Definition: AuxKernel.h:128
unsigned int _qp
Quadrature point index.
Definition: AuxKernel.h:150
DenseMatrix< Number > _local_ke
for holding local mass matrix
Definition: AuxKernel.h:162
const OutputTools< ComputeValueType >::VariableTestValue & _test
Holds the the test functions.
Definition: AuxKernel.h:117
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:101
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:120
AuxKernelTempl< RealEigenVector > ArrayAuxKernel
Definition: AuxKernel.h:21
bool isNodal() const
Nodal or elemental kernel?
Definition: AuxKernel.h:43
const GenericMaterialProperty< T, is_ad > & getGenericMaterialProperty(const std::string &name)
Definition: AuxKernel.h:201