OpenFCST: The open-source Fuel Cell Simulation Toolbox
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
base_layer.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 //
3 // FCST: Fuel Cell Simulation Toolbox
4 //
5 // Copyright (C) 2006-2013 by Energy Systems Design Laboratory, University of Alberta
6 //
7 // This software is distributed under the MIT License
8 // For more information, see the README file in /doc/LICENSE
9 //
10 // - Class: base_layer.h
11 // - Description: This is a base class for all available FCST layers
12 // - Developers: Marc Secanell Gallart, University of Alberta
13 // Madhur Bhaiya, University of Alberta
14 // Valentin N. Zingan, U of A
15 // - $Id: base_layer.h 2605 2014-08-15 03:36:44Z secanell $
16 //
17 // ----------------------------------------------------------------------------
18 
19 #ifndef _FUELCELLSHOP__BASE__LAYER_H
20 #define _FUELCELLSHOP__BASE__LAYER_H
21 
22 // Include deal.II classes
23 #include <deal.II/base/parameter_handler.h>
24 #include <deal.II/base/point.h>
25 #include <deal.II/base/function.h>
26 #include <deal.II/lac/vector.h>
27 #include <deal.II/fe/fe_values.h>
28 
29 //Include STL
30 #include <cmath>
31 #include <iostream>
32 
33 // Include OpenFCST routines:
36 #include <utils/fcst_utilities.h>
37 
38 using namespace dealii;
39 
40 namespace FuelCellShop
41 {
42 
43 
44  namespace Layer
45  {
57  template <int dim>
58  class BaseLayer : public Subscriptor
59  {
60  public:
62 
63 
67  virtual void set_derivative_flags(const std::vector<VariableNames>& flags)
68  {
69  this->derivative_flags = flags;
70  }
71 
76  void set_position(const std::vector<Point<dim> > &p)
77  {
78  point = p;
79  }
80 
81 
85  virtual void set_local_material_id(const unsigned int& id){
86 
87  AssertThrow(std::find(std::begin(material_ids), std::end(material_ids), id) != std::end(material_ids), ExcMessage("Material id not found in layer."));
88  local_material_id_ = id;
89  }
90 
97  inline void unset_local_material_id(){
98  //Ideally a material id will be 0 to 255, so we assume the max integer value will be an invalid key
99  local_material_id_ = std::numeric_limits<int>::max();
100  }
101 
113  virtual void set_constant_solution(const double& value, const VariableNames& name)
114  {
115  constant_solutions[name] = value;
116  }
117 
127  virtual void set_solution(const std::vector< SolutionVariable >&)
128  {
129  const std::type_info& info = typeid(*this);
130  FcstUtilities::log << "Pure function " << __FUNCTION__
131  << " called in Class "
132  << info.name() << std::endl;
133  }
134 
136 
138 
139 
144  bool belongs_to_material(const unsigned int material_id);
145 
146 
150  inline const std::string& name_layer() const
151  {
152  return name;
153  }
154 
177  virtual const std::type_info& get_base_type() const
178  {
179  const std::type_info& info = typeid(*this);
180  FcstUtilities::log << "Pure function " << __FUNCTION__
181  << " called in Class "
182  << info.name() << std::endl;
183  }
189  virtual void print_layer_properties() const;
190 
194  virtual bool test_layer()
195  {
196  const std::type_info& info = typeid(*this);
197  FcstUtilities::log << "Pure function " << __FUNCTION__
198  << " called in Class "
199  << info.name() << std::endl;
200 
201  return false;
202  }
203 
207  std::vector<unsigned int> get_material_ids()
208  {
209  return material_ids;
210  }
211 
215  inline unsigned int local_material_id() const
216  {
217  AssertThrow(std::find(std::begin(material_ids), std::end(material_ids), local_material_id_) != std::end(material_ids),
218  ExcMessage("The material id for layer " + name + " has not been set."));
219 
220  return local_material_id_;
221  }
222 
223  protected:
224 
226 
227 
233  {};
234 
238  BaseLayer(const std::string& name);
239 
243  virtual ~BaseLayer();
244 
248  virtual void declare_parameters (const std::string &object_name, ParameterHandler &param) const
249  {
250  param.enter_subsection("Fuel cell data");
251  {
252  param.enter_subsection(object_name);
253  {
254  param.declare_entry("Material id",
255  "1",
256  Patterns::List(Patterns::Integer(0, 255)),
257  "Id number used to identify this layer");
258  }
259  param.leave_subsection();
260  }
261  param.leave_subsection();
262  }
263 
269  virtual void declare_parameters (ParameterHandler &param) const
270  {
271  this->declare_parameters(this->name,param);
272  }
273 
284  virtual void set_parameters(const std::string &object_name,
285  const std::vector<std::string>& name_dvar,
286  const std::vector<double>& value_dvar,
287  ParameterHandler &param)
288  {
289  param.enter_subsection("Fuel cell data");
290  {
291  param.enter_subsection(object_name);
292  {
293  // ADD VARIABLES IF NEEDED
294  //param.set(name_var, value_param);
295  }
296  param.leave_subsection();
297  }
298  param.leave_subsection();
299  };
306  virtual void set_parameters(const std::vector<std::string>& name_dvar,
307  const std::vector<double>& value_dvar,
308  ParameterHandler &param)
309  {
310  param.enter_subsection("Fuel cell data");
311  {
312  param.enter_subsection(this->name);
313  {
314  // ADD VARIABLES IF NEEDED
315  //param.set(name_var, value_param);
316  }
317  param.leave_subsection();
318  }
319  param.leave_subsection();
320  };
321 
326  virtual void initialize (ParameterHandler &param);
327 
329 
331 
332 
336  const std::string name;
340  std::vector<unsigned int> material_ids;
344  std::vector<Point<dim> > point;
348  std::vector<VariableNames> derivative_flags;
352  std::map< VariableNames, double > constant_solutions;
353 
354 
355 
356  private:
363  unsigned int local_material_id_;
364 
366  };
367 
368  } // Layer
369 
370 } // FuelCellShop
371 
372  #endif // _FUELCELLSHOP__GENERIC__LAYER_H
const std::string & name_layer() const
Return the name of the layer.
Definition: base_layer.h:150
void set_position(const std::vector< Point< dim > > &p)
Member function used by some applications such as dummyGDL in order to know which value to return...
Definition: base_layer.h:76
virtual void declare_parameters(const std::string &object_name, ParameterHandler &param) const
Declare parameters for a parameter file.
Definition: base_layer.h:248
virtual void declare_parameters(ParameterHandler &param) const
Declare parameters for a parameter file.
Definition: base_layer.h:269
std::vector< Point< dim > > point
Coordinates of the point where we would like to compute the effective properties. ...
Definition: base_layer.h:344
VariableNames
The enumeration containing the names of some of the available FCST solution variables and their deriv...
Definition: system_management.h:63
std::vector< unsigned int > material_ids
List of material IDs that belong to the layer.
Definition: base_layer.h:340
virtual void set_constant_solution(const double &value, const VariableNames &name)
Set those solution variables which are constant in the particular application.
Definition: base_layer.h:113
const std::string name
Name of the layer.
Definition: base_layer.h:336
unsigned int local_material_id_
Local material ID to select the appropriate properties.
Definition: base_layer.h:363
virtual void set_parameters(const std::vector< std::string > &name_dvar, const std::vector< double > &value_dvar, ParameterHandler &param)
Set parameters in parameter file.
Definition: base_layer.h:306
std::map< VariableNames, double > constant_solutions
Map storing values of solution variables constant in a particular application.
Definition: base_layer.h:352
virtual const std::type_info & get_base_type() const
This member function return the name of the type of layer, i.e.
Definition: base_layer.h:177
FCSTLogStream log
Object used to output data to file and, if file attached recorded to a file as well.
virtual void set_parameters(const std::string &object_name, const std::vector< std::string > &name_dvar, const std::vector< double > &value_dvar, ParameterHandler &param)
Member function used to change the values in the parameter file for a given list of parameters...
Definition: base_layer.h:284
virtual void set_solution(const std::vector< SolutionVariable > &)
If the effective properties in the layer depend on the solution, the solution for a given cell should...
Definition: base_layer.h:127
virtual void set_local_material_id(const unsigned int &id)
Function for setting local material id, for unit testing purposes.
Definition: base_layer.h:85
virtual void set_derivative_flags(const std::vector< VariableNames > &flags)
Set the variables for which you would like to compute the derivatives.
Definition: base_layer.h:67
virtual bool test_layer()
This virtual class should be used for any derived class to be able to test the functionality of the c...
Definition: base_layer.h:194
BaseLayer()
Constructor.
Definition: base_layer.h:232
std::vector< unsigned int > get_material_ids()
Return the local material id of the layer.
Definition: base_layer.h:207
unsigned int local_material_id() const
Return the local material id of the layer, performs a check.
Definition: base_layer.h:215
std::vector< VariableNames > derivative_flags
Flags for derivatives: These flags are used to request derivatives.
Definition: base_layer.h:348
Virtual class used to characterize a generic layer interface.
Definition: base_layer.h:58
void unset_local_material_id()
Function for unsetting local material id, so that it isn&#39;t incorrectly used later Once the key is &quot;un...
Definition: base_layer.h:97