GRINS-0.8.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-2017 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  SharedPtr<FEVariablesBase>& variable );
64 
65  static void register_variable( const std::string& var_name,
66  SharedPtr<FEVariablesBase>& variable );
67 
68  static SharedPtr<FEVariablesBase> get_variable_ptr( const std::string& var_name );
69 
70  static FEVariablesBase& get_variable( const std::string& var_name );
71 
72  template <typename DerivedType>
73  static DerivedType& get_variable_subclass( const std::string& var_name );
74 
76  static void clear()
77  { var_map().clear(); }
78 
79  protected:
80 
81  static std::map<std::string,SharedPtr<FEVariablesBase> >& var_map();
82 
83  };
84 
85  inline
86  bool VariableWarehouse::is_registered( const std::string& var_name )
87  {
88  bool var_found = (var_map().find(var_name) != var_map().end() );
89  return var_found;
90  }
91 
92  inline
93  void VariableWarehouse::check_and_register_variable( const std::string& var_name,
94  SharedPtr<FEVariablesBase>& variable )
95  {
96  if( !VariableWarehouse::is_registered(var_name) )
97  VariableWarehouse::register_variable(var_name,variable);
98  }
99 
100  inline
101  void VariableWarehouse::register_variable( const std::string& var_name,
102  SharedPtr<FEVariablesBase>& 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  }
109 
110  inline
111  FEVariablesBase& VariableWarehouse::get_variable( const std::string& var_name )
112  {
113  SharedPtr<FEVariablesBase> var_ptr = VariableWarehouse::get_variable_ptr(var_name);
114  return *var_ptr;
115  }
116 
117  template <typename DerivedType>
118  inline
119  DerivedType& VariableWarehouse::get_variable_subclass( const std::string& var_name )
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  }
127 
128  } // end namespace GRINSPrivate
129 
130 } // end namespace GRINS
131 
132 #endif // GRINS_VARIABLE_WAREHOUSE_H
static void check_and_register_variable(const std::string &var_name, SharedPtr< FEVariablesBase > &variable)
First check if var_name is registered and then register.
static SharedPtr< FEVariablesBase > get_variable_ptr(const std::string &var_name)
Track what FEVariablesBase objects have been created.
static DerivedType & get_variable_subclass(const std::string &var_name)
GRINS namespace.
static FEVariablesBase & get_variable(const std::string &var_name)
static std::map< std::string, SharedPtr< FEVariablesBase > > & var_map()
static void register_variable(const std::string &var_name, SharedPtr< FEVariablesBase > &variable)
static void clear()
Clears the var_map()
static bool is_registered(const std::string &var_name)
Check if variable is registered.

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