www.mooseframework.org
VariableWarehouse.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "VariableWarehouse.h"
16 #include "MooseVariable.h"
17 #include "MooseVariableScalar.h"
18 #include "MooseTypes.h"
19 
21 
23 {
24  for (auto & var : _all_objects)
25  delete var;
26 }
27 
28 void
29 VariableWarehouse::add(const std::string & var_name, MooseVariableBase * var)
30 {
31  _names.push_back(var_name);
32  _var_name[var_name] = var;
33  _all_objects.push_back(var);
34 
35  if (dynamic_cast<MooseVariable *>(var) != NULL)
36  {
37  _vars.push_back(dynamic_cast<MooseVariable *>(var));
38  }
39  else if (dynamic_cast<MooseVariableScalar *>(var) != NULL)
40  {
41  _scalar_vars.push_back(dynamic_cast<MooseVariableScalar *>(var));
42  }
43  else
44  mooseError("Unknown variable class passed into VariableWarehouse. Attempt to hack us?");
45 }
46 
47 void
49 {
50  _boundary_vars[bnd].insert(var);
51 }
52 
53 void
54 VariableWarehouse::addBoundaryVar(const std::set<BoundaryID> & boundary_ids, MooseVariable * var)
55 {
56  for (const auto & bid : boundary_ids)
57  addBoundaryVar(bid, var);
58 }
59 
60 void
61 VariableWarehouse::addBoundaryVars(const std::set<BoundaryID> & boundary_ids,
62  const std::map<std::string, std::vector<MooseVariable *>> & vars)
63 {
64  for (const auto & bid : boundary_ids)
65  for (const auto & it : vars)
66  for (const auto & var : it.second)
67  addBoundaryVar(bid, var);
68 }
69 
71 VariableWarehouse::getVariable(const std::string & var_name)
72 {
73  return _var_name[var_name];
74 }
75 
77 VariableWarehouse::getVariable(unsigned int var_number)
78 {
79  if (var_number < _all_objects.size())
80  return _all_objects[var_number];
81  else
82  return NULL;
83 }
84 
85 const std::vector<VariableName> &
87 {
88  return _names;
89 }
90 
91 const std::vector<MooseVariable *> &
93 {
94  return _vars;
95 }
96 
97 const std::vector<MooseVariableScalar *> &
99 {
100  return _scalar_vars;
101 }
102 
103 const std::set<MooseVariable *> &
105 {
106  return _boundary_vars[bnd];
107 }
void add(const std::string &var_name, MooseVariableBase *var)
Add a variable.
virtual ~VariableWarehouse()
std::vector< MooseVariableScalar * > _scalar_vars
list of all variables
Class for stuff related to variables.
Definition: MooseVariable.h:43
void addBoundaryVar(BoundaryID bnd, MooseVariable *var)
Add a boundary variable.
const std::vector< MooseVariableScalar * > & scalars()
Get the list of scalar variables.
MooseVariableBase * getVariable(const std::string &var_name)
Get a variable from the warehouse.
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
const std::vector< MooseVariable * > & variables()
Get the list of variables.
std::vector< MooseVariableBase * > _all_objects
All instances of objects (raw pointers)
const std::set< MooseVariable * > & boundaryVars(BoundaryID bnd)
Get the list of variables that needs to be reinitialized on a given boundary.
std::map< std::string, MooseVariableBase * > _var_name
Name to variable mapping.
std::vector< MooseVariable * > _vars
list of "normal" variables
const std::vector< VariableName > & names() const
Get the list of all variable names.
std::vector< VariableName > _names
list of variable names
void addBoundaryVars(const std::set< BoundaryID > &boundary_ids, const std::map< std::string, std::vector< MooseVariable * >> &vars)
Add a map of variables to a set of boundaries.
std::map< BoundaryID, std::set< MooseVariable * > > _boundary_vars
Map to variables that need to be evaluated on a boundary.
boundary_id_type BoundaryID
Definition: MooseTypes.h:75