GRINS-0.8.0
List of all members | Public Member Functions | Static Public Member Functions | Static Protected Member Functions
GRINS::GRINSPrivate::VariableWarehouse Class Reference

Track what FEVariablesBase objects have been created. More...

#include <variable_warehouse.h>

Public Member Functions

 VariableWarehouse ()
 
 ~VariableWarehouse ()
 

Static Public Member Functions

static bool is_registered (const std::string &var_name)
 Check if variable is registered. More...
 
static void check_and_register_variable (const std::string &var_name, SharedPtr< FEVariablesBase > &variable)
 First check if var_name is registered and then register. More...
 
static void register_variable (const std::string &var_name, SharedPtr< FEVariablesBase > &variable)
 
static SharedPtr< FEVariablesBaseget_variable_ptr (const std::string &var_name)
 
static FEVariablesBaseget_variable (const std::string &var_name)
 
template<typename DerivedType >
static DerivedType & get_variable_subclass (const std::string &var_name)
 
static void clear ()
 Clears the var_map() More...
 

Static Protected Member Functions

static std::map< std::string, SharedPtr< FEVariablesBase > > & var_map ()
 

Detailed Description

Track what FEVariablesBase objects have been created.

Several modules need to interact with the Variables in use. So, this object creates a place to register a Variable class.

Todo:
Currently, we only allow only unique variable types. This will change in the future once we allow per-subdomain variables. Hence, we have this in GRINSPrivate since the API may change in the future.

Definition at line 49 of file variable_warehouse.h.

Constructor & Destructor Documentation

GRINS::GRINSPrivate::VariableWarehouse::VariableWarehouse ( )
inline

Definition at line 52 of file variable_warehouse.h.

52 {};
GRINS::GRINSPrivate::VariableWarehouse::~VariableWarehouse ( )
inline

Definition at line 54 of file variable_warehouse.h.

54 {};

Member Function Documentation

void GRINS::GRINSPrivate::VariableWarehouse::check_and_register_variable ( const std::string &  var_name,
SharedPtr< FEVariablesBase > &  variable 
)
inlinestatic

First check if var_name is registered and then register.

Use this API if you may be attempting to register the same variable more than once.

Definition at line 93 of file variable_warehouse.h.

References is_registered(), and register_variable().

95  {
96  if( !VariableWarehouse::is_registered(var_name) )
97  VariableWarehouse::register_variable(var_name,variable);
98  }
static void register_variable(const std::string &var_name, SharedPtr< FEVariablesBase > &variable)
static bool is_registered(const std::string &var_name)
Check if variable is registered.
static void GRINS::GRINSPrivate::VariableWarehouse::clear ( )
inlinestatic
FEVariablesBase & GRINS::GRINSPrivate::VariableWarehouse::get_variable ( const std::string &  var_name)
inlinestatic
SharedPtr< FEVariablesBase > GRINS::GRINSPrivate::VariableWarehouse::get_variable_ptr ( const std::string &  var_name)
static

Definition at line 38 of file variable_warehouse.C.

References is_registered(), and var_map().

Referenced by get_variable().

39  {
40  if( !VariableWarehouse::is_registered(var_name) )
41  {
42  const std::map<std::string,SharedPtr<FEVariablesBase> >& map = var_map();
43 
44  std::stringstream error_msg;
45  error_msg << "ERROR: Could not find Variable "+var_name+" in the VariableWarehouse!"
46  << std::endl
47  << " Variables currently the VariableWarehouse are: "
48  << (map.begin())->first << std::endl;
49 
50  std::map<std::string,SharedPtr<FEVariablesBase> >::const_iterator it = map.begin();
51  it++;
52  for( ; it != map.end(); ++it )
53  error_msg << std::string(54,' ') << it->first << std::endl;
54 
55  libmesh_error_msg(error_msg.str());
56  }
57 
58  SharedPtr<FEVariablesBase> var_ptr = var_map()[var_name];
59 
60  if( !var_ptr )
61  libmesh_error_msg("ERROR: Variable "+var_name+" is an invalid pointer!");
62 
63  return var_ptr;
64  }
static std::map< std::string, SharedPtr< FEVariablesBase > > & var_map()
static bool is_registered(const std::string &var_name)
Check if variable is registered.
template<typename DerivedType >
DerivedType & GRINS::GRINSPrivate::VariableWarehouse::get_variable_subclass ( const std::string &  var_name)
inlinestatic

Definition at line 119 of file variable_warehouse.h.

References get_variable().

120  {
121  FEVariablesBase& var_base = VariableWarehouse::get_variable(var_name);
122 
123  DerivedType& derived_var = libMesh::cast_ref<DerivedType&>(var_base);
124 
125  return derived_var;
126  }
static FEVariablesBase & get_variable(const std::string &var_name)
bool GRINS::GRINSPrivate::VariableWarehouse::is_registered ( const std::string &  var_name)
inlinestatic

Check if variable is registered.

Definition at line 86 of file variable_warehouse.h.

References var_map().

Referenced by check_and_register_variable(), get_variable_ptr(), and register_variable().

87  {
88  bool var_found = (var_map().find(var_name) != var_map().end() );
89  return var_found;
90  }
static std::map< std::string, SharedPtr< FEVariablesBase > > & var_map()
void GRINS::GRINSPrivate::VariableWarehouse::register_variable ( const std::string &  var_name,
SharedPtr< FEVariablesBase > &  variable 
)
inlinestatic

Definition at line 101 of file variable_warehouse.h.

References is_registered(), and var_map().

Referenced by GRINS::VariableBuilder::add_variable_to_warehouse(), and check_and_register_variable().

103  {
104  if( VariableWarehouse::is_registered(var_name) )
105  libmesh_error_msg("ERROR: Duplicate FEVariable registration not allowed!");
106 
107  var_map()[var_name] = variable;
108  }
static std::map< std::string, SharedPtr< FEVariablesBase > > & var_map()
static bool is_registered(const std::string &var_name)
Check if variable is registered.
std::map< std::string, SharedPtr< FEVariablesBase > > & GRINS::GRINSPrivate::VariableWarehouse::var_map ( )
staticprotected

Definition at line 32 of file variable_warehouse.C.

Referenced by clear(), get_variable_ptr(), is_registered(), and register_variable().

33  {
34  static std::map<std::string,SharedPtr<FEVariablesBase> > _var_map;
35  return _var_map;
36  }

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

Generated on Tue Dec 19 2017 12:47:32 for GRINS-0.8.0 by  doxygen 1.8.9.1