GRINS-0.7.0
variable_warehouse.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // GRINS - General Reacting Incompressible Navier-Stokes
5 //
6 // Copyright (C) 2014-2016 Paul T. Bauman, Roy H. Stogner
7 // Copyright (C) 2010-2013 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 
26 #ifndef GRINS_VARIABLE_WAREHOUSE_H
27 #define GRINS_VARIABLE_WAREHOUSE_H
28 
29 // GRINS
31 
32 // libMesh
33 #include "libmesh/libmesh_common.h"
34 
35 namespace GRINS
36 {
38  namespace GRINSPrivate
39  {
41 
50  {
51  public:
53 
55 
57  static bool is_registered( const std::string& var_name );
58 
60 
62  static void check_and_register_variable( const std::string& var_name,
63  const FEVariablesBase& variable );
64 
65  static void register_variable( const std::string& var_name,
66  const FEVariablesBase& variable );
67 
68  static const FEVariablesBase& get_variable( const std::string& var_name );
69 
70  template <typename DerivedType>
71  static const DerivedType& get_variable_subclass( const std::string& var_name )
72  {
73  const FEVariablesBase& var_base = VariableWarehouse::get_variable(var_name);
74 
75  const DerivedType& derived_var = libMesh::cast_ref<const DerivedType&>( var_base);
76 
77  return derived_var;
78  }
79 
81  static void clear()
82  { var_map().clear(); }
83 
84  protected:
85 
86  static std::map<std::string,const FEVariablesBase*>& var_map();
87 
88  };
89 
90  inline
91  bool VariableWarehouse::is_registered( const std::string& var_name )
92  {
93  bool var_found = (var_map().find(var_name) != var_map().end() );
94  return var_found;
95  }
96 
97  inline
98  void VariableWarehouse::check_and_register_variable( const std::string& var_name,
99  const FEVariablesBase& variable )
100  {
101  if( !VariableWarehouse::is_registered(var_name) )
102  VariableWarehouse::register_variable(var_name,variable);
103  }
104 
105  inline
106  void VariableWarehouse::register_variable( const std::string& var_name,
107  const FEVariablesBase& variable )
108  {
109  if( VariableWarehouse::is_registered(var_name) )
110  libmesh_error_msg("ERROR: Duplicate FEVariable registration not allowed!");
111 
112  var_map()[var_name] = &variable;
113  }
114 
115  inline
116  const FEVariablesBase& VariableWarehouse::get_variable( const std::string& var_name )
117  {
118  if( !VariableWarehouse::is_registered(var_name) )
119  libmesh_error_msg("ERROR: Could not find FEVariable "+var_name+"!");
120 
121  const FEVariablesBase* var_ptr = var_map()[var_name];
122 
123  if( !var_ptr )
124  libmesh_error_msg("ERROR: FEVariable "+var_name+" is an invalid pointer!");
125 
126  return *var_ptr;
127  }
128 
129  } // end namespace GRINSPrivate
130 
131 } // end namespace GRINS
132 
133 #endif // GRINS_VARIABLE_WAREHOUSE_H
static std::map< std::string, const FEVariablesBase * > & var_map()
Track what FEVariablesBase objects have been created.
static void check_and_register_variable(const std::string &var_name, const FEVariablesBase &variable)
First check if var_name is registered and then register.
static const DerivedType & get_variable_subclass(const std::string &var_name)
GRINS namespace.
static void register_variable(const std::string &var_name, const FEVariablesBase &variable)
static void clear()
Clears the var_map()
static const FEVariablesBase & get_variable(const std::string &var_name)
static bool is_registered(const std::string &var_name)
Check if variable is registered.

Generated on Thu Jun 2 2016 21:52:28 for GRINS-0.7.0 by  doxygen 1.8.10