OpenFCST: The open-source Fuel Cell Simulation Toolbox
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
initial_and_boundary_data.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: initial_and_boundary_data.h
11 // - Description: This namespace contains data and methods
12 // that handle initial and boundary data of
13 // a problem at hand
14 // - Developers: Valentin N. Zingan, University of Alberta
15 // M. Secanell (documentation), UofA
16 // - $Id: initial_and_boundary_data.h 2605 2014-08-15 03:36:44Z secanell $
17 //
18 // ----------------------------------------------------------------------------
19 
20 #ifndef _FCST_FUELCELL_INITIAL_AND_BOUNDARY_DATA_H_
21 #define _FCST_FUELCELL_INITIAL_AND_BOUNDARY_DATA_H_
22 
23 #define _IS_NOT_CONSTANT_ 1.e300
24 //-- dealII
25 #include <deal.II/base/point.h>
26 #include <deal.II/base/function.h>
27 #include <deal.II/lac/vector.h>
28 #include <deal.II/dofs/function_map.h>
29 #include <deal.II/fe/mapping_q1.h>
30 #include <deal.II/fe/mapping_q.h>
31 #include <deal.II/numerics/vector_tools.h>
32 #include <deal.II/numerics/matrix_tools.h>
33 
34 //-- OpenFCST
37 #include <solvers/solver_utils.h>
38 
39 using namespace dealii;
40 using namespace FuelCell::ApplicationCore;
41 
74 typedef std::map< std::string , std::map<types::material_id, double> > component_materialID_value_map;
75 
85 typedef std::map< std::string , std::map<types::boundary_id, double> > component_boundaryID_value_map;
86 
95 namespace FuelCell
96 {
97  namespace InitialAndBoundaryData
98  {
99 
104  template<typename COMPONENT_xxxID_VALUE_MAP>
105  const bool check(const std::vector< COMPONENT_xxxID_VALUE_MAP >& maps)
106  {
107  // --- types info ---
108 
109  const std::type_info& material = typeid(component_materialID_value_map);
110  const std::type_info& boundary = typeid(component_boundaryID_value_map);
111 
112  const std::type_info& info = typeid(COMPONENT_xxxID_VALUE_MAP);
113 
114  // --- checkings ---
115 
116  // --- 1 ---
117 
118  if( maps.size() == 0 )
119  {
120  FcstUtilities::log << "The argument is empty" << std::endl;
121  return false;
122  }
123 
124  // --- 2 ---
125 
126  for(unsigned int i = 0; i < maps.size(); ++i)
127  if( maps[i].empty() )
128  {
129  FcstUtilities::log << "Outer map/maps of the argument is/are empty" << std::endl;
130  return false;
131  }
132 
133  // --- 3 ---
134 
135  for(unsigned int i = 0; i < maps.size(); ++i)
136  for(typename COMPONENT_xxxID_VALUE_MAP::const_iterator iter = maps[i].begin();
137  iter != maps[i].end();
138  ++iter)
139  if( iter->second.empty() )
140  {
141  FcstUtilities::log << "Inner map/maps of the argument is/are empty" << std::endl;
142  return false;
143  }
144 
145  // --- 4 ---
146 
147  if( info == material )
148  for(unsigned int i = 0; i < maps.size(); ++i)
149  for(typename COMPONENT_xxxID_VALUE_MAP::const_iterator iter = maps[i].begin();
150  iter != maps[i].end();
151  ++iter)
152  if( iter->second.find(numbers::invalid_material_id) != iter->second.end() )
153  {
154  FcstUtilities::log << "Invalid material id/ids of the argument" << std::endl;
155  return false;
156  }
157 
158  if( info == boundary )
159  for(unsigned int i = 0; i < maps.size(); ++i)
160  for(typename COMPONENT_xxxID_VALUE_MAP::const_iterator iter = maps[i].begin();
161  iter != maps[i].end();
162  ++iter)
163  if( iter->second.find(numbers::invalid_boundary_id) != iter->second.end() )
164  {
165  FcstUtilities::log << "Invalid boundary id/ids of the argument" << std::endl;
166  return false;
167  }
168 
169  return true;
170  }
171 
189  template<typename VECTOR, typename DH>
192  const DH& dof,
193  const FuelCell::SystemManagement& system_management,
194  const std::vector< component_materialID_value_map >& maps)
195  {
196  // --- checking ---
197 
198  AssertThrow( FuelCell::InitialAndBoundaryData::check< component_materialID_value_map >(maps),
199  ExcMessage("The last argument in the FuelCell::InitialAndBoundaryData::make_piece_wise_constant_initial_data function "
200  "is wrong : check the previous message") );
201 
202  // --- main ---
203 
204  const unsigned int n_components = system_management.get_number_of_solution_names();
205  AssertThrow( n_components == dof.get_fe().n_components(),
206  ExcDimensionMismatch( n_components , dof.get_fe().n_components() ) );
207 
208  for(unsigned int i = 0; i < maps.size(); ++i)
209  for(component_materialID_value_map::const_iterator iter = maps[i].begin(); iter != maps[i].end(); ++iter)
210  {
211  std::map<types::material_id, double> tmp = iter->second;
212 
213  for(std::map<types::material_id, double>::const_iterator iter2 = tmp.begin(); iter2 != tmp.end(); ++iter2)
214  {
215  if( iter2->second != _IS_NOT_CONSTANT_ )
216  {
217  std::map< types::material_id, const Function<DH::space_dimension>* > function_map;
218 
219  const ConstantFunction<DH::space_dimension> constant_function(iter2->second, n_components);
220  function_map[iter2->first] = &constant_function;
221 
222  std::vector<bool> component_mask(n_components, false);
223  component_mask[system_management.solution_name_to_index(iter->first)] = true;
224 
225  VectorTools::interpolate_based_on_material_id( mapping,
226  dof,
227  function_map,
228  dst,
229  component_mask );
230  }
231  }
232  }
233  }
246  template<typename DH>
247  void make_constant_DirichletBC_values(std::map<unsigned int, double>& dst,
249  const DH& dof,
250  const FuelCell::SystemManagement& system_management,
251  const std::vector< component_boundaryID_value_map >& maps)
252  {
253  // --- checking ---
254 
255  AssertThrow( FuelCell::InitialAndBoundaryData::check< component_boundaryID_value_map >(maps),
256  ExcMessage("The last argument in the FuelCell::InitialAndBoundaryData::make_constant_DirichletBC_values function "
257  "is wrong : check the previous message") );
258 
259  // --- main ---
260 
261  const unsigned int n_components = system_management.get_number_of_solution_names();
262  AssertThrow( n_components == dof.get_fe().n_components(),
263  ExcDimensionMismatch( n_components , dof.get_fe().n_components() ) );
264 
265  for(unsigned int i = 0; i < maps.size(); ++i)
266  for(component_boundaryID_value_map::const_iterator iter = maps[i].begin(); iter != maps[i].end(); ++iter)
267  {
268  std::map<types::boundary_id, double> tmp = iter->second;
269 
270  for(std::map<types::boundary_id, double>::const_iterator iter2 = tmp.begin(); iter2 != tmp.end(); ++iter2)
271  {
272  typename FunctionMap<DH::space_dimension>::type function_map;
273 
274  const ConstantFunction<DH::space_dimension> constant_function(iter2->second, n_components);
275  function_map[iter2->first] = &constant_function;
276 
277 
278  std::vector<bool> component_mask(n_components, false);
279  component_mask[system_management.solution_name_to_index(iter->first)] = true;
280 
281  VectorTools::interpolate_boundary_values( mapping,
282  dof,
283  function_map,
284  dst,
285  component_mask );
286  }
287  }
288  }
289 
307  template<typename VECTOR, typename DH>
310  const DH& dof,
311  const FuelCell::SystemManagement& system_management,
312  const std::vector< component_boundaryID_value_map >& maps)
313  {
314  // --- checking ---
315  /*
316  AssertThrow( FuelCell::InitialAndBoundaryData::check< component_boundaryID_value_map >(maps),
317  ExcMessage("The last argument in the FuelCell::InitialAndBoundaryData::apply_piece_wise_constant_DirichletBCs function "
318  "is wrong : check the previous message") );
319  */
320  // --- main ---
321 
322  const unsigned int n_components = system_management.get_number_of_solution_names();
323  AssertThrow( n_components == dof.get_fe().n_components(),
324  ExcDimensionMismatch( n_components , dof.get_fe().n_components() ) );
325 
326  for(unsigned int i = 0; i < maps.size(); ++i)
327  for(component_boundaryID_value_map::const_iterator iter = maps[i].begin(); iter != maps[i].end(); ++iter)
328  {
329  std::map<types::boundary_id, double> tmp = iter->second;
330 
331  for(std::map<types::boundary_id, double>::const_iterator iter2 = tmp.begin(); iter2 != tmp.end(); ++iter2)
332  {
333  if( iter2->second != _IS_NOT_CONSTANT_ )
334  {
335  typename FunctionMap<DH::space_dimension>::type function_map;
336 
337  const ConstantFunction<DH::space_dimension> constant_function(iter2->second, n_components);
338  function_map[iter2->first] = &constant_function;
339 
340  std::vector<bool> component_mask(n_components, false);
341  component_mask[system_management.solution_name_to_index(iter->first)] = true;
342 
343  std::map<unsigned int, double> boundary_values;
344 
345  VectorTools::interpolate_boundary_values( mapping,
346  dof,
347  function_map,
348  boundary_values,
349  component_mask );
350 
351  for(std::map<unsigned int, double>::const_iterator iter3 = boundary_values.begin();
352  iter3 != boundary_values.end(); ++iter3)
353  {
354  dst(iter3->first) = iter3->second;
355  }
356  }
357  }
358  }
359  }
360 
364  template<typename DH>
365  void make_zero_boundary_values(std::map<unsigned int, double>& dst,
367  const DH& dof,
368  const FuelCell::SystemManagement& system_management,
369  const std::vector< component_boundaryID_value_map >& maps)
370  {
371  // --- checking ---
372  /*
373  AssertThrow( FuelCell::InitialAndBoundaryData::check< component_boundaryID_value_map >(maps),
374  ExcMessage("The last argument in the FuelCell::InitialAndBoundaryData::make_zero_boundary_values function "
375  "is wrong : check the previous message") );
376  */
377  // --- main ---
378 
379  const unsigned int n_components = system_management.get_number_of_solution_names();
380  AssertThrow( n_components == dof.get_fe().n_components(),
381  ExcDimensionMismatch( n_components , dof.get_fe().n_components() ) );
382 
383  for(unsigned int i = 0; i < maps.size(); ++i)
384  for(component_boundaryID_value_map::const_iterator iter = maps[i].begin(); iter != maps[i].end(); ++iter)
385  {
386  std::map<types::boundary_id, double> tmp = iter->second;
387 
388  for(std::map<types::boundary_id, double>::const_iterator iter2 = tmp.begin(); iter2 != tmp.end(); ++iter2)
389  {
390  typename FunctionMap<DH::space_dimension>::type function_map;
391 
392  const ZeroFunction<DH::space_dimension> zero_function(n_components);
393  function_map[iter2->first] = &zero_function;
394 
395  std::vector<bool> component_mask(n_components, false);
396  component_mask[system_management.solution_name_to_index(iter->first)] = true;
397 
398  VectorTools::interpolate_boundary_values( mapping,
399  dof,
400  function_map,
401  dst,
402  component_mask );
403  }
404  }
405  }
406 
416  template<typename MATRIX, typename VECTOR, typename DH>
418  VECTOR& solution,
419  VECTOR& rhs,
421  const DH& dof,
422  const FuelCell::SystemManagement& system_management,
423  const std::vector< component_boundaryID_value_map >& maps,
424  const bool& repair_diagonal = false)
425  {
426  if( repair_diagonal )
427  {
429  solution,
430  rhs );
431  }
432 
433  std::map<unsigned int, double> boundary_values;
434  FuelCell::InitialAndBoundaryData::make_zero_boundary_values<DH>( boundary_values,
435  mapping,
436  dof,
437  system_management,
438  maps );
439  MatrixTools::apply_boundary_values( boundary_values,
440  matrix,
441  solution,
442  rhs );
443  }
444 
452  template<int dim>
453  class InitialOrBoundaryDataBase : public Function<dim>
454  {
455  public:
456 
458 
459 
465  virtual double value(const Point<dim>& point,
466  const unsigned int no_component = 0) const;
467 
469 
470  protected:
471 
473 
474 
482  InitialOrBoundaryDataBase(boost::shared_ptr<ApplicationData> data,
483  const unsigned int n_components = 1);
484 
489 
491 
493 
494 
500  virtual double math_expression(const Point<dim>& point,
501  const unsigned int no_component = 0) const;
502 
504 
506 
507 
512  void print_caller_name(const std::string& caller_name) const;
513 
515 
517  // DATA //
519 
521 
522 
528  boost::shared_ptr<ApplicationData> data;
529 
531 
532  };
533 
534  } // InitialAndBoundaryData
535 
536 } // FuelCell
537 
538 #endif
Definition: dof_application.h:68
const bool check(const std::vector< COMPONENT_xxxID_VALUE_MAP > &maps)
This function does some checkings on its argument maps.
Definition: initial_and_boundary_data.h:105
boost::shared_ptr< ApplicationData > data
Data of the application serves to exchange the information between YourApplication&lt;dim&gt; and children ...
Definition: initial_and_boundary_data.h:528
void make_constant_DirichletBC_values(std::map< unsigned int, double > &dst, const Mapping< DH::dimension, DH::space_dimension > &mapping, const DH &dof, const FuelCell::SystemManagement &system_management, const std::vector< component_boundaryID_value_map > &maps)
Definition: initial_and_boundary_data.h:247
std::map< std::string, std::map< types::material_id, double > > component_materialID_value_map
The typedef for the std::map that reflects the following structure:
Definition: initial_and_boundary_data.h:74
std::map< std::string, std::map< types::boundary_id, double > > component_boundaryID_value_map
The typedef for the std::map that reflects the following structure:
Definition: initial_and_boundary_data.h:85
#define _IS_NOT_CONSTANT_
Definition: initial_and_boundary_data.h:23
void apply_piece_wise_constant_DirichletBCs(VECTOR &dst, const Mapping< DH::dimension, DH::space_dimension > &mapping, const DH &dof, const FuelCell::SystemManagement &system_management, const std::vector< component_boundaryID_value_map > &maps)
This function applies piece wise constant Dirichlet BCs.
Definition: initial_and_boundary_data.h:308
void make_zero_boundary_values(std::map< unsigned int, double > &dst, const Mapping< DH::dimension, DH::space_dimension > &mapping, const DH &dof, const FuelCell::SystemManagement &system_management, const std::vector< component_boundaryID_value_map > &maps)
This function makes zero boundary values.
Definition: initial_and_boundary_data.h:365
This class is a means to make variable initial or boundary data.
Definition: initial_and_boundary_data.h:453
FCSTLogStream log
Object used to output data to file and, if file attached recorded to a file as well.
const unsigned int solution_name_to_index(const std::string &name) const
This function returns the index of a user defined solution variable with name name stored in solution...
const unsigned int & get_number_of_solution_names() const
This function returns n_solution_names.
Definition: system_management.h:506
IMPORTANT: Add all new solution variables and equations here !
Definition: system_management.h:300
void make_piece_wise_constant_initial_data(VECTOR &dst, const Mapping< DH::dimension, DH::space_dimension > &mapping, const DH &dof, const FuelCell::SystemManagement &system_management, const std::vector< component_materialID_value_map > &maps)
This function makes piece wise constant initial data.
Definition: initial_and_boundary_data.h:190
void repair_diagonal(BlockSparseMatrix< double > &A)
This member function is used to make sure that the BlockSpareMatrix has no zeros in the diagonal...
void apply_zero_boundary_values_to_linear_system(MATRIX &matrix, VECTOR &solution, VECTOR &rhs, const Mapping< DH::dimension, DH::space_dimension > &mapping, const DH &dof, const FuelCell::SystemManagement &system_management, const std::vector< component_boundaryID_value_map > &maps, const bool &repair_diagonal=false)
This function applies zero boundary values to the linear system of equations.
Definition: initial_and_boundary_data.h:417