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 "AuxKernelBase.h" 13 : #include "MooseVariableInterface.h" 14 : 15 : // forward declarations 16 : template <typename ComputeValueType> 17 : class AuxKernelTempl; 18 : 19 : typedef AuxKernelTempl<Real> AuxKernel; 20 : typedef AuxKernelTempl<RealVectorValue> VectorAuxKernel; 21 : typedef AuxKernelTempl<RealEigenVector> ArrayAuxKernel; 22 : 23 : /** 24 : * Base class for creating new auxiliary kernels and auxiliary boundary conditions. 25 : */ 26 : template <typename ComputeValueType> 27 : class AuxKernelTempl : public AuxKernelBase, public MooseVariableInterface<ComputeValueType> 28 : { 29 : public: 30 : static InputParameters validParams(); 31 : 32 : AuxKernelTempl(const InputParameters & parameters); 33 : 34 : /** 35 : * Computes the value and stores it in the solution vector 36 : */ 37 : virtual void compute() override; 38 : 39 : /** 40 : * Nodal or elemental kernel? 41 : * @return true if this is a nodal kernel, otherwise false 42 : */ 43 127403066 : bool isNodal() const { return _nodal; } 44 : 45 : /** 46 : * @return whether this is a mortar auxiliary kernel 47 : */ 48 : bool isMortar(); 49 : 50 : /** 51 : * Get a reference to a variable this kernel is action on 52 : * @return reference to a variable this kernel is action on 53 : */ 54 85271467 : MooseVariableField<ComputeValueType> & variable() { return _var; } 55 : 56 : /** 57 : * Override functions from MaterialPropertyInterface for error checking 58 : */ 59 : template <typename T> 60 : const MaterialProperty<T> & getMaterialProperty(const std::string & name); 61 : template <typename T, bool is_ad> 62 : const GenericMaterialProperty<T, is_ad> & getGenericMaterialProperty(const std::string & name); 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 : 68 : /** 69 : * Insert the just computed values into the auxiliary solution vector 70 : */ 71 : void insert(); 72 : 73 : protected: 74 : /** 75 : * Compute and return the value of the aux variable. 76 : */ 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 : 85 : /// This callback is used for AuxKernelTempls that need to perform a per-element calculation 86 52736836 : virtual void precalculateValue() {} 87 : 88 : /** 89 : * Retrieves the old value of the variable that this AuxKernel operates on. 90 : * 91 : * Store this as a _reference_ in the constructor. 92 : */ 93 : const typename OutputTools<ComputeValueType>::VariableValue & uOld() const; 94 : 95 : /** 96 : * Retrieves the older value of the variable that this AuxKernel operates on. 97 : * 98 : * Store this as a _reference_ in the constructor. 99 : */ 100 : const typename OutputTools<ComputeValueType>::VariableValue & uOlder() const; 101 : 102 : /// This is a regular kernel so we cast to a regular MooseVariable, hides base _var 103 : MooseVariableField<ComputeValueType> & _var; 104 : 105 : /// Flag indicating if the AuxKernel is nodal 106 : const bool _nodal; 107 : 108 : /// Holds the solution at current quadrature points 109 : const typename OutputTools<ComputeValueType>::VariableValue & _u; 110 : 111 : /// Holds the the test functions 112 : const typename OutputTools<ComputeValueType>::VariableTestValue & _test; 113 : 114 : /// Active quadrature points 115 : const MooseArray<Point> & _q_point; 116 : /// Quadrature rule being used 117 : const QBase * const & _qrule; 118 : /// Transformed Jacobian weights 119 : const MooseArray<Real> & _JxW; 120 : const MooseArray<Real> & _coord; 121 : 122 : /// Current element (valid only for elemental kernels) 123 : const Elem * const & _current_elem; 124 : /// current side of the current element 125 : const unsigned int & _current_side; 126 : 127 : /// Volume of the current element 128 : const Real & _current_elem_volume; 129 : /// Volume of the current side 130 : const Real & _current_side_volume; 131 : 132 : /// Current node (valid only for nodal kernels) 133 : const Node * const & _current_node; 134 : 135 : /// The current boundary ID 136 : const BoundaryID & _current_boundary_id; 137 : 138 : /// reference to the solution vector of auxiliary system 139 : NumericVector<Number> & _solution; 140 : 141 : /// The current lower dimensional element 142 : const Elem * const & _current_lower_d_elem; 143 : 144 : /// Quadrature point index 145 : unsigned int _qp; 146 : 147 : /// number of local dofs for elemental variables 148 : unsigned int _n_local_dofs; 149 : 150 : typedef typename Moose::DOFType<ComputeValueType>::type OutputData; 151 : 152 : /// for holding local load 153 : DenseVector<OutputData> _local_re; 154 : /// for holding local solution 155 : DenseVector<OutputData> _local_sol; 156 : /// for holding local mass matrix 157 : DenseMatrix<Number> _local_ke; 158 : 159 : using MooseVariableInterface<ComputeValueType>::mooseVariableBase; 160 : 161 : private: 162 : /** 163 : * Currently only used when the auxiliary variable is a finite volume variable, this helps call 164 : * through to the variable's \p setDofValue method. This helper is necessary because \p 165 : * MooseVariableField::setDofValue expects a \p Real even when a variable is a vector variable, so 166 : * we cannot simply pass through to that method with the result of \p computeValue when \p 167 : * ComputeValueType is \p RealVectorValue 168 : */ 169 : void setDofValueHelper(const ComputeValueType & dof_value); 170 : }; 171 : 172 : template <typename ComputeValueType> 173 : template <typename T> 174 : const MaterialProperty<T> & 175 233 : AuxKernelTempl<ComputeValueType>::getMaterialProperty(const std::string & name) 176 : { 177 233 : if (isNodal()) 178 0 : mooseError("Nodal AuxKernel '", 179 0 : AuxKernelTempl::name(), 180 : "' attempted to reference material property '", 181 : name, 182 : "'\nConsider using an elemental auxiliary variable for '", 183 0 : _var.name(), 184 : "'."); 185 : 186 233 : return MaterialPropertyInterface::getMaterialProperty<T>(name); 187 : } 188 : 189 : template <typename ComputeValueType> 190 : template <typename T, bool is_ad> 191 : const GenericMaterialProperty<T, is_ad> & 192 36087 : AuxKernelTempl<ComputeValueType>::getGenericMaterialProperty(const std::string & name) 193 : { 194 36087 : if (isNodal()) 195 4 : mooseError("Nodal AuxKernel '", 196 4 : AuxKernelTempl::name(), 197 : "' attempted to reference material property '", 198 : name, 199 : "'\nConsider using an elemental auxiliary variable for '", 200 4 : _var.name(), 201 : "'."); 202 : 203 36083 : return MaterialPropertyInterface::getGenericMaterialProperty<T, is_ad>(name); 204 : } 205 : 206 : template <typename ComputeValueType> 207 : template <typename T> 208 : const MaterialProperty<T> & 209 28 : AuxKernelTempl<ComputeValueType>::getMaterialPropertyOld(const std::string & name) 210 : { 211 28 : if (isNodal()) 212 0 : mooseError("Nodal AuxKernel '", 213 0 : AuxKernelTempl::name(), 214 : "' attempted to reference material property '", 215 : name, 216 : "'\nConsider using an elemental auxiliary variable for '", 217 0 : _var.name(), 218 : "'."); 219 : 220 28 : return MaterialPropertyInterface::getMaterialPropertyOld<T>(name); 221 : } 222 : 223 : template <typename ComputeValueType> 224 : template <typename T> 225 : const MaterialProperty<T> & 226 14 : AuxKernelTempl<ComputeValueType>::getMaterialPropertyOlder(const std::string & name) 227 : { 228 14 : if (isNodal()) 229 0 : mooseError("Nodal AuxKernel '", 230 0 : AuxKernelTempl::name(), 231 : "' attempted to reference material property '", 232 : name, 233 : "'\nConsider using an elemental auxiliary variable for '", 234 0 : _var.name(), 235 : "'."); 236 : 237 14 : 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 <> 244 : void AuxKernelTempl<RealVectorValue>::setDofValueHelper(const RealVectorValue &); 245 : template <> 246 : void AuxKernelTempl<RealEigenVector>::compute(); 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>;