OpenFCST: The open-source Fuel Cell Simulation Toolbox
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
app_cathode.h
Go to the documentation of this file.
1 //---------------------------------------------------------------------------
2 //
3 // FCST: Fuel Cell Simulation Toolbox
4 //
5 // Copyright (C) 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: app_cathode.cc
11 // - Description:
12 // - Developers: M. Secanell
13 // - $Id: app_cathode.h 1417 2013-08-30 16:27:42Z secanell $
14 //
15 //---------------------------------------------------------------------------
16 
17 #ifndef _FUELCELL__APP_CATHODE__H
18 #define _FUELCELL__APP_CATHODE__H
19 
20 // Include deal.II classes
21 #include "base/parameter_handler.h"
22 #include "base/function_lib.h"
23 #include "base/function.h"
24 #include "base/quadrature_lib.h"
25 
26 #include "lac/block_vector.h"
27 #include "lac/full_matrix.h"
28 #include "lac/solver_cg.h"
29 #include "lac/solver_gmres.h"
30 #include "lac/precondition.h"
31 #include "lac/precondition_block.h"
32 #include "lac/block_matrix_array.h"
33 #include "lac/filtered_matrix.h"
34 #include "lac/sparse_ilu.h"
35 #include "lac/sparse_direct.h"
36 
37 #include "grid/grid_generator.h"
38 #include "grid/tria_accessor.h"
39 #include "grid/tria_iterator.h"
40 #include "grid/tria_boundary_lib.h"
41 
42 #include "fe/fe_values.h"
43 
44 #include "numerics/vector_tools.h"
45 #include "numerics/matrix_tools.h"
46 #include "numerics/error_estimator.h"
47 
48 #include "boost/shared_ptr.hpp"
49 
50 // Include appframe classes
51 #include "appframe/base.h"
57 
58 // Include FuelCell classes
59 #include "fcst_constants.h"
60 #include "system_management.h"
62 #include "solver_utils.h"
63 
64 #include "operating_conditions.h"
65 #include "geometries.h"
66 
67 #include "PureGas.h"
68 #include "BinaryDiffusion.h"
69 #include "platinum.h"
70 #include "nafion.h"
71 #include "carbon.h"
72 
73 #include "gas_diffusion_layer.h"
74 #include "micro_porous_layer.h"
75 #include "catalyst_layer.h"
76 
80 #include "reaction_source_terms.h"
81 
82 #include "linear_solvers.h"
83 
84 //Include STL
85 #include "fstream"
86 #include "iostream"
87 #include "sstream"
88 #include <algorithm>
89 
90 // Use namespace of deal.II
91 using namespace dealii;
92 
93 namespace FuelCell
94 {
95 
96  namespace Application
97  {
98  //---------------------------------------------------------------------------
99  //---------------------------------------------------------------------------
100  //---------------------------------------------------------------------------
187  template <int dim>
189  :
191  {
192  public:
193 
195 
196 
202  AppCathode ( boost::shared_ptr<AppFrame::ApplicationData> data =
203  boost::shared_ptr<AppFrame::ApplicationData> () );
204 
208  ~AppCathode();
215  virtual void declare_parameters ( ParameterHandler& param );
216 
223  virtual void set_parameters ( const std::vector<std::string>& name_dvar,
224  const std::vector<double>& value_dvar,
225  ParameterHandler& param );
226 
231  void _initialize ( ParameterHandler& param );
232 
236  virtual void initialize ( ParameterHandler& param );
237 
242  void initialize_grid ( ParameterHandler& param );
243 
248  void init_solution ( AppFrame::FEVector& src ) ;
249 
251 
253 
254 
268  virtual void cell_matrix ( MatrixVector& cell_matrices,
269  const typename DoFApplication<dim>::CellInfo& cell );
270 
271  virtual void bdry_matrix ( MatrixVector& bdry_matrices,
272  const typename DoFApplication<dim>::FaceInfo& bdry);
282  virtual void cell_residual ( AppFrame::FEVector& cell_vector,
283  const typename DoFApplication<dim>::CellInfo& cell );
284 
285  virtual void bdry_residual ( AppFrame::FEVector& bdry_vector,
286  const typename DoFApplication<dim>::FaceInfo& bdry);
287 
288 
295  virtual void dirichlet_bc ( std::map<unsigned int, double>& boundary_values ) const;
297 
298 
302  virtual void solve ( AppFrame::FEVector& start,
303  const AppFrame::FEVectors& rhs );
304 
308  virtual double estimate ( const AppFrame::FEVectors& sol );
309 
314  virtual double evaluate ( const AppFrame::FEVectors& src );
315 
320  virtual void data_out ( const std::string &basename,
321  const AppFrame::FEVectors &src );
322 
328  void parse_init_solution ( AppFrame::FEVector& src,
330  bool &good_solution );
331 
337  bool parse_init_solution_phi_s ( AppFrame::FEVector& src, double& V_cell );
338 
344  bool parse_init_solution_x_O2 ( AppFrame::FEVector& src, double& x_O2 );
345 
346 
348 
349 
352  virtual void cell_dresidual_dlambda ( std::vector<AppFrame::FEVector >& cell_vector,
353  const typename DoFApplication<dim>::CellInfo& cell,
354  std::vector<std::vector<double> >& src );
355 
362  virtual void check_responses();
363 
367  virtual void cell_responses ( std::vector<double>& resp,
368  const typename DoFApplication<dim>::CellInfo& info,
369  const AppFrame::FEVector& sol );
374  virtual void global_responses ( std::vector<double>& resp,
375  const AppFrame::FEVector& sol );
376 
382  virtual void cell_dresponses_dl ( std::vector<std::vector<double> >& cell_df_dl,
383  const typename DoFApplication<dim>::CellInfo& info,
384  const AppFrame::FEVector& sol );
385 
391  virtual void global_dresponses_dl ( std::vector<std::vector<double> >& df_dl,
392  const AppFrame::FEVector& sol );
398  virtual void cell_dresponses_du ( std::vector<AppFrame::FEVector >& cell_df_du,
399  const typename DoFApplication<dim>::CellInfo& info,
400  std::vector<std::vector<double> >& src );
401 
407  virtual void global_dresponses_du ( std::vector<AppFrame::FEVector >& df_du,
408  const AppFrame::FEVector& src );
410 
411 
412  protected:
414 
415 
423  void print_cell_matrix(FullMatrix<double> matrix, std::string filename = "cell_matrix.dat", bool exit = true) const
424  {
425  std::ofstream marc;
426  marc.open(filename);
427  matrix.print(marc);
428  marc.close();
429  if (exit)
430  {
431  deallog<<"Fins aviat..."<<std::endl;
432  abort();
433  }
434  }
435 
439  void print_cell_matrix(ParameterHandler param, std::string filename = "parameters_sample.prm", bool exit = true) const
440  {
441  std::ofstream marc(filename);
442  param.print_parameters(marc,
443  ParameterHandler::Text);
444  if (exit)
445  {
446  deallog<<"Fins aviat..."<<std::endl;
447  abort();
448  }
449 
450  }
451 
453 
459 
461 
462 
463  boost::shared_ptr< FuelCellShop::Geometry::GridBase<dim> > grid;
464 
468 
470 
471 
475 
480 
486 
488 
489 
492  boost::shared_ptr<FuelCellShop::Layer::GasDiffusionLayer<dim> > CGDL;
493 
497  boost::shared_ptr<FuelCellShop::Layer::MicroPorousLayer<dim> > CMPL;
498 
502  boost::shared_ptr<FuelCellShop::Layer::CatalystLayer<dim> > CCL;
503 
505 
507 
508 
530 
532 
534 
535 
541  std::vector<std::string> equation_names;
547  std::vector<std::string> component_names;
548 
550  std::vector<std::string> design_var;
551 
553  std::vector<double> design_var_value;
555 
556  };
557 
558  }
559 
560 }
561 
562 #endif //_FUELCELL__APP_CATHODE_H