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 
25 #include <base/point.h>
26 #include <base/function.h>
27 
28 #include <lac/vector.h>
29 #include <lac/block_vector.h>
30 #include <lac/block_sparse_matrix.h>
31 
32 #include <dofs/function_map.h>
33 
34 #include <fe/mapping_q1.h>
35 #include <fe/mapping_q.h>
36 
37 #include <numerics/vector_tools.h>
38 #include <numerics/matrix_tools.h>
39 
40 #include "application_data.h"
41 #include "system_management.h"
42 #include "solver_utils.h"
43 
44 using namespace dealii;
45 using namespace FuelCell::ApplicationCore;
46 
79 typedef std::map< std::string , std::map<types::material_id, double> > component_materialID_value_map;
80 
90 typedef std::map< std::string , std::map<types::boundary_id, double> > component_boundaryID_value_map;
91 
100 namespace FuelCell
101 {
102  namespace InitialAndBoundaryData
103  {
104 
109  template<typename COMPONENT_xxxID_VALUE_MAP>
110  const bool check(const std::vector< COMPONENT_xxxID_VALUE_MAP >& maps)
111  {
112  // --- types info ---
113 
114  const std::type_info& material = typeid(component_materialID_value_map);
115  const std::type_info& boundary = typeid(component_boundaryID_value_map);
116 
117  const std::type_info& info = typeid(COMPONENT_xxxID_VALUE_MAP);
118 
119  // --- checkings ---
120 
121  // --- 1 ---
122 
123  if( maps.size() == 0 )
124  {
125  FcstUtilities::log << "The argument is empty" << std::endl;
126  return false;
127  }
128 
129  // --- 2 ---
130 
131  for(unsigned int i = 0; i < maps.size(); ++i)
132  if( maps[i].empty() )
133  {
134  FcstUtilities::log << "Outer map/maps of the argument is/are empty" << std::endl;
135  return false;
136  }
137 
138  // --- 3 ---
139 
140  for(unsigned int i = 0; i < maps.size(); ++i)
141  for(typename COMPONENT_xxxID_VALUE_MAP::const_iterator iter = maps[i].begin();
142  iter != maps[i].end();
143  ++iter)
144  if( iter->second.empty() )
145  {
146  FcstUtilities::log << "Inner map/maps of the argument is/are empty" << std::endl;
147  return false;
148  }
149 
150  // --- 4 ---
151 
152  if( info == material )
153  for(unsigned int i = 0; i < maps.size(); ++i)
154  for(typename COMPONENT_xxxID_VALUE_MAP::const_iterator iter = maps[i].begin();
155  iter != maps[i].end();
156  ++iter)
157  if( iter->second.find(numbers::invalid_material_id) != iter->second.end() )
158  {
159  FcstUtilities::log << "Invalid material id/ids of the argument" << std::endl;
160  return false;
161  }
162 
163  if( info == boundary )
164  for(unsigned int i = 0; i < maps.size(); ++i)
165  for(typename COMPONENT_xxxID_VALUE_MAP::const_iterator iter = maps[i].begin();
166  iter != maps[i].end();
167  ++iter)
168  if( iter->second.find(numbers::invalid_boundary_id) != iter->second.end() )
169  {
170  FcstUtilities::log << "Invalid boundary id/ids of the argument" << std::endl;
171  return false;
172  }
173 
174  return true;
175  }
176 
194  template<typename VECTOR, typename DH>
197  const DH& dof,
198  const FuelCell::SystemManagement& system_management,
199  const std::vector< component_materialID_value_map >& maps)
200  {
201  // --- checking ---
202 
203  AssertThrow( FuelCell::InitialAndBoundaryData::check< component_materialID_value_map >(maps),
204  ExcMessage("The last argument in the FuelCell::InitialAndBoundaryData::make_piece_wise_constant_initial_data function "
205  "is wrong : check the previous message") );
206 
207  // --- main ---
208 
209  const unsigned int n_components = system_management.get_number_of_solution_names();
210  AssertThrow( n_components == dof.get_fe().n_components(),
211  ExcDimensionMismatch( n_components , dof.get_fe().n_components() ) );
212 
213  for(unsigned int i = 0; i < maps.size(); ++i)
214  for(component_materialID_value_map::const_iterator iter = maps[i].begin(); iter != maps[i].end(); ++iter)
215  {
216  std::map<types::material_id, double> tmp = iter->second;
217 
218  for(std::map<types::material_id, double>::const_iterator iter2 = tmp.begin(); iter2 != tmp.end(); ++iter2)
219  {
220  if( iter2->second != _IS_NOT_CONSTANT_ )
221  {
222  std::map< types::material_id, const Function<DH::space_dimension>* > function_map;
223 
224  const ConstantFunction<DH::space_dimension> constant_function(iter2->second, n_components);
225  function_map[iter2->first] = &constant_function;
226 
227  std::vector<bool> component_mask(n_components, false);
228  component_mask[system_management.solution_name_to_index(iter->first)] = true;
229 
230  VectorTools::interpolate_based_on_material_id( mapping,
231  dof,
232  function_map,
233  dst,
234  component_mask );
235  }
236  }
237  }
238  }
251  template<typename DH>
252  void make_constant_DirichletBC_values(std::map<unsigned int, double>& dst,
254  const DH& dof,
255  const FuelCell::SystemManagement& system_management,
256  const std::vector< component_boundaryID_value_map >& maps)
257  {
258  // --- checking ---
259 
260  AssertThrow( FuelCell::InitialAndBoundaryData::check< component_boundaryID_value_map >(maps),
261  ExcMessage("The last argument in the FuelCell::InitialAndBoundaryData::make_constant_DirichletBC_values function "
262  "is wrong : check the previous message") );
263 
264  // --- main ---
265 
266  const unsigned int n_components = system_management.get_number_of_solution_names();
267  AssertThrow( n_components == dof.get_fe().n_components(),
268  ExcDimensionMismatch( n_components , dof.get_fe().n_components() ) );
269 
270  for(unsigned int i = 0; i < maps.size(); ++i)
271  for(component_boundaryID_value_map::const_iterator iter = maps[i].begin(); iter != maps[i].end(); ++iter)
272  {
273  std::map<types::boundary_id, double> tmp = iter->second;
274 
275  for(std::map<types::boundary_id, double>::const_iterator iter2 = tmp.begin(); iter2 != tmp.end(); ++iter2)
276  {
277  typename FunctionMap<DH::space_dimension>::type function_map;
278 
279  const ConstantFunction<DH::space_dimension> constant_function(iter2->second, n_components);
280  function_map[iter2->first] = &constant_function;
281 
282 
283  std::vector<bool> component_mask(n_components, false);
284  component_mask[system_management.solution_name_to_index(iter->first)] = true;
285 
286  VectorTools::interpolate_boundary_values( mapping,
287  dof,
288  function_map,
289  dst,
290  component_mask );
291  }
292  }
293  }
294 
312  template<typename VECTOR, typename DH>
315  const DH& dof,
316  const FuelCell::SystemManagement& system_management,
317  const std::vector< component_boundaryID_value_map >& maps)
318  {
319  // --- checking ---
320 
321  AssertThrow( FuelCell::InitialAndBoundaryData::check< component_boundaryID_value_map >(maps),
322  ExcMessage("The last argument in the FuelCell::InitialAndBoundaryData::apply_piece_wise_constant_DirichletBCs function "
323  "is wrong : check the previous message") );
324 
325  // --- main ---
326 
327  const unsigned int n_components = system_management.get_number_of_solution_names();
328  AssertThrow( n_components == dof.get_fe().n_components(),
329  ExcDimensionMismatch( n_components , dof.get_fe().n_components() ) );
330 
331  for(unsigned int i = 0; i < maps.size(); ++i)
332  for(component_boundaryID_value_map::const_iterator iter = maps[i].begin(); iter != maps[i].end(); ++iter)
333  {
334  std::map<types::boundary_id, double> tmp = iter->second;
335 
336  for(std::map<types::boundary_id, double>::const_iterator iter2 = tmp.begin(); iter2 != tmp.end(); ++iter2)
337  {
338  if( iter2->second != _IS_NOT_CONSTANT_ )
339  {
340  typename FunctionMap<DH::space_dimension>::type function_map;
341 
342  const ConstantFunction<DH::space_dimension> constant_function(iter2->second, n_components);
343  function_map[iter2->first] = &constant_function;
344 
345  std::vector<bool> component_mask(n_components, false);
346  component_mask[system_management.solution_name_to_index(iter->first)] = true;
347 
348  std::map<unsigned int, double> boundary_values;
349 
350  VectorTools::interpolate_boundary_values( mapping,
351  dof,
352  function_map,
353  boundary_values,
354  component_mask );
355 
356  for(std::map<unsigned int, double>::const_iterator iter3 = boundary_values.begin();
357  iter3 != boundary_values.end(); ++iter3)
358  {
359  dst(iter3->first) = iter3->second;
360  }
361  }
362  }
363  }
364  }
365 
369  template<typename DH>
370  void make_zero_boundary_values(std::map<unsigned int, double>& dst,
372  const DH& dof,
373  const FuelCell::SystemManagement& system_management,
374  const std::vector< component_boundaryID_value_map >& maps)
375  {
376  // --- checking ---
377 
378  AssertThrow( FuelCell::InitialAndBoundaryData::check< component_boundaryID_value_map >(maps),
379  ExcMessage("The last argument in the FuelCell::InitialAndBoundaryData::make_zero_boundary_values function "
380  "is wrong : check the previous message") );
381 
382  // --- main ---
383 
384  const unsigned int n_components = system_management.get_number_of_solution_names();
385  AssertThrow( n_components == dof.get_fe().n_components(),
386  ExcDimensionMismatch( n_components , dof.get_fe().n_components() ) );
387 
388  for(unsigned int i = 0; i < maps.size(); ++i)
389  for(component_boundaryID_value_map::const_iterator iter = maps[i].begin(); iter != maps[i].end(); ++iter)
390  {
391  std::map<types::boundary_id, double> tmp = iter->second;
392 
393  for(std::map<types::boundary_id, double>::const_iterator iter2 = tmp.begin(); iter2 != tmp.end(); ++iter2)
394  {
395  typename FunctionMap<DH::space_dimension>::type function_map;
396 
397  const ZeroFunction<DH::space_dimension> zero_function(n_components);
398  function_map[iter2->first] = &zero_function;
399 
400  std::vector<bool> component_mask(n_components, false);
401  component_mask[system_management.solution_name_to_index(iter->first)] = true;
402 
403  VectorTools::interpolate_boundary_values( mapping,
404  dof,
405  function_map,
406  dst,
407  component_mask );
408  }
409  }
410  }
411 
421  template<typename MATRIX, typename VECTOR, typename DH>
423  VECTOR& solution,
424  VECTOR& rhs,
426  const DH& dof,
427  const FuelCell::SystemManagement& system_management,
428  const std::vector< component_boundaryID_value_map >& maps,
429  const bool& repair_diagonal = false)
430  {
431  if( repair_diagonal )
432  {
434  solution,
435  rhs );
436  }
437 
438  std::map<unsigned int, double> boundary_values;
439  FuelCell::InitialAndBoundaryData::make_zero_boundary_values<DH>( boundary_values,
440  mapping,
441  dof,
442  system_management,
443  maps );
444  MatrixTools::apply_boundary_values( boundary_values,
445  matrix,
446  solution,
447  rhs );
448  }
449 
457  template<int dim>
458  class InitialOrBoundaryDataBase : public Function<dim>
459  {
460  public:
461 
463 
464 
470  virtual double value(const Point<dim>& point,
471  const unsigned int no_component = 0) const;
472 
474 
475  protected:
476 
478 
479 
487  InitialOrBoundaryDataBase(boost::shared_ptr<ApplicationData> data,
488  const unsigned int n_components = 1);
489 
494 
496 
498 
499 
505  virtual double math_expression(const Point<dim>& point,
506  const unsigned int no_component = 0) const;
507 
509 
511 
512 
517  void print_caller_name(const std::string& caller_name) const;
518 
520 
522  // DATA //
524 
526 
527 
533  boost::shared_ptr<ApplicationData> data;
534 
536 
537  };
538 
539  } // InitialAndBoundaryData
540 
541 } // FuelCell
542 
543 #endif
Definition: dof_application.h:83
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:110
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:533
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:252
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:79
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:90
#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:313
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:370
This class is a means to make variable initial or boundary data.
Definition: initial_and_boundary_data.h:458
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:464
IMPORTANT: Add all new solution variables and equations here !
Definition: system_management.h:271
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:195
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:422