www.mooseframework.org
Public Member Functions | Protected Attributes | List of all members
VariableWarehouse Class Reference

Holds variables and provides some services. More...

#include <VariableWarehouse.h>

Public Member Functions

 VariableWarehouse ()
 
virtual ~VariableWarehouse ()
 
void add (const std::string &var_name, MooseVariableBase *var)
 Add a variable. More...
 
void addBoundaryVar (BoundaryID bnd, MooseVariableFEBase *var)
 Add a boundary variable. More...
 
void addBoundaryVar (const std::set< BoundaryID > &boundary_ids, MooseVariableFEBase *var)
 Add a variable to a set of boundaries. More...
 
void addBoundaryVars (const std::set< BoundaryID > &boundary_ids, const std::map< std::string, std::vector< MooseVariableFEBase *>> &vars)
 Add a map of variables to a set of boundaries. More...
 
MooseVariableBasegetVariable (const std::string &var_name)
 Get a variable from the warehouse. More...
 
MooseVariableBasegetVariable (unsigned int var_number)
 Get a variable from the warehouse. More...
 
template<typename T >
MooseVariableFE< T > * getFieldVariable (const std::string &var_name)
 Get a finite element variable from the warehouse of either Real or RealVectorValue type. More...
 
template<typename T >
MooseVariableFE< T > * getFieldVariable (unsigned int var_number)
 Get a finite element variable from the warehouse of either Real or RealVectorValue type. More...
 
const std::vector< VariableName > & names () const
 Get the list of all variable names. More...
 
const std::vector< MooseVariableFEBase * > & fieldVariables ()
 Get the list of variables. More...
 
const std::set< MooseVariableFEBase * > & boundaryVars (BoundaryID bnd)
 Get the list of variables that needs to be reinitialized on a given boundary. More...
 
const std::vector< MooseVariableScalar * > & scalars ()
 Get the list of scalar variables. More...
 
template<>
MooseVariableFE< RealVectorValue > * getFieldVariable (const std::string &var_name)
 
template<>
MooseVariableFE< RealVectorValue > * getFieldVariable (unsigned int var_number)
 
template<>
MooseVariableFE< RealVectorValue > * getFieldVariable (const std::string &var_name)
 
template<>
MooseVariableFE< RealVectorValue > * getFieldVariable (unsigned int var_number)
 

Protected Attributes

std::vector< VariableName > _names
 list of variable names More...
 
std::vector< MooseVariableFEBase * > _vars
 list of finite element variables More...
 
HashMap< std::string, MooseVariable * > _regular_vars_by_name
 map of non-vector finite element variables with name keys More...
 
HashMap< unsigned, MooseVariable * > _regular_vars_by_number
 map of non-vector finite element variables with unsigned keys More...
 
HashMap< std::string, VectorMooseVariable * > _vector_vars_by_name
 map of vector finite element variables with name keys More...
 
HashMap< unsigned, VectorMooseVariable * > _vector_vars_by_number
 map of vector finite element variables with unsigned keys More...
 
std::map< std::string, MooseVariableBase * > _var_name
 Name to variable mapping. More...
 
std::map< BoundaryID, std::set< MooseVariableFEBase * > > _boundary_vars
 Map to variables that need to be evaluated on a boundary. More...
 
std::vector< MooseVariableScalar * > _scalar_vars
 list of all scalar, non-finite element variables More...
 
std::vector< MooseVariableBase * > _all_objects
 All instances of objects (raw pointers) More...
 

Detailed Description

Holds variables and provides some services.

Definition at line 31 of file VariableWarehouse.h.

Constructor & Destructor Documentation

◆ VariableWarehouse()

VariableWarehouse::VariableWarehouse ( )

Definition at line 15 of file VariableWarehouse.C.

15 {}

◆ ~VariableWarehouse()

VariableWarehouse::~VariableWarehouse ( )
virtual

Definition at line 17 of file VariableWarehouse.C.

18 {
19  for (auto & var : _all_objects)
20  delete var;
21 }
std::vector< MooseVariableBase * > _all_objects
All instances of objects (raw pointers)

Member Function Documentation

◆ add()

void VariableWarehouse::add ( const std::string &  var_name,
MooseVariableBase var 
)

Add a variable.

Parameters
var_nameThe name of the variable
varVariable

Definition at line 24 of file VariableWarehouse.C.

25 {
26  _names.push_back(var_name);
27  _var_name[var_name] = var;
28  _all_objects.push_back(var);
29 
30  if (auto * tmp_var = dynamic_cast<MooseVariableFEBase *>(var))
31  {
32  _vars.push_back(tmp_var);
33  if (auto * tmp_var = dynamic_cast<MooseVariable *>(var))
34  {
35  _regular_vars_by_number[tmp_var->number()] = tmp_var;
36  _regular_vars_by_name[var_name] = tmp_var;
37  }
38  else if (auto * tmp_var = dynamic_cast<VectorMooseVariable *>(var))
39  {
40  _vector_vars_by_number[tmp_var->number()] = tmp_var;
41  _vector_vars_by_name[var_name] = tmp_var;
42  }
43  else
44  mooseError("Unknown variable class passed into VariableWarehouse. Attempt to hack us?");
45  }
46  else if (auto * tmp_var = dynamic_cast<MooseVariableScalar *>(var))
47  _scalar_vars.push_back(tmp_var);
48  else
49  mooseError("Unknown variable class passed into VariableWarehouse. Attempt to hack us?");
50 }
std::vector< MooseVariableScalar * > _scalar_vars
list of all scalar, non-finite element variables
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
std::vector< MooseVariableFEBase * > _vars
list of finite element variables
std::vector< MooseVariableBase * > _all_objects
All instances of objects (raw pointers)
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
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
HashMap< std::string, MooseVariable * > _regular_vars_by_name
map of non-vector finite element variables with name keys
HashMap< unsigned, VectorMooseVariable * > _vector_vars_by_number
map of vector finite element variables with unsigned keys

◆ addBoundaryVar() [1/2]

void VariableWarehouse::addBoundaryVar ( BoundaryID  bnd,
MooseVariableFEBase var 
)

Add a boundary variable.

Parameters
bndThe boundary id where this variable is defined
varThe variable

Definition at line 53 of file VariableWarehouse.C.

Referenced by addBoundaryVar(), and addBoundaryVars().

54 {
55  _boundary_vars[bnd].insert(var);
56 }
std::map< BoundaryID, std::set< MooseVariableFEBase * > > _boundary_vars
Map to variables that need to be evaluated on a boundary.

◆ addBoundaryVar() [2/2]

void VariableWarehouse::addBoundaryVar ( const std::set< BoundaryID > &  boundary_ids,
MooseVariableFEBase var 
)

Add a variable to a set of boundaries.

Parameters
boundary_idsThe boundary ids where this variable is defined
varThe variable

Definition at line 59 of file VariableWarehouse.C.

61 {
62  for (const auto & bid : boundary_ids)
63  addBoundaryVar(bid, var);
64 }
void addBoundaryVar(BoundaryID bnd, MooseVariableFEBase *var)
Add a boundary variable.

◆ addBoundaryVars()

void VariableWarehouse::addBoundaryVars ( const std::set< BoundaryID > &  boundary_ids,
const std::map< std::string, std::vector< MooseVariableFEBase *>> &  vars 
)

Add a map of variables to a set of boundaries.

Parameters
boundary_idsThe boundary ids where this variable is defined
varsA map of variables

Definition at line 67 of file VariableWarehouse.C.

70 {
71  for (const auto & bid : boundary_ids)
72  for (const auto & it : vars)
73  for (const auto & var : it.second)
74  addBoundaryVar(bid, var);
75 }
void addBoundaryVar(BoundaryID bnd, MooseVariableFEBase *var)
Add a boundary variable.

◆ boundaryVars()

const std::set< MooseVariableFEBase * > & VariableWarehouse::boundaryVars ( BoundaryID  bnd)

Get the list of variables that needs to be reinitialized on a given boundary.

Parameters
bndThe boundary ID
Returns
The list of variables

Definition at line 111 of file VariableWarehouse.C.

112 {
113  return _boundary_vars[bnd];
114 }
std::map< BoundaryID, std::set< MooseVariableFEBase * > > _boundary_vars
Map to variables that need to be evaluated on a boundary.

◆ fieldVariables()

const std::vector< MooseVariableFEBase * > & VariableWarehouse::fieldVariables ( )

Get the list of variables.

Returns
The list of variables

Definition at line 99 of file VariableWarehouse.C.

100 {
101  return _vars;
102 }
std::vector< MooseVariableFEBase * > _vars
list of finite element variables

◆ getFieldVariable() [1/6]

template<>
MooseVariableFE<RealVectorValue>* VariableWarehouse::getFieldVariable ( const std::string &  var_name)

◆ getFieldVariable() [2/6]

template<>
MooseVariableFE<RealVectorValue>* VariableWarehouse::getFieldVariable ( unsigned int  var_number)

◆ getFieldVariable() [3/6]

template<typename T >
MooseVariableFE< T > * VariableWarehouse::getFieldVariable ( const std::string &  var_name)

Get a finite element variable from the warehouse of either Real or RealVectorValue type.

Parameters
var_nameThe name of the variable to retrieve
Returns
The retrieved variable

Definition at line 118 of file VariableWarehouse.C.

119 {
120  return _regular_vars_by_name.at(var_name);
121 }
HashMap< std::string, MooseVariable * > _regular_vars_by_name
map of non-vector finite element variables with name keys

◆ getFieldVariable() [4/6]

template<typename T >
MooseVariableFE< T > * VariableWarehouse::getFieldVariable ( unsigned int  var_number)

Get a finite element variable from the warehouse of either Real or RealVectorValue type.

Parameters
var_numberThe number of the variable to retrieve
Returns
The retrieved variable

Definition at line 125 of file VariableWarehouse.C.

126 {
127  return _regular_vars_by_number.at(var_number);
128 }
HashMap< unsigned, MooseVariable * > _regular_vars_by_number
map of non-vector finite element variables with unsigned keys

◆ getFieldVariable() [5/6]

template<>
template MooseVariableFE< Real > * VariableWarehouse::getFieldVariable< Real > ( unsigned int  var_number)

Definition at line 139 of file VariableWarehouse.C.

140 {
141  return _vector_vars_by_number.at(var_number);
142 }
HashMap< unsigned, VectorMooseVariable * > _vector_vars_by_number
map of vector finite element variables with unsigned keys

◆ getFieldVariable() [6/6]

template<>
template MooseVariableFE< Real > * VariableWarehouse::getFieldVariable< Real > ( const std::string &  var_name)

Definition at line 132 of file VariableWarehouse.C.

133 {
134  return _vector_vars_by_name.at(var_name);
135 }
HashMap< std::string, VectorMooseVariable * > _vector_vars_by_name
map of vector finite element variables with name keys

◆ getVariable() [1/2]

MooseVariableBase * VariableWarehouse::getVariable ( const std::string &  var_name)

Get a variable from the warehouse.

Parameters
var_nameThe name of the variable to retrieve
Returns
The retrieved variable

Definition at line 78 of file VariableWarehouse.C.

79 {
80  return _var_name[var_name];
81 }
std::map< std::string, MooseVariableBase * > _var_name
Name to variable mapping.

◆ getVariable() [2/2]

MooseVariableBase * VariableWarehouse::getVariable ( unsigned int  var_number)

Get a variable from the warehouse.

Parameters
var_numberThe number of the variable to retrieve
Returns
The retrieved variable

Definition at line 84 of file VariableWarehouse.C.

85 {
86  if (var_number < _all_objects.size())
87  return _all_objects[var_number];
88  else
89  return NULL;
90 }
std::vector< MooseVariableBase * > _all_objects
All instances of objects (raw pointers)

◆ names()

const std::vector< VariableName > & VariableWarehouse::names ( ) const

Get the list of all variable names.

Returns
The list of variable names

Definition at line 93 of file VariableWarehouse.C.

94 {
95  return _names;
96 }
std::vector< VariableName > _names
list of variable names

◆ scalars()

const std::vector< MooseVariableScalar * > & VariableWarehouse::scalars ( )

Get the list of scalar variables.

Returns
The list of scalar variables

Definition at line 105 of file VariableWarehouse.C.

106 {
107  return _scalar_vars;
108 }
std::vector< MooseVariableScalar * > _scalar_vars
list of all scalar, non-finite element variables

Member Data Documentation

◆ _all_objects

std::vector<MooseVariableBase *> VariableWarehouse::_all_objects
protected

All instances of objects (raw pointers)

Definition at line 152 of file VariableWarehouse.h.

Referenced by add(), getVariable(), and ~VariableWarehouse().

◆ _boundary_vars

std::map<BoundaryID, std::set<MooseVariableFEBase *> > VariableWarehouse::_boundary_vars
protected

Map to variables that need to be evaluated on a boundary.

Definition at line 146 of file VariableWarehouse.h.

Referenced by addBoundaryVar(), and boundaryVars().

◆ _names

std::vector<VariableName> VariableWarehouse::_names
protected

list of variable names

Definition at line 125 of file VariableWarehouse.h.

Referenced by add(), and names().

◆ _regular_vars_by_name

HashMap<std::string, MooseVariable *> VariableWarehouse::_regular_vars_by_name
protected

map of non-vector finite element variables with name keys

Definition at line 131 of file VariableWarehouse.h.

Referenced by add(), and getFieldVariable().

◆ _regular_vars_by_number

HashMap<unsigned, MooseVariable *> VariableWarehouse::_regular_vars_by_number
protected

map of non-vector finite element variables with unsigned keys

Definition at line 134 of file VariableWarehouse.h.

Referenced by add(), and getFieldVariable().

◆ _scalar_vars

std::vector<MooseVariableScalar *> VariableWarehouse::_scalar_vars
protected

list of all scalar, non-finite element variables

Definition at line 149 of file VariableWarehouse.h.

Referenced by add(), and scalars().

◆ _var_name

std::map<std::string, MooseVariableBase *> VariableWarehouse::_var_name
protected

Name to variable mapping.

Definition at line 143 of file VariableWarehouse.h.

Referenced by add(), and getVariable().

◆ _vars

std::vector<MooseVariableFEBase *> VariableWarehouse::_vars
protected

list of finite element variables

Definition at line 128 of file VariableWarehouse.h.

Referenced by add(), and fieldVariables().

◆ _vector_vars_by_name

HashMap<std::string, VectorMooseVariable *> VariableWarehouse::_vector_vars_by_name
protected

map of vector finite element variables with name keys

Definition at line 137 of file VariableWarehouse.h.

Referenced by add().

◆ _vector_vars_by_number

HashMap<unsigned, VectorMooseVariable *> VariableWarehouse::_vector_vars_by_number
protected

map of vector finite element variables with unsigned keys

Definition at line 140 of file VariableWarehouse.h.

Referenced by add().


The documentation for this class was generated from the following files: