www.mooseframework.org
VariableWarehouse.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
15 #include <vector>
16 #include <map>
17 #include <set>
18 
19 namespace libMesh
20 {
21 template <typename>
22 class VectorValue;
24 }
25 
26 class MooseVariableBase;
28 template <typename>
29 class MooseVariableFE;
30 template <typename>
35 
36 template <typename>
39 
40 template <typename>
43 
45 
50 {
51 public:
53 
59  void add(const std::string & var_name, std::shared_ptr<MooseVariableBase> var);
60 
66  void addBoundaryVar(BoundaryID bnd, const MooseVariableFieldBase * var);
67 
73  void addBoundaryVar(const std::set<BoundaryID> & boundary_ids,
74  const MooseVariableFieldBase * var);
75 
81  void addBoundaryVars(
82  const std::set<BoundaryID> & boundary_ids,
83  const std::unordered_map<std::string, std::vector<MooseVariableFieldBase *>> & vars);
84 
90  MooseVariableBase * getVariable(const std::string & var_name) const;
91 
97  MooseVariableBase * getVariable(unsigned int var_number) const;
98 
108  template <typename T>
109  MooseVariableFE<T> * getFieldVariable(const std::string & var_name);
110 
120  template <typename T>
121  MooseVariableFE<T> * getFieldVariable(unsigned int var_number);
122 
127  template <typename T>
128  MooseVariableField<T> * getActualFieldVariable(const std::string & var_name);
129 
133  template <typename T>
134  MooseVariableFV<T> * getFVVariable(const std::string & var_name);
135 
140  template <typename T>
141  MooseVariableField<T> * getActualFieldVariable(unsigned int var_number);
142 
147  const std::vector<VariableName> & names() const;
148 
153  const std::vector<MooseVariableFieldBase *> & fieldVariables() const;
154 
160  const std::set<const MooseVariableFieldBase *> & boundaryVars(BoundaryID bnd) const;
161 
166  const std::vector<MooseVariableScalar *> & scalars() const;
167 
171  void initialSetup();
172 
176  void timestepSetup();
177 
181  void customSetup(const ExecFlagType & exec_type);
182 
186  void subdomainSetup();
187 
191  void residualSetup();
192 
196  void jacobianSetup();
197 
201  void clearAllDofIndices();
202 
206  void setActiveVariableCoupleableVectorTags(const std::set<TagID> & vtags);
207 
211  void setActiveScalarVariableCoupleableVectorTags(const std::set<TagID> & vtags);
212 
216  const std::map<unsigned int, std::shared_ptr<MooseVariableBase>> & numberToVariableMap() const;
217 
218 protected:
220  std::vector<VariableName> _names;
221 
223  std::vector<MooseVariableFieldBase *> _vars;
224 
227 
230 
233 
236 
239 
242 
245 
248 
251 
254 
256  std::map<std::string, MooseVariableBase *> _var_name;
257 
259  std::map<BoundaryID, std::set<const MooseVariableFieldBase *>> _boundary_vars;
260 
262  std::vector<MooseVariableScalar *> _scalar_vars;
263 
265  std::map<unsigned int, std::shared_ptr<MooseVariableBase>> _all_objects;
266 };
267 
268 template <typename T>
270 VariableWarehouse::getFVVariable(const std::string & var_name)
271 {
272  auto it = _fv_vars_by_name.find(var_name);
273  if (it == _fv_vars_by_name.end())
274  mooseError("Requested variable ",
275  var_name,
276  " doesn't exist as a finite volume variable in the warehouse.");
277 
278  return it->second;
279 }
280 
281 inline const std::map<unsigned int, std::shared_ptr<MooseVariableBase>> &
283 {
284  return _all_objects;
285 }
286 
287 template <>
289 VariableWarehouse::getFieldVariable<RealVectorValue>(const std::string & var_name);
290 
291 template <>
293 VariableWarehouse::getFieldVariable<RealVectorValue>(unsigned int var_number);
294 
295 template <>
297 VariableWarehouse::getFieldVariable<RealEigenVector>(const std::string & var_name);
298 
299 template <>
301 VariableWarehouse::getFieldVariable<RealEigenVector>(unsigned int var_number);
302 
303 template <>
305 VariableWarehouse::getActualFieldVariable<RealVectorValue>(const std::string & var_name);
306 
307 template <>
309 VariableWarehouse::getActualFieldVariable<RealVectorValue>(unsigned int var_number);
310 
311 template <>
313 VariableWarehouse::getActualFieldVariable<RealEigenVector>(const std::string & var_name);
314 
315 template <>
317 VariableWarehouse::getActualFieldVariable<RealEigenVector>(unsigned int var_number);
const std::vector< VariableName > & names() const
Get the list of all variable names.
MooseVariableFE< RealEigenVector > ArrayMooseVariable
void addBoundaryVar(BoundaryID bnd, const MooseVariableFieldBase *var)
Add a boundary variable.
MooseVariableBase * getVariable(const std::string &var_name) const
Get a variable from the warehouse.
void residualSetup()
Call residualSetup for all variables.
void setActiveScalarVariableCoupleableVectorTags(const std::set< TagID > &vtags)
Set the active vector tags for the variables.
MooseVariableFV< Real > MooseVariableFVReal
void addBoundaryVars(const std::set< BoundaryID > &boundary_ids, const std::unordered_map< std::string, std::vector< MooseVariableFieldBase *>> &vars)
Add a map of variables to a set of boundaries.
void add(const std::string &var_name, std::shared_ptr< MooseVariableBase > var)
Add a variable.
MooseVariableFV< T > * getFVVariable(const std::string &var_name)
Get a finite volume variable.
std::vector< MooseVariableScalar * > _scalar_vars
list of all scalar, non-finite element variables
void jacobianSetup()
Call jacobianSetup for all variables.
HashMap is an abstraction for dictionary data type, we make it thread-safe by locking inserts...
Definition: HashMap.h:18
Class for stuff related to variables.
Definition: Adaptivity.h:31
void setActiveVariableCoupleableVectorTags(const std::set< TagID > &vtags)
Set the active vector tags for the variables.
Class for stuff related to variables.
Definition: Coupleable.h:38
VectorValue< Real > RealVectorValue
Definition: SubProblem.h:33
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:299
void initialSetup()
Call initialSetup for all variables.
void timestepSetup()
Call timestepSetup for all variables.
HashMap< unsigned, ArrayMooseVariable * > _array_vars_by_number
map of vector finite element variables with unsigned keys
This class provides an interface for common operations on field variables of both FE and FV types wit...
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
const std::vector< MooseVariableScalar * > & scalars() const
Get the list of scalar variables.
std::map< std::string, MooseVariableBase * > _var_name
Name to variable mapping.
HashMap< std::string, VectorMooseVariable * > _vector_vars_by_name
map of vector finite element variables with name keys
void clearAllDofIndices()
Clear all dof indices from each variable.
const std::map< unsigned int, std::shared_ptr< MooseVariableBase > > & numberToVariableMap() const
Map from variable number to variable pointer.
HashMap< std::string, MooseLinearVariableFVReal * > _linear_fv_vars_by_name
map of non-vector linear finite volume variables with name keys
Holds variables and provides some services.
boundary_id_type BoundaryID
MooseVariableFE< Real > MooseVariable
MooseVariableFE< RealVectorValue > VectorMooseVariable
std::map< unsigned int, std::shared_ptr< MooseVariableBase > > _all_objects
All instances of objects.
MooseVariableField< T > * getActualFieldVariable(const std::string &var_name)
This should be called getFieldVariable, but that name is already taken by a legacy function...
HashMap< unsigned, MooseVariableFVReal * > _fv_vars_by_number
map of non-vector finite element variables with unsigned keys
std::vector< MooseVariableFieldBase * > _vars
list of finite element variables
HashMap< std::string, ArrayMooseVariable * > _array_vars_by_name
map of vector finite element variables with name keys
std::map< BoundaryID, std::set< const MooseVariableFieldBase * > > _boundary_vars
Map to variables that need to be evaluated on a boundary.
HashMap< unsigned, MooseVariable * > _regular_vars_by_number
map of non-vector finite element variables with unsigned keys
std::vector< VariableName > _names
list of variable names
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:18
Class for scalar variables (they are different).
const std::set< const MooseVariableFieldBase * > & boundaryVars(BoundaryID bnd) const
Get the list of variables that needs to be reinitialized on a given boundary.
MooseLinearVariableFV< Real > MooseLinearVariableFVReal
void subdomainSetup()
Call subdomainSetup for all variables.
HashMap< std::string, MooseVariable * > _regular_vars_by_name
map of non-vector finite element variables with name keys
MooseVariableFE< T > * getFieldVariable(const std::string &var_name)
Get a finite element variable from the warehouse of either Real or RealVectorValue type...
HashMap< unsigned, MooseLinearVariableFVReal * > _linear_fv_vars_by_number
map of non-vector finite element variables with unsigned keys
This class provides variable solution values for other classes/objects to bind to when looping over f...
HashMap< unsigned, VectorMooseVariable * > _vector_vars_by_number
map of vector finite element variables with unsigned keys
This class provides variable solution interface for linear finite volume problems.
Definition: FVUtils.h:24
const std::vector< MooseVariableFieldBase * > & fieldVariables() const
Get the list of variables.
HashMap< std::string, MooseVariableFVReal * > _fv_vars_by_name
map of non-vector finite element variables with name keys
void customSetup(const ExecFlagType &exec_type)
Call setup on a particular execute flag for all variables.