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 "MooseTypes.h" 13 : #include "HashMap.h" 14 : #include "MooseError.h" 15 : 16 : #include <vector> 17 : #include <map> 18 : #include <set> 19 : 20 : namespace libMesh 21 : { 22 : template <typename> 23 : class VectorValue; 24 : typedef VectorValue<Real> RealVectorValue; 25 : } 26 : 27 : class MooseVariableBase; 28 : class MooseVariableFieldBase; 29 : template <typename> 30 : class MooseVariableFE; 31 : template <typename> 32 : class MooseVariableField; 33 : typedef MooseVariableFE<Real> MooseVariable; 34 : typedef MooseVariableFE<RealVectorValue> VectorMooseVariable; 35 : typedef MooseVariableFE<RealEigenVector> ArrayMooseVariable; 36 : 37 : template <typename> 38 : class MooseVariableFV; 39 : typedef MooseVariableFV<Real> MooseVariableFVReal; 40 : 41 : template <typename> 42 : class MooseLinearVariableFV; 43 : typedef MooseLinearVariableFV<Real> MooseLinearVariableFVReal; 44 : 45 : class MooseVariableScalar; 46 : 47 : /** 48 : * Holds variables and provides some services 49 : */ 50 : class VariableWarehouse 51 : { 52 : public: 53 : VariableWarehouse(); 54 : 55 : /** 56 : * Add a variable 57 : * @param var_name The name of the variable 58 : * @param var Variable 59 : */ 60 : void add(const std::string & var_name, std::shared_ptr<MooseVariableBase> var); 61 : 62 : /** 63 : * Add a boundary variable 64 : * @param bnd The boundary id where this variable is defined 65 : * @param var The variable 66 : */ 67 : void addBoundaryVar(BoundaryID bnd, const MooseVariableFieldBase * var); 68 : 69 : /** 70 : * Add a variable to a set of boundaries 71 : * @param boundary_ids The boundary ids where this variable is defined 72 : * @param var The variable 73 : */ 74 : void addBoundaryVar(const std::set<BoundaryID> & boundary_ids, 75 : const MooseVariableFieldBase * var); 76 : 77 : /** 78 : * Add a map of variables to a set of boundaries 79 : * @param boundary_ids The boundary ids where this variable is defined 80 : * @param vars A map of variables 81 : */ 82 : void addBoundaryVars( 83 : const std::set<BoundaryID> & boundary_ids, 84 : const std::unordered_map<std::string, std::vector<MooseVariableFieldBase *>> & vars); 85 : 86 : /** 87 : * Get a variable from the warehouse 88 : * @param var_name The name of the variable to retrieve 89 : * @return The retrieved variable 90 : */ 91 : MooseVariableBase * getVariable(const std::string & var_name) const; 92 : 93 : /** 94 : * Get a variable from the warehouse 95 : * @param var_number The number of the variable to retrieve 96 : * @return The retrieved variable 97 : */ 98 : MooseVariableBase * getVariable(unsigned int var_number) const; 99 : 100 : /** 101 : * Get a finite element variable from the warehouse 102 : * of either Real or RealVectorValue type 103 : * @param var_name The name of the variable to retrieve 104 : * @return The retrieved variable 105 : * 106 : * Note this should actually be named getFieldFEVariable, but that would 107 : * require fixing a lot of code in a lot of apps 108 : */ 109 : template <typename T> 110 : MooseVariableFE<T> * getFieldVariable(const std::string & var_name); 111 : 112 : /** 113 : * Get a finite element variable from the warehouse 114 : * of either Real or RealVectorValue type 115 : * @param var_number The number of the variable to retrieve 116 : * @return The retrieved variable 117 : * 118 : * Note this should actually be named getFieldFEVariable, but that would 119 : * require fixing a lot of code in a lot of apps 120 : */ 121 : template <typename T> 122 : MooseVariableFE<T> * getFieldVariable(unsigned int var_number); 123 : 124 : /** 125 : * This should be called getFieldVariable, but that name is already taken 126 : * by a legacy function. 127 : */ 128 : template <typename T> 129 : MooseVariableField<T> * getActualFieldVariable(const std::string & var_name); 130 : 131 : /** 132 : * Get a finite volume variable 133 : */ 134 : template <typename T> 135 : MooseVariableFV<T> * getFVVariable(const std::string & var_name); 136 : 137 : /** 138 : * This should be called getFieldVariable, but that name is already taken 139 : * by a legacy function. 140 : */ 141 : template <typename T> 142 : MooseVariableField<T> * getActualFieldVariable(unsigned int var_number); 143 : 144 : /** 145 : * Get the list of all variable names 146 : * @return The list of variable names 147 : */ 148 : const std::vector<VariableName> & names() const; 149 : 150 : /** 151 : * Get the list of variables 152 : * @return The list of variables 153 : */ 154 : const std::vector<MooseVariableFieldBase *> & fieldVariables() const; 155 : 156 : /** 157 : * Get the list of variables that needs to be reinitialized on a given boundary 158 : * @param bnd The boundary ID 159 : * @return The list of variables 160 : */ 161 : const std::set<const MooseVariableFieldBase *> & boundaryVars(BoundaryID bnd) const; 162 : 163 : /** 164 : * Get the list of scalar variables 165 : * @return The list of scalar variables 166 : */ 167 : const std::vector<MooseVariableScalar *> & scalars() const; 168 : 169 : /** 170 : * Call initialSetup for all variables 171 : */ 172 : void initialSetup(); 173 : 174 : /** 175 : * Call timestepSetup for all variables 176 : */ 177 : void timestepSetup(); 178 : 179 : /** 180 : * Call setup on a particular execute flag for all variables 181 : */ 182 : void customSetup(const ExecFlagType & exec_type); 183 : 184 : /** 185 : * Call subdomainSetup for all variables 186 : */ 187 : void subdomainSetup(); 188 : 189 : /** 190 : * Call residualSetup for all variables 191 : */ 192 : void residualSetup(); 193 : 194 : /** 195 : * Call jacobianSetup for all variables 196 : */ 197 : void jacobianSetup(); 198 : 199 : /** 200 : * Clear all dof indices from each variable 201 : */ 202 : void clearAllDofIndices(); 203 : 204 : /** 205 : * Set the active vector tags for the variables 206 : */ 207 : void setActiveVariableCoupleableVectorTags(const std::set<TagID> & vtags); 208 : 209 : /** 210 : * Set the active vector tags for the variables 211 : */ 212 : void setActiveScalarVariableCoupleableVectorTags(const std::set<TagID> & vtags); 213 : 214 : /** 215 : * Map from variable number to variable pointer. Includes both field and scalar variables 216 : */ 217 : const std::map<unsigned int, std::shared_ptr<MooseVariableBase>> & numberToVariableMap() const; 218 : 219 : protected: 220 : /// list of variable names 221 : std::vector<VariableName> _names; 222 : 223 : /// list of finite element variables 224 : std::vector<MooseVariableFieldBase *> _vars; 225 : 226 : /// map of non-vector finite element variables with unsigned keys 227 : HashMap<unsigned, MooseVariable *> _regular_vars_by_number; 228 : 229 : /// map of non-vector finite element variables with name keys 230 : HashMap<std::string, MooseVariableFVReal *> _fv_vars_by_name; 231 : 232 : /// map of non-vector linear finite volume variables with name keys 233 : HashMap<std::string, MooseLinearVariableFVReal *> _linear_fv_vars_by_name; 234 : 235 : /// map of non-vector finite element variables with name keys 236 : HashMap<std::string, MooseVariable *> _regular_vars_by_name; 237 : 238 : /// map of non-vector finite element variables with unsigned keys 239 : HashMap<unsigned, MooseVariableFVReal *> _fv_vars_by_number; 240 : 241 : /// map of non-vector finite element variables with unsigned keys 242 : HashMap<unsigned, MooseLinearVariableFVReal *> _linear_fv_vars_by_number; 243 : 244 : /// map of vector finite element variables with name keys 245 : HashMap<std::string, VectorMooseVariable *> _vector_vars_by_name; 246 : 247 : /// map of vector finite element variables with unsigned keys 248 : HashMap<unsigned, VectorMooseVariable *> _vector_vars_by_number; 249 : 250 : /// map of vector finite element variables with name keys 251 : HashMap<std::string, ArrayMooseVariable *> _array_vars_by_name; 252 : 253 : /// map of vector finite element variables with unsigned keys 254 : HashMap<unsigned, ArrayMooseVariable *> _array_vars_by_number; 255 : 256 : /// Name to variable mapping 257 : std::map<std::string, MooseVariableBase *> _var_name; 258 : 259 : /// Map to variables that need to be evaluated on a boundary 260 : std::map<BoundaryID, std::set<const MooseVariableFieldBase *>> _boundary_vars; 261 : 262 : /// list of all scalar, non-finite element variables 263 : std::vector<MooseVariableScalar *> _scalar_vars; 264 : 265 : /// All instances of objects 266 : std::map<unsigned int, std::shared_ptr<MooseVariableBase>> _all_objects; 267 : }; 268 : 269 : template <typename T> 270 : MooseVariableFV<T> * 271 662 : VariableWarehouse::getFVVariable(const std::string & var_name) 272 : { 273 662 : auto it = _fv_vars_by_name.find(var_name); 274 662 : if (it == _fv_vars_by_name.end()) 275 0 : mooseError("Requested variable ", 276 : var_name, 277 : " doesn't exist as a finite volume variable in the warehouse."); 278 : 279 662 : return it->second; 280 : } 281 : 282 : inline const std::map<unsigned int, std::shared_ptr<MooseVariableBase>> & 283 431 : VariableWarehouse::numberToVariableMap() const 284 : { 285 431 : return _all_objects; 286 : } 287 : 288 : template <> 289 : MooseVariableFE<RealVectorValue> * 290 : VariableWarehouse::getFieldVariable<RealVectorValue>(const std::string & var_name); 291 : 292 : template <> 293 : MooseVariableFE<RealVectorValue> * 294 : VariableWarehouse::getFieldVariable<RealVectorValue>(unsigned int var_number); 295 : 296 : template <> 297 : MooseVariableFE<RealEigenVector> * 298 : VariableWarehouse::getFieldVariable<RealEigenVector>(const std::string & var_name); 299 : 300 : template <> 301 : MooseVariableFE<RealEigenVector> * 302 : VariableWarehouse::getFieldVariable<RealEigenVector>(unsigned int var_number); 303 : 304 : template <> 305 : MooseVariableField<RealVectorValue> * 306 : VariableWarehouse::getActualFieldVariable<RealVectorValue>(const std::string & var_name); 307 : 308 : template <> 309 : MooseVariableField<RealVectorValue> * 310 : VariableWarehouse::getActualFieldVariable<RealVectorValue>(unsigned int var_number); 311 : 312 : template <> 313 : MooseVariableField<RealEigenVector> * 314 : VariableWarehouse::getActualFieldVariable<RealEigenVector>(const std::string & var_name); 315 : 316 : template <> 317 : MooseVariableField<RealEigenVector> * 318 : VariableWarehouse::getActualFieldVariable<RealEigenVector>(unsigned int var_number);