https://mooseframework.inl.gov
Loading...
Searching...
No Matches
VariableWarehouse.h
Go to the documentation of this file.
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
20namespace libMesh
21{
22template <typename>
23class VectorValue;
24typedef VectorValue<Real> RealVectorValue;
25}
26
29template <typename>
30class MooseVariableFE;
31template <typename>
36
37template <typename>
38class MooseVariableFV;
40
41template <typename>
44
46
51{
52public:
54
60 void add(const std::string & var_name, std::shared_ptr<MooseVariableBase> var);
61
68
74 void addBoundaryVar(const std::set<BoundaryID> & boundary_ids,
75 const MooseVariableFieldBase * var);
76
82 void addBoundaryVars(
83 const std::set<BoundaryID> & boundary_ids,
84 const std::unordered_map<std::string, std::vector<MooseVariableFieldBase *>> & vars);
85
91 MooseVariableBase * getVariable(const std::string & var_name) const;
92
98 MooseVariableBase * getVariable(unsigned int var_number) const;
99
109 template <typename T>
110 MooseVariableFE<T> * getFieldVariable(const std::string & var_name);
111
121 template <typename T>
122 MooseVariableFE<T> * getFieldVariable(unsigned int var_number);
123
128 template <typename T>
129 MooseVariableField<T> * getActualFieldVariable(const std::string & var_name);
130
134 template <typename T>
135 MooseVariableFV<T> * getFVVariable(const std::string & var_name);
136
141 template <typename T>
142 MooseVariableField<T> * getActualFieldVariable(unsigned int var_number);
143
148 const std::vector<VariableName> & names() const;
149
154 const std::vector<MooseVariableFieldBase *> & fieldVariables() const;
155
161 const std::set<const MooseVariableFieldBase *> & boundaryVars(BoundaryID bnd) const;
162
167 const std::vector<MooseVariableScalar *> & scalars() const;
168
172 void initialSetup();
173
177 void timestepSetup();
178
182 void customSetup(const ExecFlagType & exec_type);
183
187 void subdomainSetup();
188
192 void residualSetup();
193
197 void jacobianSetup();
198
202 void clearAllDofIndices();
203
207 void setActiveVariableCoupleableVectorTags(const std::set<TagID> & vtags);
208
212 void setActiveScalarVariableCoupleableVectorTags(const std::set<TagID> & vtags);
213
217 const std::map<unsigned int, std::shared_ptr<MooseVariableBase>> & numberToVariableMap() const;
218
219protected:
221 std::vector<VariableName> _names;
222
224 std::vector<MooseVariableFieldBase *> _vars;
225
228
231
234
237
240
243
246
249
252
255
257 std::map<std::string, MooseVariableBase *> _var_name;
258
260 std::map<BoundaryID, std::set<const MooseVariableFieldBase *>> _boundary_vars;
261
263 std::vector<MooseVariableScalar *> _scalar_vars;
264
266 std::map<unsigned int, std::shared_ptr<MooseVariableBase>> _all_objects;
267};
268
269template <typename T>
271VariableWarehouse::getFVVariable(const std::string & var_name)
272{
273 auto it = _fv_vars_by_name.find(var_name);
274 if (it == _fv_vars_by_name.end())
275 mooseError("Requested variable ",
276 var_name,
277 " doesn't exist as a finite volume variable in the warehouse.");
278
279 return it->second;
280}
281
282inline const std::map<unsigned int, std::shared_ptr<MooseVariableBase>> &
284{
285 return _all_objects;
286}
287
288template <>
290VariableWarehouse::getFieldVariable<RealVectorValue>(const std::string & var_name);
291
292template <>
294VariableWarehouse::getFieldVariable<RealVectorValue>(unsigned int var_number);
295
296template <>
298VariableWarehouse::getFieldVariable<RealEigenVector>(const std::string & var_name);
299
300template <>
302VariableWarehouse::getFieldVariable<RealEigenVector>(unsigned int var_number);
303
304template <>
306VariableWarehouse::getActualFieldVariable<RealVectorValue>(const std::string & var_name);
307
308template <>
310VariableWarehouse::getActualFieldVariable<RealVectorValue>(unsigned int var_number);
311
312template <>
314VariableWarehouse::getActualFieldVariable<RealEigenVector>(const std::string & var_name);
315
316template <>
318VariableWarehouse::getActualFieldVariable<RealEigenVector>(unsigned int var_number);
boundary_id_type BoundaryID
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
char ** vars
MooseVariableFE< Real > MooseVariable
MooseVariableFE< RealEigenVector > ArrayMooseVariable
MooseVariableFV< Real > MooseVariableFVReal
MooseLinearVariableFV< Real > MooseLinearVariableFVReal
MooseVariableFE< RealVectorValue > VectorMooseVariable
HashMap is an abstraction for dictionary data type, we make it thread-safe by locking inserts.
Definition HashMap.h:19
Class for containing MooseEnum item information.
This class provides variable solution interface for linear finite volume problems.
Base variable class.
Class for stuff related to variables.
This class provides variable solution values for other classes/objects to bind to when looping over f...
This class provides an interface for common operations on field variables of both FE and FV types wit...
Class for stuff related to variables.
Class for scalar variables (they are different).
Holds variables and provides some services.
HashMap< std::string, VectorMooseVariable * > _vector_vars_by_name
map of vector finite element variables with name keys
MooseVariableBase * getVariable(const std::string &var_name) const
Get a variable from the warehouse.
const std::set< const MooseVariableFieldBase * > & boundaryVars(BoundaryID bnd) const
Get the list of variables that needs to be reinitialized on a given boundary.
void jacobianSetup()
Call jacobianSetup for all variables.
MooseVariableFV< T > * getFVVariable(const std::string &var_name)
Get a finite volume variable.
const std::vector< MooseVariableScalar * > & scalars() const
Get the list of scalar variables.
HashMap< unsigned, VectorMooseVariable * > _vector_vars_by_number
map of vector finite element variables with unsigned keys
void subdomainSetup()
Call subdomainSetup for all variables.
MooseVariableFE< T > * getFieldVariable(const std::string &var_name)
Get a finite element variable from the warehouse of either Real or RealVectorValue type.
void initialSetup()
Call initialSetup for all variables.
std::vector< MooseVariableFieldBase * > _vars
list of finite element variables
std::vector< MooseVariableScalar * > _scalar_vars
list of all scalar, non-finite element variables
const std::map< unsigned int, std::shared_ptr< MooseVariableBase > > & numberToVariableMap() const
Map from variable number to variable pointer.
void add(const std::string &var_name, std::shared_ptr< MooseVariableBase > var)
Add a variable.
void setActiveVariableCoupleableVectorTags(const std::set< TagID > &vtags)
Set the active vector tags for the variables.
HashMap< std::string, MooseVariable * > _regular_vars_by_name
map of non-vector finite element variables with name keys
HashMap< std::string, MooseLinearVariableFVReal * > _linear_fv_vars_by_name
map of non-vector linear finite volume 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, MooseLinearVariableFVReal * > _linear_fv_vars_by_number
map of non-vector finite element variables with unsigned keys
HashMap< unsigned, ArrayMooseVariable * > _array_vars_by_number
map of vector finite element variables with unsigned keys
void addBoundaryVar(BoundaryID bnd, const MooseVariableFieldBase *var)
Add a boundary variable.
HashMap< unsigned, MooseVariable * > _regular_vars_by_number
map of non-vector finite element variables with unsigned keys
HashMap< unsigned, MooseVariableFVReal * > _fv_vars_by_number
map of non-vector finite element variables with unsigned keys
void timestepSetup()
Call timestepSetup for all variables.
void clearAllDofIndices()
Clear all dof indices from each variable.
std::map< std::string, MooseVariableBase * > _var_name
Name to variable mapping.
const std::vector< MooseVariableFieldBase * > & fieldVariables() const
Get the list of variables.
MooseVariableField< T > * getActualFieldVariable(const std::string &var_name)
This should be called getFieldVariable, but that name is already taken by a legacy function.
std::vector< VariableName > _names
list of variable names
void residualSetup()
Call residualSetup for all variables.
std::map< unsigned int, std::shared_ptr< MooseVariableBase > > _all_objects
All instances of objects.
HashMap< std::string, ArrayMooseVariable * > _array_vars_by_name
map of vector finite element variables with name keys
const std::vector< VariableName > & names() const
Get the list of all variable names.
void customSetup(const ExecFlagType &exec_type)
Call setup on a particular execute flag for all variables.
HashMap< std::string, MooseVariableFVReal * > _fv_vars_by_name
map of non-vector finite element variables with name keys
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 setActiveScalarVariableCoupleableVectorTags(const std::set< TagID > &vtags)
Set the active vector tags for the variables.
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
VectorValue< Real > RealVectorValue
Definition SubProblem.h:34