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 
79  virtual std::set<MooseVariableFieldBase *>
80  checkVariables(const libMesh::Node & node,
81  const std::set<MooseVariableFieldBase *> & vars_to_check) override;
82 
83 protected:
87  virtual ComputeValueType computeValue() = 0;
88 
89  virtual const VariableValue & coupledDot(const std::string & var_name,
90  unsigned int comp = 0) const override;
91 
92  virtual const VariableValue & coupledDotDu(const std::string & var_name,
93  unsigned int comp = 0) const override;
94 
96  virtual void precalculateValue() {}
97 
103  const typename OutputTools<ComputeValueType>::VariableValue & uOld() const;
104 
110  const typename OutputTools<ComputeValueType>::VariableValue & uOlder() const;
111 
114 
116  const bool _nodal;
117 
120 
123 
127  const QBase * const & _qrule;
131 
133  const Elem * const & _current_elem;
135  const unsigned int & _current_side;
136 
141 
143  const Node * const & _current_node;
144 
147 
150 
152  const Elem * const & _current_lower_d_elem;
153 
155  unsigned int _qp;
156 
158  unsigned int _n_shapes;
159 
161 
163  DenseVector<OutputData> _local_re;
165  DenseVector<OutputData> _local_sol;
168 
171  std::optional<bool> _coincident_lower_d_calc;
172 
174 
175 private:
183  void setDofValueHelper(const ComputeValueType & dof_value);
184 };
185 
186 template <typename ComputeValueType>
187 template <typename T>
188 const MaterialProperty<T> &
190 {
191  if (isNodal())
192  mooseError("Nodal AuxKernel '",
194  "' attempted to reference material property '",
195  name,
196  "'\nConsider using an elemental auxiliary variable for '",
197  _var.name(),
198  "'.");
199 
200  return MaterialPropertyInterface::getMaterialProperty<T>(name);
201 }
202 
203 template <typename ComputeValueType>
204 template <typename T, bool is_ad>
207 {
208  if (isNodal())
209  mooseError("Nodal AuxKernel '",
211  "' attempted to reference material property '",
212  name,
213  "'\nConsider using an elemental auxiliary variable for '",
214  _var.name(),
215  "'.");
216 
217  return MaterialPropertyInterface::getGenericMaterialProperty<T, is_ad>(name);
218 }
219 
220 template <typename ComputeValueType>
221 template <typename T>
222 const MaterialProperty<T> &
224 {
225  if (isNodal())
226  mooseError("Nodal AuxKernel '",
228  "' attempted to reference material property '",
229  name,
230  "'\nConsider using an elemental auxiliary variable for '",
231  _var.name(),
232  "'.");
233 
234  return MaterialPropertyInterface::getMaterialPropertyOld<T>(name);
235 }
236 
237 template <typename ComputeValueType>
238 template <typename T>
239 const MaterialProperty<T> &
241 {
242  if (isNodal())
243  mooseError("Nodal AuxKernel '",
245  "' attempted to reference material property '",
246  name,
247  "'\nConsider using an elemental auxiliary variable for '",
248  _var.name(),
249  "'.");
250 
251  return MaterialPropertyInterface::getMaterialPropertyOlder<T>(name);
252 }
253 
254 // Declare all the specializations, as the template specialization declaration below must know
255 template <>
256 void AuxKernelTempl<Real>::setDofValueHelper(const Real & value);
257 template <>
259 template <>
261 
262 // Prevent implicit instantiation in other translation units where these classes are used
263 extern template class AuxKernelTempl<Real>;
264 extern template class AuxKernelTempl<RealVectorValue>;
265 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:119
AuxKernelTempl< RealVectorValue > VectorAuxKernel
Definition: AuxKernel.h:20
Base class for auxiliary kernels.
Definition: AuxKernelBase.h:42
const MooseArray< Real > & _coord
Definition: AuxKernel.h:130
const unsigned int & _current_side
current side of the current element
Definition: AuxKernel.h:135
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:140
virtual std::set< MooseVariableFieldBase * > checkVariables(const libMesh::Node &node, const std::set< MooseVariableFieldBase *> &vars_to_check)
Check whether all of the supplied variables have degree of freedom indices on the supplied node...
const Node *const & _current_node
Current node (valid only for nodal kernels)
Definition: AuxKernel.h:143
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
virtual std::set< MooseVariableFieldBase * > checkVariables(const libMesh::Node &node, const std::set< MooseVariableFieldBase *> &vars_to_check) override
Check whether all of the supplied variables have degree of freedom indices on the supplied node...
Definition: AuxKernel.C:357
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:146
DenseVector< OutputData > _local_sol
for holding local solution
Definition: AuxKernel.h:165
AuxKernelTempl< Real > AuxKernel
Definition: AuxKernel.h:17
const MooseArray< Real > & _JxW
Transformed Jacobian weights.
Definition: AuxKernel.h:129
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:163
virtual void precalculateValue()
This callback is used for AuxKernelTempls that need to perform a per-element calculation.
Definition: AuxKernel.h:96
unsigned int _n_shapes
number of shape functions for the finite element type and current DofObject
Definition: AuxKernel.h:158
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:138
std::optional< bool > _coincident_lower_d_calc
Whether we are computing for a lower dimensional variable using boundary restriction, e.g.
Definition: AuxKernel.h:171
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:152
OutputTools< Real >::VariableValue VariableValue
Definition: MooseTypes.h:343
NumericVector< Number > & _solution
reference to the solution vector of auxiliary system
Definition: AuxKernel.h:149
const MaterialProperty< T > & getMaterialPropertyOld(const std::string &name)
Definition: AuxKernel.h:223
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:113
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const QBase *const & _qrule
Quadrature rule being used.
Definition: AuxKernel.h:127
const bool _nodal
Flag indicating if the AuxKernel is nodal.
Definition: AuxKernel.h:116
const MaterialProperty< T > & getMaterialPropertyOlder(const std::string &name)
Definition: AuxKernel.h:240
Moose::DOFType< ComputeValueType >::type OutputData
Definition: AuxKernel.h:160
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:189
const Elem *const & _current_elem
Current element (valid only for elemental kernels)
Definition: AuxKernel.h:133
unsigned int _qp
Quadrature point index.
Definition: AuxKernel.h:155
DenseMatrix< Number > _local_ke
for holding local mass matrix
Definition: AuxKernel.h:167
const OutputTools< ComputeValueType >::VariableTestValue & _test
Holds the the test functions.
Definition: AuxKernel.h:122
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:125
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:206