GRINS-0.8.0
bc_factory_abstract.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 #ifndef GRINS_BC_FACTORY_ABSTRACT_H
26 #define GRINS_BC_FACTORY_ABSTRACT_H
27 
28 // GRINS
30 #include "grins/var_typedefs.h"
32 
33 // libMesh
34 #include "libmesh/libmesh.h"
35 #include "libmesh/boundary_info.h" // invalid_id
36 #include "grins/multiphysics_sys.h"
37 
38 namespace GRINS
39 {
40  // Forward declarations
41  class MultiphysicsSystem;
42 
43  template<typename Base>
44  class BCFactoryAbstract : public FactoryWithGetPot<Base>
45  {
46  public:
47  BCFactoryAbstract( const std::string& bc_type_name )
48  : FactoryWithGetPot<Base>(bc_type_name)
49  {}
50 
52 
53  static void set_system( MultiphysicsSystem& system )
54  { _system = &system; }
55 
57  static void set_bc_ids( const std::set<BoundaryID>& bc_ids )
58  { _bc_ids = &bc_ids; }
59 
61  static void set_fe_var( const FEVariablesBase& fe_var )
62  { _fe_var = &fe_var; }
63 
65 
69  static void set_section( const std::string& section )
70  { _section = section; }
71 
72  static bool have_bc_type( const std::string& bc_type );
73 
74  protected:
75 
77 
81  void check_for_multiple_expressions( const GetPot& input,const std::string& section,
82  const std::string& var_name ) const;
83 
84  void build_var_indices( const MultiphysicsSystem& system,
85  const std::vector<std::string>& var_names,
86  std::vector<VariableIndex>& var_indices ) const;
87 
89  virtual void check_state() const;
90 
92  virtual void reset_state();
93 
98 
100  static const std::set<BoundaryID>* _bc_ids;
101 
103 
106  static const FEVariablesBase* _fe_var;
107 
108  static std::string _section;
109 
110  };
111 
112  template<typename Base>
113  inline
114  void BCFactoryAbstract<Base>::check_for_multiple_expressions( const GetPot& input,const std::string& section,
115  const std::string& var_name ) const
116  {
117  std::string input_var = section+"/"+var_name;
118 
119  if( input.vector_variable_size(input_var) > 1 )
120  libmesh_error_msg("ERROR: expression size in input ["+input_var+"] is greater than 1!");
121  }
122 
123  template<typename Base>
124  inline
126  const std::vector<std::string>& var_names,
127  std::vector<VariableIndex>& var_indices ) const
128  {
129  var_indices.resize(var_names.size(),libMesh::invalid_uint);
130 
131  for( unsigned int i = 0; i < var_names.size(); i++ )
132  var_indices[i] = system.variable_number( var_names[i] );
133  }
134 
135  template<typename Base>
136  inline
138  {
139  if( !this->_input )
140  libmesh_error_msg("ERROR: must call set_getpot() before building boundary condition!");
141 
142  if( !_system )
143  libmesh_error_msg("ERROR: must call set_system() before building boundary condition!");
144 
145  if( !_bc_ids )
146  libmesh_error_msg("ERROR: must call set_bc_ids() before building boundary condition!");
147 
148  if( !_fe_var )
149  libmesh_error_msg("ERROR: must call set_fe_var() before building boundary condition!");
150 
151  if( _section == std::string("DIE!") )
152  libmesh_error_msg("ERROR: must call set_section() before building boundary condition!");
153  }
154 
155  template<typename Base>
156  inline
158  {
159  _bc_ids = NULL;
160  _fe_var = NULL;
161  _section = std::string("DIE!");
162  }
163 
164  template<typename Base>
165  inline
166  bool BCFactoryAbstract<Base>::have_bc_type( const std::string& bc_type )
167  {
168  const std::map<std::string, FactoryAbstract<Base>*>& map =
170 
171  bool have_bc = false;
172 
173  if( map.find(bc_type) != map.end() )
174  have_bc = true;
175 
176  return have_bc;
177  }
178 
179 } // end namespace GRINS
180 
181 #endif // GRINS_BC_FACTORY_ABSTRACT_H
static void set_fe_var(const FEVariablesBase &fe_var)
Active variable for the current boundary condition.
virtual void reset_state()
Helper function to redue code duplication.
static std::map< std::string, FactoryAbstract< Base > * > & factory_map()
static void set_section(const std::string &section)
Sets the current section of the input file.
static void set_system(MultiphysicsSystem &system)
static const std::set< BoundaryID > * _bc_ids
BoundaryID for constructing a particular boundary condition.
static bool have_bc_type(const std::string &bc_type)
BCFactoryAbstract(const std::string &bc_type_name)
const std::set< BoundaryID > * _bc_ids
GRINS namespace.
Interface with libMesh for solving Multiphysics problems.
virtual void check_state() const
Helper function to reduce code duplication.
void build_var_indices(const MultiphysicsSystem &system, const std::vector< std::string > &var_names, std::vector< VariableIndex > &var_indices) const
void check_for_multiple_expressions(const GetPot &input, const std::string &section, const std::string &var_name) const
Ensure that there is only one expression for the [Section/var_name] variable.
static MultiphysicsSystem * _system
We store only a raw pointer here because we can't make a copy.
Abstract factory that provides availability of GetPot.
static const FEVariablesBase * _fe_var
The FEVariablesBase class associated with the boundary condition being built.
static void set_bc_ids(const std::set< BoundaryID > &bc_ids)
Boundary id for the current boundary condition section.

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