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 : #include "MooseVariableInterface.h" 11 : 12 : #include "Assembly.h" 13 : #include "MooseError.h" // mooseDeprecated 14 : #include "MooseTypes.h" 15 : #include "MooseVariableFE.h" 16 : #include "MooseVariableFV.h" 17 : #include "MooseLinearVariableFV.h" 18 : #include "Problem.h" 19 : #include "SubProblem.h" 20 : #include "SystemBase.h" 21 : 22 : template <typename T> 23 289143 : MooseVariableInterface<T>::MooseVariableInterface(const MooseObject * moose_object, 24 : bool nodal, 25 : std::string var_param_name, 26 : Moose::VarKindType expected_var_type, 27 : Moose::VarFieldType expected_var_field_type) 28 289143 : : _nodal(nodal), _moose_object(*moose_object) 29 : { 30 289143 : const InputParameters & parameters = _moose_object.parameters(); 31 : 32 289143 : SubProblem & problem = *parameters.getCheckedPointerParam<SubProblem *>("_subproblem"); 33 : 34 289143 : THREAD_ID tid = parameters.get<THREAD_ID>("_tid"); 35 : 36 289143 : _var = &problem.getVariable(tid, 37 289143 : parameters.varName(var_param_name, moose_object->name()), 38 : expected_var_type, 39 : expected_var_field_type); 40 289135 : if (!(_variable = dynamic_cast<MooseVariableFE<T> *>(_var))) 41 25442 : if (!(_fv_variable = dynamic_cast<MooseVariableFV<T> *>(_var))) 42 4936 : _linear_fv_variable = dynamic_cast<MooseLinearVariableFV<T> *>(_var); 43 289135 : if (!(_field_variable = dynamic_cast<MooseVariableField<T> *>(_var))) 44 0 : mooseError("The variable supplied to the variable interface is not of field type"); 45 : 46 289135 : _mvi_assembly = 47 289135 : &problem.assembly(tid, (_var->kind() == Moose::VAR_SOLVER) ? _var->sys().number() : 0); 48 289135 : } 49 : 50 : template <typename T> 51 277204 : MooseVariableInterface<T>::~MooseVariableInterface() 52 : { 53 277204 : } 54 : 55 : template <typename T> 56 : MooseVariableFV<T> * 57 16768 : MooseVariableInterface<T>::mooseVariableFV() const 58 : { 59 16768 : if (!_fv_variable) 60 8 : mooseError("_fv_variable is null in ", 61 4 : _moose_object.name(), 62 : ". Did you forget to set fv = true in the Variables block?"); 63 16764 : return _fv_variable; 64 : } 65 : 66 : template <typename T> 67 : MooseLinearVariableFV<T> * 68 4632 : MooseVariableInterface<T>::mooseLinearVariableFV() const 69 : { 70 4632 : if (!_linear_fv_variable) 71 0 : mooseError( 72 0 : "The variable defined in ", _moose_object.name(), " is not a MooseLinearVariableFV!"); 73 4632 : return _linear_fv_variable; 74 : } 75 : 76 : template <typename T> 77 : MooseVariableFE<T> * 78 327323 : MooseVariableInterface<T>::mooseVariable() const 79 : { 80 327323 : if (!_variable) 81 0 : mooseError( 82 0 : "_variable is null in ", _moose_object.name(), ". Are you using a finite volume variable?"); 83 327323 : return _variable; 84 : } 85 : 86 : template <typename T> 87 : const typename OutputTools<T>::VariableValue & 88 0 : MooseVariableInterface<T>::value() 89 : { 90 0 : if (_nodal) 91 0 : return _variable->dofValues(); 92 : else 93 0 : return _variable->sln(); 94 : } 95 : 96 : template <> 97 : const VectorVariableValue & 98 0 : MooseVariableInterface<RealVectorValue>::value() 99 : { 100 0 : if (_nodal) 101 0 : mooseError("Dofs are scalars while vector variables have vector values. Mismatch"); 102 : else 103 0 : return _variable->sln(); 104 : } 105 : 106 : template <typename T> 107 : const typename OutputTools<T>::VariableValue & 108 0 : MooseVariableInterface<T>::valueOld() 109 : { 110 0 : if (_nodal) 111 0 : return _variable->dofValuesOld(); 112 : else 113 0 : return _variable->slnOld(); 114 : } 115 : 116 : template <> 117 : const VectorVariableValue & 118 0 : MooseVariableInterface<RealVectorValue>::valueOld() 119 : { 120 0 : if (_nodal) 121 0 : mooseError("Dofs are scalars while vector variables have vector values. Mismatch"); 122 : else 123 0 : return _variable->slnOld(); 124 : } 125 : 126 : template <typename T> 127 : const typename OutputTools<T>::VariableValue & 128 0 : MooseVariableInterface<T>::valueOlder() 129 : { 130 0 : if (_nodal) 131 0 : return _variable->dofValuesOlder(); 132 : else 133 0 : return _variable->slnOlder(); 134 : } 135 : 136 : template <> 137 : const VectorVariableValue & 138 0 : MooseVariableInterface<RealVectorValue>::valueOlder() 139 : { 140 0 : if (_nodal) 141 0 : mooseError("Dofs are scalars while vector variables have vector values. Mismatch"); 142 : else 143 0 : return _variable->slnOlder(); 144 : } 145 : 146 : template <typename T> 147 : const typename OutputTools<T>::VariableValue & 148 0 : MooseVariableInterface<T>::dot() 149 : { 150 0 : if (_nodal) 151 0 : return _variable->dofValuesDot(); 152 : else 153 0 : return _variable->uDot(); 154 : } 155 : 156 : template <typename T> 157 : const typename OutputTools<T>::VariableValue & 158 0 : MooseVariableInterface<T>::dotDot() 159 : { 160 0 : if (_nodal) 161 0 : return _variable->dofValuesDotDot(); 162 : else 163 0 : return _variable->uDotDot(); 164 : } 165 : 166 : template <typename T> 167 : const typename OutputTools<T>::VariableValue & 168 0 : MooseVariableInterface<T>::dotOld() 169 : { 170 0 : if (_nodal) 171 0 : return _variable->dofValuesDotOld(); 172 : else 173 0 : return _variable->uDotOld(); 174 : } 175 : 176 : template <typename T> 177 : const typename OutputTools<T>::VariableValue & 178 0 : MooseVariableInterface<T>::dotDotOld() 179 : { 180 0 : if (_nodal) 181 0 : return _variable->dofValuesDotDotOld(); 182 : else 183 0 : return _variable->uDotDotOld(); 184 : } 185 : 186 : template <> 187 : const VectorVariableValue & 188 0 : MooseVariableInterface<RealVectorValue>::dot() 189 : { 190 0 : if (_nodal) 191 0 : mooseError("Dofs are scalars while vector variables have vector values. Mismatch"); 192 : else 193 0 : return _variable->uDot(); 194 : } 195 : 196 : template <> 197 : const VectorVariableValue & 198 0 : MooseVariableInterface<RealVectorValue>::dotDot() 199 : { 200 0 : if (_nodal) 201 0 : mooseError("Dofs are scalars while vector variables have vector values. Mismatch"); 202 : else 203 0 : return _variable->uDotDot(); 204 : } 205 : 206 : template <> 207 : const VectorVariableValue & 208 0 : MooseVariableInterface<RealVectorValue>::dotOld() 209 : { 210 0 : if (_nodal) 211 0 : mooseError("Dofs are scalars while vector variables have vector values. Mismatch"); 212 : else 213 0 : return _variable->uDotOld(); 214 : } 215 : 216 : template <> 217 : const VectorVariableValue & 218 0 : MooseVariableInterface<RealVectorValue>::dotDotOld() 219 : { 220 0 : if (_nodal) 221 0 : mooseError("Dofs are scalars while vector variables have vector values. Mismatch"); 222 : else 223 0 : return _variable->uDotDotOld(); 224 : } 225 : 226 : template <typename T> 227 : const VariableValue & 228 0 : MooseVariableInterface<T>::dotDu() 229 : { 230 0 : if (_nodal) 231 0 : return _variable->dofValuesDuDotDu(); 232 : else 233 0 : return _variable->duDotDu(); 234 : } 235 : 236 : template <typename T> 237 : const VariableValue & 238 0 : MooseVariableInterface<T>::dotDotDu() 239 : { 240 0 : if (_nodal) 241 0 : return _variable->dofValuesDuDotDotDu(); 242 : else 243 0 : return _variable->duDotDotDu(); 244 : } 245 : 246 : template <typename T> 247 : const typename OutputTools<T>::VariableGradient & 248 0 : MooseVariableInterface<T>::gradient() 249 : { 250 0 : if (_nodal) 251 0 : mooseError("gradients are not defined at nodes"); 252 : 253 0 : return _variable->gradSln(); 254 : } 255 : 256 : template <typename T> 257 : const typename OutputTools<T>::VariableGradient & 258 0 : MooseVariableInterface<T>::gradientOld() 259 : { 260 0 : if (_nodal) 261 0 : mooseError("gradients are not defined at nodes"); 262 : 263 0 : return _variable->gradSlnOld(); 264 : } 265 : 266 : template <typename T> 267 : const typename OutputTools<T>::VariableGradient & 268 0 : MooseVariableInterface<T>::gradientOlder() 269 : { 270 0 : if (_nodal) 271 0 : mooseError("gradients are not defined at nodes"); 272 : 273 0 : return _variable->gradSlnOlder(); 274 : } 275 : 276 : template <typename T> 277 : const typename OutputTools<T>::VariableSecond & 278 96 : MooseVariableInterface<T>::second() 279 : { 280 96 : if (_nodal) 281 0 : mooseError("second derivatives are not defined at nodes"); 282 : 283 96 : return _variable->secondSln(); 284 : } 285 : 286 : template <typename T> 287 : const typename OutputTools<T>::VariableSecond & 288 0 : MooseVariableInterface<T>::secondOld() 289 : { 290 0 : if (_nodal) 291 0 : mooseError("second derivatives are not defined at nodes"); 292 : 293 0 : return _variable->secondSlnOld(); 294 : } 295 : 296 : template <typename T> 297 : const typename OutputTools<T>::VariableSecond & 298 0 : MooseVariableInterface<T>::secondOlder() 299 : { 300 0 : if (_nodal) 301 0 : mooseError("second derivatives are not defined at nodes"); 302 : 303 0 : return _variable->secondSlnOlder(); 304 : } 305 : 306 : template <typename T> 307 : const typename OutputTools<T>::VariableTestSecond & 308 57 : MooseVariableInterface<T>::secondTest() 309 : { 310 57 : if (_nodal) 311 0 : mooseError("second derivatives are not defined at nodes"); 312 : 313 57 : return _variable->secondPhi(); 314 : } 315 : 316 : template <typename T> 317 : const typename OutputTools<T>::VariableTestSecond & 318 0 : MooseVariableInterface<T>::secondTestFace() 319 : { 320 0 : if (_nodal) 321 0 : mooseError("second derivatives are not defined at nodes"); 322 : 323 0 : return _variable->secondPhiFace(); 324 : } 325 : 326 : template <typename T> 327 : const typename OutputTools<T>::VariablePhiSecond & 328 57 : MooseVariableInterface<T>::secondPhi() 329 : { 330 57 : if (_nodal) 331 0 : mooseError("second derivatives are not defined at nodes"); 332 : 333 57 : if (_linear_fv_variable) 334 0 : mooseError("second order shape function derivatives not available for linear FV variables"); 335 : 336 57 : return _mvi_assembly->secondPhi(*_variable); 337 : } 338 : 339 : template <typename T> 340 : const typename OutputTools<T>::VariablePhiSecond & 341 0 : MooseVariableInterface<T>::secondPhiFace() 342 : { 343 0 : if (_nodal) 344 0 : mooseError("second derivatives are not defined at nodes"); 345 : 346 0 : if (_linear_fv_variable) 347 0 : mooseError("second order shape function derivatives not available for linear FV variables"); 348 : 349 0 : return _mvi_assembly->secondPhiFace(*_variable); 350 : } 351 : 352 : template <typename T> 353 : MooseVariableField<T> & 354 34332 : MooseVariableInterface<T>::mooseVariableField() 355 : { 356 34332 : return *_field_variable; 357 : } 358 : 359 : template class MooseVariableInterface<Real>; 360 : template class MooseVariableInterface<RealVectorValue>; 361 : template class MooseVariableInterface<RealEigenVector>;