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 "MooseVariableBase.h" 13 : 14 : // Forward declarations 15 : class Assembly; 16 : class MooseObject; 17 : template <typename T> 18 : class MooseVariableField; 19 : template <typename T> 20 : class MooseVariableFE; 21 : template <typename T> 22 : class MooseVariableFV; 23 : template <typename T> 24 : class MooseLinearVariableFV; 25 : 26 : /** 27 : * Interface for objects that need to get values of MooseVariables 28 : */ 29 : template <typename T> 30 : class MooseVariableInterface 31 : { 32 : public: 33 : /** 34 : * Constructing the object 35 : * @param parameters Parameters that come from constructing the object 36 : * @param nodal true if the variable is nodal 37 : * @param var_param_name the parameter name where we will find the coupled variable name 38 : */ 39 : MooseVariableInterface( 40 : const MooseObject * moose_object, 41 : bool nodal, 42 : std::string var_param_name = "variable", 43 : Moose::VarKindType expected_var_type = Moose::VarKindType::VAR_ANY, 44 : Moose::VarFieldType expected_var_field_type = Moose::VarFieldType::VAR_FIELD_ANY); 45 : 46 : /** 47 : * Get the variable that this object is using. 48 : * @return The variable this object is using. 49 : */ 50 917330 : MooseVariableBase * mooseVariableBase() const { return _var; }; 51 : 52 : /** 53 : * Return the \p MooseVariableField object that this interface acts on 54 : */ 55 : MooseVariableField<T> & mooseVariableField(); 56 : 57 : /** 58 : * Return the \p MooseVariableFE object that this interface acts on 59 : */ 60 : MooseVariableFE<T> * mooseVariable() const; 61 : 62 : /** 63 : * Return the \p MooseVariableFV object that this interface acts on 64 : */ 65 : MooseVariableFV<T> * mooseVariableFV() const; 66 : 67 : /** 68 : * Return the \p MooseLinearVariableFV object that this interface acts on 69 : */ 70 : MooseLinearVariableFV<T> * mooseLinearVariableFV() const; 71 : 72 : virtual ~MooseVariableInterface(); 73 : 74 : protected: 75 : /** 76 : * The value of the variable this object is operating on. 77 : * 78 : * This is computed by default and should already be available as _u 79 : * 80 : * @return The reference to be stored off and used later. 81 : */ 82 : virtual const typename OutputTools<T>::VariableValue & value(); 83 : 84 : /** 85 : * The old value of the variable this object is operating on. 86 : * 87 : * @return The reference to be stored off and used later. 88 : */ 89 : virtual const typename OutputTools<T>::VariableValue & valueOld(); 90 : 91 : /** 92 : * The older value of the variable this object is operating on. 93 : * 94 : * @return The reference to be stored off and used later. 95 : */ 96 : virtual const typename OutputTools<T>::VariableValue & valueOlder(); 97 : 98 : /** 99 : * The time derivative of the variable this object is operating on. 100 : * 101 : * @return The reference to be stored off and used later. 102 : */ 103 : virtual const typename OutputTools<T>::VariableValue & dot(); 104 : 105 : /** 106 : * The second time derivative of the variable this object is operating on. 107 : * 108 : * @return The reference to be stored off and used later. 109 : */ 110 : virtual const typename OutputTools<T>::VariableValue & dotDot(); 111 : 112 : /** 113 : * The old time derivative of the variable this object is operating on. 114 : * 115 : * @return The reference to be stored off and used later. 116 : */ 117 : virtual const typename OutputTools<T>::VariableValue & dotOld(); 118 : 119 : /** 120 : * The old second time derivative of the variable this object is operating on. 121 : * 122 : * @return The reference to be stored off and used later. 123 : */ 124 : virtual const typename OutputTools<T>::VariableValue & dotDotOld(); 125 : 126 : /** 127 : * The derivative of the time derivative of the variable this object is operating on 128 : * with respect to this variable's coefficients. 129 : * 130 : * This is useful for creating Jacobian entries for residual statements that use _u_dot 131 : * 132 : * @return The reference to be stored off and used later. 133 : */ 134 : virtual const VariableValue & dotDu(); 135 : 136 : /** 137 : * The derivative of the second time derivative of the variable this object is operating on 138 : * with respect to this variable's coefficients. 139 : * 140 : * This is useful for creating Jacobian entries for residual statements that use _u_dotdot 141 : * 142 : * @return The reference to be stored off and used later. 143 : */ 144 : virtual const VariableValue & dotDotDu(); 145 : 146 : /** 147 : * The gradient of the variable this object is operating on. 148 : * 149 : * This is computed by default and should already be available as _grad_u 150 : * 151 : * @return The reference to be stored off and used later. 152 : */ 153 : virtual const typename OutputTools<T>::VariableGradient & gradient(); 154 : 155 : /** 156 : * The old gradient of the variable this object is operating on. 157 : * 158 : * @return The reference to be stored off and used later. 159 : */ 160 : virtual const typename OutputTools<T>::VariableGradient & gradientOld(); 161 : 162 : /** 163 : * The older gradient of the variable this object is operating on. 164 : * 165 : * @return The reference to be stored off and used later. 166 : */ 167 : virtual const typename OutputTools<T>::VariableGradient & gradientOlder(); 168 : 169 : /** 170 : * The second derivative of the variable this object is operating on. 171 : * 172 : * @return The reference to be stored off and used later. 173 : */ 174 : virtual const typename OutputTools<T>::VariableSecond & second(); 175 : 176 : /** 177 : * The old second derivative of the variable this object is operating on. 178 : * 179 : * @return The reference to be stored off and used later. 180 : */ 181 : virtual const typename OutputTools<T>::VariableSecond & secondOld(); 182 : 183 : /** 184 : * The older second derivative of the variable this object is operating on. 185 : * 186 : * @return The reference to be stored off and used later. 187 : */ 188 : virtual const typename OutputTools<T>::VariableSecond & secondOlder(); 189 : 190 : /** 191 : * The second derivative of the test function. 192 : * 193 : * @return The reference to be stored off and used later. 194 : */ 195 : virtual const typename OutputTools<T>::VariableTestSecond & secondTest(); 196 : 197 : /** 198 : * The second derivative of the test function on the current face. 199 : * This should be called in e.g. IntegratedBC when you need second 200 : * derivatives of the test function function on the boundary. 201 : * 202 : * @return The reference to be stored off and used later. 203 : */ 204 : virtual const typename OutputTools<T>::VariableTestSecond & secondTestFace(); 205 : 206 : /** 207 : * The second derivative of the trial function. 208 : * 209 : * @return The reference to be stored off and used later. 210 : */ 211 : virtual const typename OutputTools<T>::VariablePhiSecond & secondPhi(); 212 : 213 : /** 214 : * The second derivative of the trial function on the current face. 215 : * This should be called in e.g. IntegratedBC when you need second 216 : * derivatives of the trial function function on the boundary. 217 : * 218 : * @return The reference to be stored off and used later. 219 : */ 220 : virtual const typename OutputTools<T>::VariablePhiSecond & secondPhiFace(); 221 : 222 : /// Whether or not this object is acting only at nodes 223 : bool _nodal; 224 : 225 : /// The variable this object is acting on 226 : MooseVariableBase * _var = nullptr; 227 : MooseVariableFE<T> * _variable = nullptr; 228 : MooseVariableFV<T> * _fv_variable = nullptr; 229 : MooseLinearVariableFV<T> * _linear_fv_variable = nullptr; 230 : MooseVariableField<T> * _field_variable = nullptr; 231 : 232 : protected: 233 : Assembly * _mvi_assembly; 234 : 235 : private: 236 : const MooseObject & _moose_object; 237 : }; 238 : 239 : // Declare all the specializations, as the template specialization declaration below must know 240 : template <> 241 : const VectorVariableValue & MooseVariableInterface<RealVectorValue>::value(); 242 : template <> 243 : const VectorVariableValue & MooseVariableInterface<RealVectorValue>::valueOld(); 244 : template <> 245 : const VectorVariableValue & MooseVariableInterface<RealVectorValue>::valueOlder(); 246 : template <> 247 : const VectorVariableValue & MooseVariableInterface<RealVectorValue>::dot(); 248 : template <> 249 : const VectorVariableValue & MooseVariableInterface<RealVectorValue>::dotDot(); 250 : template <> 251 : const VectorVariableValue & MooseVariableInterface<RealVectorValue>::dotOld(); 252 : template <> 253 : const VectorVariableValue & MooseVariableInterface<RealVectorValue>::dotDotOld(); 254 : 255 : // Prevent implicit instantiation in other translation units where these classes are used 256 : extern template class MooseVariableInterface<Real>; 257 : extern template class MooseVariableInterface<RealVectorValue>; 258 : extern template class MooseVariableInterface<RealEigenVector>;