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 8046757726 : unsigned int number() const { return _var_num; } 61 : 62 : /** 63 : * Get the type of finite element object 64 : */ 65 10245774 : const libMesh::FEType & feType() const { return _fe_type; } 66 : 67 : /** 68 : * Get the system this variable is part of. 69 : */ 70 1662106117 : SystemBase & sys() { return _sys; } 71 : 72 : /** 73 : * Get the system this variable is part of. 74 : */ 75 18759 : const SystemBase & sys() const { return _sys; } 76 : 77 : /** 78 : * Get dual mortar option 79 : */ 80 535651 : 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 33924178 : 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 60564619 : Real scalingFactor() const { return _scaling_factor[0]; } 102 1367642330 : 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 2692884215 : 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 : * Return the continuity of this variable 130 : */ 131 0 : virtual libMesh::FEContinuity getContinuity() const 132 : { 133 0 : mooseError("Base class cannot determine this"); 134 : }; 135 : 136 : /** 137 : * The DofMap associated with the system this variable is in. 138 : */ 139 4176160 : const libMesh::DofMap & dofMap() const { return _dof_map; } 140 : 141 0 : virtual void getDofIndices(const Elem * /*elem*/, 142 : std::vector<dof_id_type> & /*dof_indices*/) const 143 : { 144 0 : mooseError("not implemented"); 145 : }; 146 : 147 : /** 148 : * Get local DoF indices 149 : */ 150 6345333 : virtual const std::vector<dof_id_type> & dofIndices() const { return _dof_indices; } 151 : 152 : /** 153 : * Obtain DoF indices of a component with the indices of the 0th component 154 : */ 155 : std::vector<dof_id_type> componentDofIndices(const std::vector<dof_id_type> & dof_indices, 156 : unsigned int component) const; 157 : 158 : /** 159 : * Get the number of local DoFs 160 : */ 161 0 : virtual unsigned int numberOfDofs() const { return _dof_indices.size(); } 162 : 163 : /** 164 : * Whether or not this variable operates on an eigen kernel 165 : */ 166 2821 : bool eigen() const { return _is_eigen; } 167 : 168 : /** 169 : * Mark this variable as an eigen var or non-eigen var 170 : */ 171 1401 : void eigen(bool eigen) { _is_eigen = eigen; } 172 : 173 : void initialSetup() override; 174 : 175 0 : virtual void clearAllDofIndices() { _dof_indices.clear(); } 176 : 177 : /** 178 : * Set the active vector tags 179 : * @param vtags Additional vector tags that this variable will need to query at dof indices for, 180 : * in addition to our own required solution tags 181 : */ 182 : virtual void setActiveTags(const std::set<TagID> & vtags); 183 : 184 : /** 185 : * @return whether this is an array variable 186 : */ 187 1188745 : virtual bool isArray() const { return !_array_var_component_names.empty(); } 188 : 189 : /** 190 : * @return whether this variable lives on lower dimensional blocks 191 : */ 192 1420 : bool isLowerD() const { return _is_lower_d; } 193 : 194 : /** 195 : * Size data structures related to matrix tagging 196 : */ 197 0 : virtual void sizeMatrixTagData() { mooseError("Derived class must implement this method"); } 198 : 199 : protected: 200 : /** 201 : * Get the solution corresponding to the provided state 202 : */ 203 : const libMesh::NumericVector<libMesh::Number> & getSolution(const Moose::StateArg & state) const; 204 : 205 : /** 206 : * @returns whether we should insert derivatives 207 : */ 208 : bool doDerivatives() const; 209 : 210 : /// System this variable is part of 211 : SystemBase & _sys; 212 : 213 : /// The FEType associated with this variable 214 : libMesh::FEType _fe_type; 215 : 216 : /// variable number (from libMesh) 217 : unsigned int _var_num; 218 : 219 : /// variable number within MOOSE 220 : unsigned int _index; 221 : 222 : /// Whether or not this variable operates on eigen kernels 223 : bool _is_eigen; 224 : 225 : /// Variable type (see MooseTypes.h) 226 : Moose::VarKindType _var_kind; 227 : 228 : /// Problem this variable is part of 229 : SubProblem & _subproblem; 230 : 231 : /// libMesh variable object for this variable 232 : const libMesh::Variable & _variable; 233 : 234 : /// Assembly data 235 : Assembly & _assembly; 236 : 237 : /// DOF map 238 : const libMesh::DofMap & _dof_map; 239 : 240 : /// DOF indices 241 : std::vector<dof_id_type> _dof_indices; 242 : 243 : /// mesh the variable is active in 244 : MooseMesh & _mesh; 245 : 246 : /// Thread ID 247 : THREAD_ID _tid; 248 : 249 : /// Number of variables in the array 250 : const unsigned int _count; 251 : 252 : /// scaling factor for this variable 253 : std::vector<Real> _scaling_factor; 254 : 255 : /// If dual mortar approach is used 256 : bool _use_dual; 257 : 258 : /// Whether this variable lives on lower dimensional blocks 259 : bool _is_lower_d; 260 : 261 : /// Array variable names when the variable is an array variable 262 : std::vector<std::string> _array_var_component_names; 263 : }; 264 : 265 : inline void 266 0 : MooseVariableBase::setActiveTags(const std::set<TagID> &) 267 : { 268 0 : mooseError("setActiveTags must be overridden in derived classes."); 269 : } 270 : 271 : #define usingMooseVariableBaseMembers \ 272 : using MooseVariableBase::_sys; \ 273 : using MooseVariableBase::_fe_type; \ 274 : using MooseVariableBase::_var_num; \ 275 : using MooseVariableBase::_index; \ 276 : using MooseVariableBase::_var_kind; \ 277 : using MooseVariableBase::_subproblem; \ 278 : using MooseVariableBase::_variable; \ 279 : using MooseVariableBase::_assembly; \ 280 : using MooseVariableBase::_dof_map; \ 281 : using MooseVariableBase::_dof_indices; \ 282 : using MooseVariableBase::_mesh; \ 283 : using MooseVariableBase::_tid; \ 284 : using MooseVariableBase::_count; \ 285 : using MooseVariableBase::_scaling_factor