Line data Source code
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 "MooseObject.h"
13 : #include "MooseVariableFE.h"
14 : #include "SetupInterface.h"
15 : #include "CoupleableMooseVariableDependencyIntermediateInterface.h"
16 : #include "MaterialPropertyInterface.h"
17 : #include "FunctionInterface.h"
18 : #include "UserObjectInterface.h"
19 : #include "TransientInterface.h"
20 : #include "PostprocessorInterface.h"
21 : #include "DependencyResolverInterface.h"
22 : #include "RandomInterface.h"
23 : #include "GeometricSearchInterface.h"
24 : #include "BlockRestrictable.h"
25 : #include "BoundaryRestrictable.h"
26 : #include "Restartable.h"
27 : #include "MeshChangedInterface.h"
28 : #include "VectorPostprocessorInterface.h"
29 : #include "MooseVariableInterface.h"
30 : #include "ElementIDInterface.h"
31 : #include "UserObject.h"
32 : #include "NonADFunctorInterface.h"
33 :
34 : // forward declarations
35 : template <typename ComputeValueType>
36 : class AuxKernelTempl;
37 :
38 : typedef AuxKernelTempl<Real> AuxKernel;
39 : typedef AuxKernelTempl<RealVectorValue> VectorAuxKernel;
40 : typedef AuxKernelTempl<RealEigenVector> ArrayAuxKernel;
41 :
42 : class SubProblem;
43 : class AuxiliarySystem;
44 : class SystemBase;
45 : class MooseMesh;
46 :
47 : /**
48 : * Base class for creating new auxiliary kernels and auxiliary boundary conditions.
49 : *
50 : */
51 : template <typename ComputeValueType>
52 : class AuxKernelTempl : public MooseObject,
53 : public MooseVariableInterface<ComputeValueType>,
54 : public BlockRestrictable,
55 : public BoundaryRestrictable,
56 : public SetupInterface,
57 : public CoupleableMooseVariableDependencyIntermediateInterface,
58 : public FunctionInterface,
59 : public UserObjectInterface,
60 : public TransientInterface,
61 : public MaterialPropertyInterface,
62 : public PostprocessorInterface,
63 : public DependencyResolverInterface,
64 : public RandomInterface,
65 : public GeometricSearchInterface,
66 : public Restartable,
67 : public MeshChangedInterface,
68 : protected VectorPostprocessorInterface,
69 : public ElementIDInterface,
70 : protected NonADFunctorInterface
71 : {
72 : public:
73 : static InputParameters validParams();
74 :
75 : AuxKernelTempl(const InputParameters & parameters);
76 :
77 : /**
78 : * Computes the value and stores it in the solution vector
79 : */
80 : virtual void compute();
81 :
82 : /**
83 : * Nodal or elemental kernel?
84 : * @return true if this is a nodal kernel, otherwise false
85 : */
86 112881132 : bool isNodal() const { return _nodal; }
87 :
88 : /**
89 : * @return whether this is a mortar auxiliary kernel
90 : */
91 : bool isMortar();
92 :
93 : /**
94 : * Get a reference to a variable this kernel is action on
95 : * @return reference to a variable this kernel is action on
96 : */
97 75431370 : MooseVariableField<ComputeValueType> & variable() { return _var; }
98 :
99 176465 : const std::set<UserObjectName> & getDependObjects() const { return _depend_uo; }
100 :
101 : void coupledCallback(const std::string & var_name, bool is_old) const override;
102 :
103 : virtual const std::set<std::string> & getRequestedItems() override;
104 :
105 : virtual const std::set<std::string> & getSuppliedItems() override;
106 :
107 : /**
108 : * Override functions from MaterialPropertyInterface for error checking
109 : */
110 : template <typename T>
111 : const MaterialProperty<T> & getMaterialProperty(const std::string & name);
112 : template <typename T, bool is_ad>
113 : const GenericMaterialProperty<T, is_ad> & getGenericMaterialProperty(const std::string & name);
114 : template <typename T>
115 : const MaterialProperty<T> & getMaterialPropertyOld(const std::string & name);
116 : template <typename T>
117 : const MaterialProperty<T> & getMaterialPropertyOlder(const std::string & name);
118 :
119 : /**
120 : * Insert the just computed values into the auxiliary solution vector
121 : */
122 : void insert();
123 :
124 : protected:
125 : /**
126 : * Compute and return the value of the aux variable.
127 : */
128 : virtual ComputeValueType computeValue() = 0;
129 :
130 : virtual const VariableValue & coupledDot(const std::string & var_name,
131 : unsigned int comp = 0) const override;
132 :
133 : virtual const VariableValue & coupledDotDu(const std::string & var_name,
134 : unsigned int comp = 0) const override;
135 :
136 : /// This callback is used for AuxKernelTempls that need to perform a per-element calculation
137 46635856 : virtual void precalculateValue() {}
138 :
139 : /**
140 : * Retrieves the old value of the variable that this AuxKernel operates on.
141 : *
142 : * Store this as a _reference_ in the constructor.
143 : */
144 : const typename OutputTools<ComputeValueType>::VariableValue & uOld() const;
145 :
146 : /**
147 : * Retrieves the older value of the variable that this AuxKernel operates on.
148 : *
149 : * Store this as a _reference_ in the constructor.
150 : */
151 : const typename OutputTools<ComputeValueType>::VariableValue & uOlder() const;
152 :
153 : /**
154 : * Whether or not to check for repeated element sides on the sideset to which
155 : * the auxkernel is restricted (if boundary restricted _and_ elemental). Setting
156 : * this to false will allow an element with more than one face on the boundary
157 : * to which it is restricted allow contribution to the element's value(s). This
158 : * flag allows auxkernels that evaluate boundary-restricted elemental auxvariables
159 : * to have more than one element face on the boundary of interest.
160 : */
161 : const bool & _check_boundary_restricted;
162 :
163 : /// Subproblem this kernel is part of
164 : SubProblem & _subproblem;
165 : /// System this kernel is part of
166 : SystemBase & _sys;
167 : SystemBase & _nl_sys;
168 : AuxiliarySystem & _aux_sys;
169 :
170 : /// Thread ID
171 : THREAD_ID _tid;
172 :
173 : /// This is a regular kernel so we cast to a regular MooseVariable
174 : MooseVariableField<ComputeValueType> & _var;
175 :
176 : /// Flag indicating if the AuxKernel is nodal
177 : bool _nodal;
178 :
179 : /// Holds the solution at current quadrature points
180 : const typename OutputTools<ComputeValueType>::VariableValue & _u;
181 :
182 : /// Assembly class
183 : Assembly & _assembly;
184 :
185 : /// true if the kernel is boundary kernel, false if it is interior kernels
186 : bool _bnd;
187 : /// Mesh this kernel is active on
188 : MooseMesh & _mesh;
189 : /// Dimension of the problem being solved
190 : // unsigned int _dim;
191 :
192 : /// Holds the the test functions
193 : const typename OutputTools<ComputeValueType>::VariableTestValue & _test;
194 :
195 : /// Active quadrature points
196 : const MooseArray<Point> & _q_point;
197 : /// Quadrature rule being used
198 : const QBase * const & _qrule;
199 : /// Transformed Jacobian weights
200 : const MooseArray<Real> & _JxW;
201 : const MooseArray<Real> & _coord;
202 :
203 : /// Current element (valid only for elemental kernels)
204 : const Elem * const & _current_elem;
205 : /// current side of the current element
206 : const unsigned int & _current_side;
207 :
208 : /// Volume of the current element
209 : const Real & _current_elem_volume;
210 : /// Volume of the current side
211 : const Real & _current_side_volume;
212 :
213 : /// Current node (valid only for nodal kernels)
214 : const Node * const & _current_node;
215 :
216 : /// The current boundary ID
217 : const BoundaryID & _current_boundary_id;
218 :
219 : /// reference to the solution vector of auxiliary system
220 : NumericVector<Number> & _solution;
221 :
222 : /// The current lower dimensional element
223 : const Elem * const & _current_lower_d_elem;
224 :
225 : /// Whether we are computing for a lower dimensional variable using boundary restriction, e.g. a
226 : /// variable whose block restriction is coincident with a higher-dimensional boundary face
227 : const bool _coincident_lower_d_calc;
228 :
229 : /// Quadrature point index
230 : unsigned int _qp;
231 :
232 : /// number of local dofs for elemental variables
233 : unsigned int _n_local_dofs;
234 :
235 : typedef typename Moose::DOFType<ComputeValueType>::type OutputData;
236 :
237 : /// for holding local load
238 : DenseVector<OutputData> _local_re;
239 : /// for holding local solution
240 : DenseVector<OutputData> _local_sol;
241 : /// for holding local mass matrix
242 : DenseMatrix<Number> _local_ke;
243 :
244 : using MooseVariableInterface<ComputeValueType>::mooseVariableBase;
245 :
246 : private:
247 : void addPostprocessorDependencyHelper(const PostprocessorName & name) const override final;
248 : void addUserObjectDependencyHelper(const UserObject & uo) const override final;
249 : void
250 : addVectorPostprocessorDependencyHelper(const VectorPostprocessorName & name) const override final;
251 :
252 : /**
253 : * Currently only used when the auxiliary variable is a finite volume variable, this helps call
254 : * through to the variable's \p setDofValue method. This helper is necessary because \p
255 : * MooseVariableField::setDofValue expects a \p Real even when a variable is a vector variable, so
256 : * we cannot simply pass through to that method with the result of \p computeValue when \p
257 : * ComputeValueType is \p RealVectorValue
258 : */
259 : void setDofValueHelper(const ComputeValueType & dof_value);
260 :
261 : /// Depend AuxKernelTempls
262 : mutable std::set<std::string> _depend_vars;
263 : std::set<std::string> _supplied_vars;
264 :
265 : /// Depend UserObjects
266 : mutable std::set<UserObjectName> _depend_uo;
267 : };
268 :
269 : template <typename ComputeValueType>
270 : template <typename T>
271 : const MaterialProperty<T> &
272 215 : AuxKernelTempl<ComputeValueType>::getMaterialProperty(const std::string & name)
273 : {
274 215 : if (isNodal())
275 0 : mooseError("Nodal AuxKernel '",
276 0 : AuxKernelTempl::name(),
277 : "' attempted to reference material property '",
278 : name,
279 : "'\nConsider using an elemental auxiliary variable for '",
280 0 : _var.name(),
281 : "'.");
282 :
283 215 : return MaterialPropertyInterface::getMaterialProperty<T>(name);
284 : }
285 :
286 : template <typename ComputeValueType>
287 : template <typename T, bool is_ad>
288 : const GenericMaterialProperty<T, is_ad> &
289 33841 : AuxKernelTempl<ComputeValueType>::getGenericMaterialProperty(const std::string & name)
290 : {
291 33841 : if (isNodal())
292 4 : mooseError("Nodal AuxKernel '",
293 4 : AuxKernelTempl::name(),
294 : "' attempted to reference material property '",
295 : name,
296 : "'\nConsider using an elemental auxiliary variable for '",
297 4 : _var.name(),
298 : "'.");
299 :
300 33837 : return MaterialPropertyInterface::getGenericMaterialProperty<T, is_ad>(name);
301 : }
302 :
303 : template <typename ComputeValueType>
304 : template <typename T>
305 : const MaterialProperty<T> &
306 26 : AuxKernelTempl<ComputeValueType>::getMaterialPropertyOld(const std::string & name)
307 : {
308 26 : if (isNodal())
309 0 : mooseError("Nodal AuxKernel '",
310 0 : AuxKernelTempl::name(),
311 : "' attempted to reference material property '",
312 : name,
313 : "'\nConsider using an elemental auxiliary variable for '",
314 0 : _var.name(),
315 : "'.");
316 :
317 26 : return MaterialPropertyInterface::getMaterialPropertyOld<T>(name);
318 : }
319 :
320 : template <typename ComputeValueType>
321 : template <typename T>
322 : const MaterialProperty<T> &
323 13 : AuxKernelTempl<ComputeValueType>::getMaterialPropertyOlder(const std::string & name)
324 : {
325 13 : if (isNodal())
326 0 : mooseError("Nodal AuxKernel '",
327 0 : AuxKernelTempl::name(),
328 : "' attempted to reference material property '",
329 : name,
330 : "'\nConsider using an elemental auxiliary variable for '",
331 0 : _var.name(),
332 : "'.");
333 :
334 13 : return MaterialPropertyInterface::getMaterialPropertyOlder<T>(name);
335 : }
336 :
337 : // Declare all the specializations, as the template specialization declaration below must know
338 : template <>
339 : void AuxKernelTempl<Real>::setDofValueHelper(const Real & value);
340 : template <>
341 : void AuxKernelTempl<RealVectorValue>::setDofValueHelper(const RealVectorValue &);
342 : template <>
343 : void AuxKernelTempl<RealEigenVector>::compute();
344 :
345 : // Prevent implicit instantiation in other translation units where these classes are used
346 : extern template class AuxKernelTempl<Real>;
347 : extern template class AuxKernelTempl<RealVectorValue>;
348 : extern template class AuxKernelTempl<RealEigenVector>;
|