GRINS-0.8.0
variable_factory.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_VARIABLE_FACTORY_H
26 #define GRINS_VARIABLE_FACTORY_H
27 
28 // GRINS
32 
33 // libMesh
34 #include "libmesh/factory.h"
35 
36 namespace GRINS
37 {
38  // According to the standard, we need a declaration of the
39  // specialization which precedes any automatic instantiation.
41 
42  class VariableFactoryAbstract : public FactoryWithGetPot<FEVariablesBase>
43  {
44  public:
45 
46  VariableFactoryAbstract( const std::string& name )
48  {}
49 
51 
52  virtual libMesh::UniquePtr<FEVariablesBase> create();
53 
55 
58  static std::vector<std::string> build_var_names( const std::string& name );
59 
60  static std::string parse_fe_family( const std::string& name );
61 
62  static std::string parse_fe_order( const std::string& name );
63 
65  static void set_var_names( const std::vector<std::string>& var_names )
66  { _var_names = &var_names; }
67 
69  static void set_var_indices( const std::vector<VariableIndex>& var_indices )
70  { _var_indices = &var_indices; }
71 
73 
74  static void set_var_section( const std::string& var_section )
75  { _var_section = var_section; }
76 
77  static void set_subdomain_ids( const std::set<libMesh::subdomain_id_type>& subdomain_ids )
78  { _subdomain_ids = &subdomain_ids; }
79 
80  protected:
81 
83  virtual void check_create_state() const;
84 
86  virtual void reset_create_state();
87 
89  static void check_build_parse_state();
90 
92  static void reset_build_parse_state();
93 
95 
98  virtual libMesh::UniquePtr<FEVariablesBase> build_fe_var( const std::vector<std::string>& var_names,
99  const std::vector<VariableIndex>& var_indices,
100  const std::set<libMesh::subdomain_id_type>& subdomain_ids ) =0;
101 
102  // Subclasses implement this to parse the variable component name(s)
103  virtual std::vector<std::string> parse_var_names( const GetPot& input, const std::string& var_section ) =0;
104 
105  virtual std::string parse_fe_family_impl( const GetPot& input, const std::string& var_section ) =0;
106 
107  virtual std::string parse_fe_order_impl( const GetPot& input, const std::string& var_section ) =0;
108 
109  std::string parse_var_option( const GetPot& input,
110  const std::string& var_section,
111  const std::string& option,
112  const std::string& default_val ) const
113  {
114  std::string input_sec = var_section+"/"+option;
115  if(!input.have_variable(input_sec))
116  libmesh_error_msg("ERROR: Could not find Variable input option "+input_sec);
117 
118  return input(input_sec,default_val);
119  }
120 
121 
123  static const std::vector<std::string>* _var_names;
124 
126  static const std::vector<VariableIndex>* _var_indices;
127 
129  static std::string _var_section;
130 
132  static const std::set<libMesh::subdomain_id_type>* _subdomain_ids;
133 
134  private:
135 
137 
138  };
139 
142  {
143  public:
144 
145  VariableFactoryBase( const std::string& name )
147  {}
148 
150 
151  protected:
152 
153  virtual std::string parse_fe_family_impl( const GetPot& input, const std::string& var_section )
154  {
155  return this->parse_var_option(input,var_section,std::string("fe_family"),std::string("DIE!"));
156  }
157 
158  virtual std::string parse_fe_order_impl( const GetPot& input, const std::string& var_section )
159  {
160  return this->parse_var_option(input,var_section,std::string("order"),std::string("DIE!"));
161  }
162 
163  };
164 
166  template<typename VariableType>
168  {
169  public:
170 
171  VariableFactoryBasic( const std::string& name )
172  : VariableFactoryBase(name)
173  {}
174 
176 
177  protected:
178 
179  virtual libMesh::UniquePtr<FEVariablesBase>
180  build_fe_var( const std::vector<std::string>& var_names,
181  const std::vector<VariableIndex>& var_indices,
182  const std::set<libMesh::subdomain_id_type>& subdomain_ids )
183  {
184  return libMesh::UniquePtr<FEVariablesBase>( new VariableType(var_names,var_indices,subdomain_ids) );
185  }
186 
188  virtual std::vector<std::string>
189  parse_var_names( const GetPot& input, const std::string& var_section );
190 
191  };
192 
194 
196  template<typename VariableType>
197  class ScalarVariableFactory : public VariableFactoryBasic<VariableType>
198  {
199  public:
200 
201  ScalarVariableFactory( const std::string& name )
202  : VariableFactoryBasic<VariableType>(name)
203  {}
204 
206 
207  protected:
208 
209  virtual std::string parse_fe_family_impl( const GetPot& input, const std::string& var_section )
210  {
211  if( input.have_variable(var_section+"/fe_family") )
212  libmesh_error_msg("ERROR: Cannot specify fe_family for ScalarVariable. It is implicitly SCALAR!");
213 
214  return std::string("SCALAR");
215  }
216  };
217 
218 
220 
222  template<typename VariableType>
224  {
225  public:
226 
227  SpeciesVariableFactory( const std::string& name )
228  : VariableFactoryBase(name)
229  {}
230 
232 
233  protected:
234 
236 
240  virtual std::vector<std::string> parse_var_names( const GetPot& input, const std::string& var_section );
241 
242  virtual libMesh::UniquePtr<FEVariablesBase> build_fe_var( const std::vector<std::string>& var_names,
243  const std::vector<VariableIndex>& var_indices,
244  const std::set<libMesh::subdomain_id_type>& subdomain_ids )
245  { return libMesh::UniquePtr<FEVariablesBase>( new VariableType(var_names,var_indices,_prefix,_material,subdomain_ids) ); }
246 
247  std::string _prefix;
248 
249  std::string _material;
250  };
251 
252  template<typename VariableType>
253  inline
254  std::vector<std::string> VariableFactoryBasic<VariableType>::parse_var_names( const GetPot& input,
255  const std::string& var_section )
256  {
257  std::vector<std::string> var_names;
258 
259  std::string input_sec = var_section+"/names";
260 
261  // Make sure the names are present
262  if( !input.have_variable(input_sec) )
263  libmesh_error_msg("ERROR: Could not find input parameter "+input_sec);
264 
265  unsigned int n_names = input.vector_variable_size(input_sec);
266 
267  var_names.resize(n_names);
268  for( unsigned int i = 0; i < n_names; i++ )
269  var_names[i] = input(input_sec,std::string("DIE!"),i);
270 
271  return var_names;
272  }
273 
274  template<typename VariableType>
275  inline
276  std::vector<std::string> SpeciesVariableFactory<VariableType>::parse_var_names( const GetPot& input,
277  const std::string& var_section )
278  {
279  // Make sure the prefix is present
280  std::string prefix_sec = var_section+"/names";
281  if( !input.have_variable(prefix_sec) )
282  libmesh_error_msg("ERROR: Could not find input parameter "+prefix_sec+" for species prefix!");
283 
284  // Make sure the material is present
285  std::string material_sec = var_section+"/material";
286  if( !input.have_variable(material_sec) )
287  libmesh_error_msg("ERROR: Could not find input parameter "+material_sec+" for species material!");
288 
289  this->_prefix = input(prefix_sec,std::string("DIE!"));
290  this->_material = input(material_sec,std::string("DIE!"));
291 
292  std::vector<std::string> var_names;
293  MaterialsParsing::parse_species_varnames(input,this->_material,this->_prefix,var_names);
294 
295  return var_names;
296  }
297 
298 } // end namespace GRINS
299 
300 #endif // GRINS_VARIABLE_FACTORY_H
static std::string _var_section
Section of input to parse variable names in build_var_names.
static void parse_species_varnames(const GetPot &input, const std::string &material, const std::string &prefix, std::vector< std::string > &species_names)
Helper function for parsing the chemical species and setting variable name.
virtual libMesh::UniquePtr< FEVariablesBase > build_fe_var(const std::vector< std::string > &var_names, const std::vector< VariableIndex > &var_indices, const std::set< libMesh::subdomain_id_type > &subdomain_ids)=0
Subclasses implement construction of the FEVariablesBase object using the var_names and var_indices...
virtual void check_create_state() const
Helper function to check required data is set when calling create()
virtual std::string parse_fe_family_impl(const GetPot &input, const std::string &var_section)
virtual std::string parse_fe_family_impl(const GetPot &input, const std::string &var_section)
static void check_build_parse_state()
Helper function to check required data is set when calling build_* or parse_* methods.
virtual libMesh::UniquePtr< FEVariablesBase > build_fe_var(const std::vector< std::string > &var_names, const std::vector< VariableIndex > &var_indices, const std::set< libMesh::subdomain_id_type > &subdomain_ids)
Subclasses implement construction of the FEVariablesBase object using the var_names and var_indices...
virtual std::vector< std::string > parse_var_names(const GetPot &input, const std::string &var_section)=0
virtual void reset_create_state()
Helper function to reset data before next call to create()
static void set_var_indices(const std::vector< VariableIndex > &var_indices)
Set the variable indices before calling create()
VariableFactoryAbstract(const std::string &name)
SpeciesVariableFactory(const std::string &name)
Common implementations.
virtual libMesh::UniquePtr< FEVariablesBase > create()
Subclasses implement the actual construction of the Base object in create().
static const std::vector< std::string > * _var_names
Variable component names needed for FEVariableBase construction.
static void reset_build_parse_state()
Helper function to check required data is set when calling build_* or parse_* methods.
virtual std::vector< std::string > parse_var_names(const GetPot &input, const std::string &var_section)
The basic factory implementation looks in [Variables//names].
static void set_var_names(const std::vector< std::string > &var_names)
Set the variable names before calling create()
static std::vector< std::string > build_var_names(const std::string &name)
Build the variable names for the FEVariablesBase type (name), returned in the std::vector.
static void set_subdomain_ids(const std::set< libMesh::subdomain_id_type > &subdomain_ids)
Factory to build SCALAR variable.
ScalarVariableFactory(const std::string &name)
virtual std::string parse_fe_family_impl(const GetPot &input, const std::string &var_section)=0
virtual std::vector< std::string > parse_var_names(const GetPot &input, const std::string &var_section)
Implementation species variable name parsing.
GRINS namespace.
std::string parse_var_option(const GetPot &input, const std::string &var_section, const std::string &option, const std::string &default_val) const
Factory to build "standard" FEVariablesBase classes.
static void set_var_section(const std::string &var_section)
Set the section for the input file before calling build_var_names()
Factory to build FEVariablesBase classes that use species names as variables.
virtual std::string parse_fe_order_impl(const GetPot &input, const std::string &var_section)
VariableFactoryBasic(const std::string &name)
static std::string parse_fe_family(const std::string &name)
VariableFactoryBase(const std::string &name)
virtual libMesh::UniquePtr< FEVariablesBase > build_fe_var(const std::vector< std::string > &var_names, const std::vector< VariableIndex > &var_indices, const std::set< libMesh::subdomain_id_type > &subdomain_ids)
Subclasses implement construction of the FEVariablesBase object using the var_names and var_indices...
static const std::set< libMesh::subdomain_id_type > * _subdomain_ids
Subdomain ids for the variable.
virtual std::string parse_fe_order_impl(const GetPot &input, const std::string &var_section)=0
static const std::vector< VariableIndex > * _var_indices
Variable component indices needed for FEVariableBase construction.
static std::string parse_fe_order(const std::string &name)
Abstract factory that provides availability of GetPot.

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