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 "BlockRestrictable.h" 14 : #include "OutputInterface.h" 15 : #include "SetupInterface.h" 16 : #include "MooseTypes.h" 17 : #include "MooseArray.h" 18 : #include "MooseError.h" 19 : #include "MooseFunctorArguments.h" 20 : 21 : #include "libmesh/fe_type.h" 22 : #include "libmesh/enum_fe_family.h" 23 : 24 : // libMesh forward declarations 25 : namespace libMesh 26 : { 27 : class DofMap; 28 : class Variable; 29 : } 30 : 31 : class Assembly; 32 : class SubProblem; 33 : class SystemBase; 34 : class MooseMesh; 35 : 36 : /** 37 : * Base variable class. Sadly there are a lot of methods in here that should be pure virtual but 38 : * can't be because AddVariableAction/MooseObjectAction will retrieve the validParams of 39 : * MooseVariableBase which checks to ensure that MooseVariableBase is a registered object, and 40 : * registration requires an instantiation. So we add runtime errors instead of compile-time 41 : * errors for these would-be pure virtuals 42 : */ 43 : class MooseVariableBase : public MooseObject, 44 : public BlockRestrictable, 45 : public OutputInterface, 46 : public SetupInterface 47 : { 48 : public: 49 : static InputParameters validParams(); 50 : 51 : MooseVariableBase(const InputParameters & parameters); 52 : 53 : /// Returns the variable name of a component of an array variable 54 : const std::string & arrayVariableComponent(const unsigned int i) const; 55 : 56 : /** 57 : * Get variable number coming from libMesh 58 : * @return the libmesh variable number 59 : */ 60 7211672976 : unsigned int number() const { return _var_num; } 61 : 62 : /** 63 : * Get the type of finite element object 64 : */ 65 9625588 : const libMesh::FEType & feType() const { return _fe_type; } 66 : 67 : /** 68 : * Get the system this variable is part of. 69 : */ 70 1421590449 : SystemBase & sys() { return _sys; } 71 : 72 : /** 73 : * Get the system this variable is part of. 74 : */ 75 10276531 : const SystemBase & sys() const { return _sys; } 76 : 77 : /** 78 : * Get dual mortar option 79 : */ 80 527839 : bool useDual() const { return _use_dual; } 81 : 82 : /** 83 : * Get all global dofindices for the variable 84 : */ 85 : const std::vector<dof_id_type> & allDofIndices() const; 86 : unsigned int totalVarDofs() { return allDofIndices().size(); } 87 : 88 : /** 89 : * Kind of the variable (Nonlinear, Auxiliary, ...) 90 : */ 91 29982987 : Moose::VarKindType kind() const { return _var_kind; } 92 : 93 : /** 94 : * Set the scaling factor for this variable 95 : */ 96 : void scalingFactor(const std::vector<Real> & factor); 97 : 98 : /** 99 : * Get the scaling factor for this variable 100 : */ 101 36775415 : Real scalingFactor() const { return _scaling_factor[0]; } 102 1104196380 : const std::vector<Real> & arrayScalingFactor() const { return _scaling_factor; } 103 : 104 : /** 105 : * Get the order of this variable 106 : * Note: Order enum can be implicitly converted to unsigned int. 107 : */ 108 : libMesh::Order order() const; 109 : 110 : /** 111 : * Get the number of components 112 : * Note: For standard and vector variables, the number is one. 113 : */ 114 592523500 : unsigned int count() const { return _count; } 115 : 116 : /** 117 : * Is this variable nodal 118 : * @return true if it nodal, otherwise false 119 : */ 120 0 : virtual bool isNodal() const { mooseError("Base class cannot determine this"); } 121 : 122 : /** 123 : * Does this variable have DoFs on nodes 124 : * @return true if it does, false if not. 125 : */ 126 0 : virtual bool hasDoFsOnNodes() const { mooseError("Base class cannot determine this"); }; 127 : 128 : /** 129 : * Whether this variable supports QP-indexed loops. Returns true for FE variables and nonlinear 130 : * FV variables. Returns false for linear FV variables by default and for scalar variables. 131 : */ 132 : virtual bool supportsQpBasedLoops() const; 133 : 134 : /** 135 : * Whether this variable supports geometric-info-based loops, such as ElemInfo/FaceInfo loops. 136 : * Static, per-class property - never toggled by requireQpComputations(). 137 : */ 138 : virtual bool supportsGeometricInfoBasedLoops() const; 139 : 140 : /** 141 : * Return the continuity of this variable 142 : */ 143 0 : virtual libMesh::FEContinuity getContinuity() const 144 : { 145 0 : mooseError("Base class cannot determine this"); 146 : }; 147 : 148 : /** 149 : * The DofMap associated with the system this variable is in. 150 : */ 151 3897446 : const libMesh::DofMap & dofMap() const { return _dof_map; } 152 : 153 0 : virtual void getDofIndices(const Elem * /*elem*/, 154 : std::vector<dof_id_type> & /*dof_indices*/) const 155 : { 156 0 : mooseError("not implemented"); 157 : }; 158 : 159 : /** 160 : * Get local DoF indices 161 : */ 162 7104858 : virtual const std::vector<dof_id_type> & dofIndices() const { return _dof_indices; } 163 : 164 : /** 165 : * Obtain DoF indices of a component with the indices of the 0th component 166 : */ 167 : std::vector<dof_id_type> componentDofIndices(const std::vector<dof_id_type> & dof_indices, 168 : unsigned int component) const; 169 : 170 : /** 171 : * Get the number of local DoFs 172 : */ 173 0 : virtual unsigned int numberOfDofs() const { return _dof_indices.size(); } 174 : 175 : /** 176 : * Whether or not this variable operates on an eigen kernel 177 : */ 178 2652 : bool eigen() const { return _is_eigen; } 179 : 180 : /** 181 : * Mark this variable as an eigen var or non-eigen var 182 : */ 183 1344 : void eigen(bool eigen) { _is_eigen = eigen; } 184 : 185 : void initialSetup() override; 186 : 187 0 : virtual void clearAllDofIndices() { _dof_indices.clear(); } 188 : 189 : /** 190 : * Set the active vector tags 191 : * @param vtags Additional vector tags that this variable will need to query at dof indices for, 192 : * in addition to our own required solution tags 193 : */ 194 : virtual void setActiveTags(const std::set<TagID> & vtags); 195 : 196 : /** 197 : * @return whether this is an array variable 198 : */ 199 1134418 : virtual bool isArray() const { return !_array_var_component_names.empty(); } 200 : 201 : /** 202 : * Size data structures related to matrix tagging 203 : */ 204 0 : virtual void sizeMatrixTagData() { mooseError("Derived class must implement this method"); } 205 : 206 : protected: 207 : /** 208 : * Get the solution corresponding to the provided state 209 : */ 210 : const libMesh::NumericVector<libMesh::Number> & getSolution(const Moose::StateArg & state) const; 211 : 212 : /** 213 : * @returns whether we should insert derivatives 214 : */ 215 : bool doDerivatives() const; 216 : 217 : /// System this variable is part of 218 : SystemBase & _sys; 219 : 220 : /// The FEType associated with this variable 221 : libMesh::FEType _fe_type; 222 : 223 : /// variable number (from libMesh) 224 : unsigned int _var_num; 225 : 226 : /// variable number within MOOSE 227 : unsigned int _index; 228 : 229 : /// Whether or not this variable operates on eigen kernels 230 : bool _is_eigen; 231 : 232 : /// Variable type (see MooseTypes.h) 233 : Moose::VarKindType _var_kind; 234 : 235 : /// Problem this variable is part of 236 : SubProblem & _subproblem; 237 : 238 : /// libMesh variable object for this variable 239 : const libMesh::Variable & _variable; 240 : 241 : /// Assembly data 242 : Assembly & _assembly; 243 : 244 : /// DOF map 245 : const libMesh::DofMap & _dof_map; 246 : 247 : /// DOF indices 248 : std::vector<dof_id_type> _dof_indices; 249 : 250 : /// mesh the variable is active in 251 : MooseMesh & _mesh; 252 : 253 : /// Thread ID 254 : THREAD_ID _tid; 255 : 256 : /// Number of variables in the array 257 : const unsigned int _count; 258 : 259 : /// scaling factor for this variable 260 : std::vector<Real> _scaling_factor; 261 : 262 : /// If dual mortar approach is used 263 : bool _use_dual; 264 : 265 : /// Whether this variable lives on lower dimensional blocks 266 : bool _is_lower_d; 267 : 268 : /// Array variable names when the variable is an array variable 269 : std::vector<std::string> _array_var_component_names; 270 : }; 271 : 272 : inline void 273 0 : MooseVariableBase::setActiveTags(const std::set<TagID> &) 274 : { 275 0 : mooseError("setActiveTags must be overridden in derived classes."); 276 : } 277 : 278 : #define usingMooseVariableBaseMembers \ 279 : using MooseVariableBase::_sys; \ 280 : using MooseVariableBase::_fe_type; \ 281 : using MooseVariableBase::_var_num; \ 282 : using MooseVariableBase::_index; \ 283 : using MooseVariableBase::_var_kind; \ 284 : using MooseVariableBase::_subproblem; \ 285 : using MooseVariableBase::_variable; \ 286 : using MooseVariableBase::_assembly; \ 287 : using MooseVariableBase::_dof_map; \ 288 : using MooseVariableBase::_dof_indices; \ 289 : using MooseVariableBase::_mesh; \ 290 : using MooseVariableBase::_tid; \ 291 : using MooseVariableBase::_count; \ 292 : using MooseVariableBase::_scaling_factor