OpenFCST: The open-source Fuel Cell Simulation Toolbox
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
micro_scale_base.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 //
3 // FCST: Fuel Cell Simulation Toolbox
4 //
5 // Copyright (C) 2006-2014 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: MicroScaleBase
11 // - Description: Base class for micro scale objects
12 // - Developers: Philip Wardlaw, University of Alberta
13 // - $Id: micro_scale_base.h 2605 2014-08-15 03:36:44Z secanell $
14 //
15 // ----------------------------------------------------------------------------
16 
17 #ifndef _FUELCELLSHOP__LAYER__MICROSCALE_BASE_H
18 #define _FUELCELLSHOP__LAYER__MICROSCALE_BASE_H
19 
20 
21 // The following definitions are necessary for compilation
22 // MultiScaleCL must be included in this header
23 // MultiScaleCL makes references to this class
24 // This class must be declared before we read MultiScaleCL file
25 namespace FuelCellShop
26 {
27  namespace MicroScale
28  {
29  class MicroScaleBase;
30  }
31  namespace Layer
32  {
33  template <int dim>
34  class MultiScaleCL;
35  }
36 }
37 
38 
39 
40 
41 //FCST classes and utils
42 #include <fcst_constants.h>
43 #include <fcst_utilities.h>
44 #include <multi_scale_CL.h>
45 #include <logging.h>
46 
47 //deal.ii classes and utils
48 #include <base/utilities.h>
49 #include <base/parameter_handler.h>
50 
51 //STL containers, functions, streams
52 #include <vector>
53 #include <map>
54 #include <string.h>
55 #include <cmath>
56 #include <iostream>
57 
58 //Boost shared pointer
59 #include <boost/shared_ptr.hpp>
60 
61 
62 
63 namespace FuelCellShop
64 {
65  namespace MicroScale
66  {
135  {
136 
137  public:
138 
140  virtual ~MicroScaleBase() {};
141 
142 
143 
145 
146 
186  static void declare_MicroScale_parameters (ParameterHandler &param)
187  {
188  param.enter_subsection("MicroScale");
189  std::string micro_type_list;
190 
191  for (typename FuelCellShop::MicroScale::MicroScaleBase::_mapFactory::iterator iterator = FuelCellShop::MicroScale::MicroScaleBase::get_mapFactory()->begin();
192  iterator != FuelCellShop::MicroScale::MicroScaleBase::get_mapFactory()->end(); iterator++)
193  {
194  iterator->second->declare_parameters(param);
195  micro_type_list += iterator->first +"|";
196  }
197 
198  micro_type_list = micro_type_list.substr(0, micro_type_list.size()-1);//Trim string 1 '|' char
199  param.declare_entry("Microscale type", "IonomerAgglomerateAnalytical", Patterns::Selection(micro_type_list));
200  param.leave_subsection();
201 
202  }
203 
219  static boost::shared_ptr<FuelCellShop::MicroScale::MicroScaleBase > create_MicroStructure (ParameterHandler &param,
221  {
222  boost::shared_ptr<FuelCellShop::MicroScale::MicroScaleBase > pointer;
223 
224  param.enter_subsection("MicroScale");
225  std::string concrete_name = param.get("Microscale type");
226 
227 
228  typename FuelCellShop::MicroScale::MicroScaleBase::_mapFactory::iterator iterator = FuelCellShop::MicroScale::MicroScaleBase::get_mapFactory()->find(concrete_name);
229 
231  {
232  if (iterator->second)
233  {
234  pointer = iterator->second->create_replica();
235  }
236  else
237  {
238  FcstUtilities::log<<"Pointer not initialized"<<std::endl;
239  abort();
240  }
241  }
242  else
243  {
244  FcstUtilities::log<<"Concrete name in FuelCellShop::MicroScale::MicroScaleBase::create_MicroStructure does not exist"<<std::endl;
245  abort();
246  }
247 
248  pointer->set_layer(layer);
249  pointer->initialize(param);
250  pointer->set_structure();
251  param.leave_subsection();
252  return pointer;
253  }
255 
257 
258 
268  virtual void set_solution(const std::map<VariableNames,SolutionVariable>&,const VariableNames&, const int&) = 0;
270 
278  virtual SolutionMap compute_current () = 0;
279 
291  virtual std::vector<double> compute_derivative_current ()
292  {
293  Assert(false, ExcPureFunctionCalled());
294  return std::vector<double>(3, 0.0);
295  }
296 
305  virtual bool has_derivatives() = 0;
306 
310  virtual std::string get_name() = 0;
311 
315  virtual void print_properties() = 0;
316 
317 
323  virtual double aux_volume_fraction() = 0;
324 
325 
326  /*
327  * MicroScale will deep create new instances of pointers (kinetics, materials), to prevent race condition during parallel execution.
328  */
329  virtual void make_thread_safe(ParameterHandler &param, unsigned int thread_index) = 0;
330 
331 
332  protected:
333 
334  /*
335  * Protected member function, for storing address to catalyst layer which
336  * constructed this MicroScale object.
337  */
339 
340  if(_layer!= NULL){
341  layer = _layer;
342  }
343  else
344  {
345  std::string msg = "MultiScaleCl pointer passed to MicroScaleBase is NULL!";
346  throw std::runtime_error(msg);
347  }
348  }
349 
350  /*
351  * Protected member pointer, for storing address to catalyst layer which
352  * constructed this MicroScale object.
353  */
355 
356  /*
357  * Protected pure virtual member function for declaring parameters, must be implemented
358  * by all children. Parameter structure is hierarchical, therefore children
359  * should call their parent's declare parameter function from their own declare
360  * parameter function.
361  */
362  virtual void declare_parameters (ParameterHandler &param) const =0;
363 
364  /*
365  * Protected pure virtual member function for initializing parameters, must be implemented
366  * by all children. Parameter structure is hierarchical, therefore children
367  * should call their parent's initialize function from their own initialize function.
368  */
369  virtual void initialize (ParameterHandler &param) =0;
370 
371 
372  /*
373  * Constructor
374  */
376 
377 
378  /*
379  * Protected member function for setting up MicroScale structure after object
380  * initialization.
381  *
382  * Responsible for pulling structural properties from catalyst layer.
383  *
384  * Responsible for setting up pointer to materials and kinetics.
385  *
386  */
387  virtual void set_structure () = 0;
388 
390 
391 
394  typedef std::map< std::string, MicroScaleBase* > _mapFactory;
396 
397 
399 
400 
406  {
407  static _mapFactory mapFactory;
408  return &mapFactory;
409  }
411 
413 
414 
419  virtual boost::shared_ptr<MicroScaleBase> create_replica () = 0;
421 
422  };
423  }
424 }
425 
426 #endif
virtual void print_properties()=0
Print out key micro-structural dimensions, defined by child.
virtual void declare_parameters(ParameterHandler &param) const =0
virtual void make_thread_safe(ParameterHandler &param, unsigned int thread_index)=0
std::map< std::string, MicroScaleBase * > _mapFactory
This object is used to store all objects of type MicroScaleBase.
Definition: micro_scale_base.h:394
VariableNames
The enumeration containing the names of some of the available FCST solution variables and their deriv...
Definition: system_management.h:62
Convenient storage object for SolutionVariables.
Definition: fcst_variables.h:447
static _mapFactory * get_mapFactory()
This member function is used to create an object of type MicroScaleBase.
Definition: micro_scale_base.h:405
virtual void set_solution(const std::map< VariableNames, SolutionVariable > &, const VariableNames &, const int &)=0
Function for setting the solution map(reactant concentration, phi_s, phi_m, etc.).
MicroScaleBase()
Definition: micro_scale_base.h:375
FuelCellShop::Layer::MultiScaleCL< deal_II_dimension > * layer
Definition: micro_scale_base.h:354
virtual bool has_derivatives()=0
Returns true if the class instance can calculate current density derivatives.
FCSTLogStream log
Object used to output data to file and, if file attached recorded to a file as well.
virtual boost::shared_ptr< MicroScaleBase > create_replica()=0
This member function is used to create an object of MicroScaleBase.
virtual void initialize(ParameterHandler &param)=0
void set_layer(FuelCellShop::Layer::MultiScaleCL< deal_II_dimension > *_layer)
Definition: micro_scale_base.h:338
virtual ~MicroScaleBase()
Destructor.
Definition: micro_scale_base.h:140
static boost::shared_ptr< FuelCellShop::MicroScale::MicroScaleBase > create_MicroStructure(ParameterHandler &param, FuelCellShop::Layer::MultiScaleCL< deal_II_dimension > *layer)
Function used to select the appropriate MicroScale type as specified in the ParameterHandler under li...
Definition: micro_scale_base.h:219
The base class for micro scale objects in OpenFCST.
Definition: micro_scale_base.h:134
virtual std::string get_name()=0
Return name of class instance, i.e.
virtual double aux_volume_fraction()=0
MicroScale object may have extra contribution to volume of layer, e.g.
virtual std::vector< double > compute_derivative_current()
Function to compute the derivative of the current density at the local operating conditions.
Definition: micro_scale_base.h:291
virtual SolutionMap compute_current()=0
Function used to compute the current density produced by the micro structure.
static void declare_MicroScale_parameters(ParameterHandler &param)
Function used to declare all the data necessary in the parameter files for all MicroScale children...
Definition: micro_scale_base.h:186