OpenFCST: The open-source Fuel Cell Simulation Toolbox
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dof_application.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 //
3 // FCST: Fuel Cell Simulation Toolbox
4 //
5 // Copyright (C) 2006-2009 by Guido Kanschat
6 // Copyright (C) 2006-2014 by Energy Systems Design Laboratory, University of Alberta
7 //
8 // This software is distributed under the MIT License
9 // For more information, see the README file in /doc/LICENSE
10 //
11 // - Class: dof_application.h
12 // - Description: This class implements:
13 // - triangulation
14 // - finite element spaces
15 // - dof handler
16 // - distribution of dofs over triangulation
17 // - residual of nonlinear system of equations
18 // - estimations of cell-wise errors for adaptive refinement
19 // - and more
20 // - Developers: Guido Kanschat, Texas A&M University
21 // Valentin N. Zingan, University of Alberta
22 // Marc Secanell, University of Alberta
23 // Peter Dobson, University of Alberta
24 //
25 // ----------------------------------------------------------------------------
26 
27 #ifndef _FUEL_CELL_APPLICATION_CORE_DOF_APPLICATION_H_
28 #define _FUEL_CELL_APPLICATION_CORE_DOF_APPLICATION_H_
29 //-- dealII
30 #include <deal.II/base/data_out_base.h>
31 #include <deal.II/lac/constraint_matrix.h>
32 #include <deal.II/lac/petsc_parallel_vector.h>
33 #include <deal.II/lac/petsc_vector.h>
34 #include <deal.II/grid/tria.h>
35 #include <deal.II/grid/tria_iterator.h>
36 #include <deal.II/grid/tria_accessor.h>
37 #include <deal.II/grid/grid_refinement.h>
38 #include <deal.II/grid/grid_tools.h>
39 #include <deal.II/grid/grid_out.h>
40 #include <deal.II/dofs/dof_handler.h>
41 #include <deal.II/dofs/dof_renumbering.h>
42 #include <deal.II/numerics/data_out.h>
43 #include <deal.II/numerics/solution_transfer.h>
44 #include <deal.II/numerics/error_estimator.h>
45 #include <deal.II/distributed/solution_transfer.h>
46 
47 //-- OpenFCST
48 #include <grid/geometry.h>
49 #include <grid/geometries.h>
52 #include <utils/fcst_utilities.h>
54 
55 //--C++ Standard Libraries
56 #include <iostream>
57 #include <fstream>
58 #include <string>
59 #include <sstream>
60 #include <typeinfo>
61 
62 using namespace dealii;
63 using namespace FuelCell::ApplicationCore;
64 
65 namespace dealii
66 {
67  template<int, int> class Triangulation;
68  template<int, int> class Mapping;
69  template<int, int> class FiniteElement;
70  template<int, int> class DoFHandler;
71 }
72 
73 namespace FuelCell
74 {
75  namespace ApplicationCore
76  {
77 
106  template<int dim>
108  {
109  public:
110 
115 
120 
123 
130  DoFApplication(boost::shared_ptr<ApplicationData> data = boost::shared_ptr<ApplicationData>());
131 
136  DoFApplication();
137 
147  bool triangulation_only);
148 
153  ~DoFApplication();
154 
173  virtual void declare_parameters(ParameterHandler& param);
174 
179  virtual void initialize(ParameterHandler& param);
180 
189  virtual void remesh_dofs();
190 
195  virtual void remesh();
196 
209  virtual void init_vector(FEVector& dst) const;
210 
288  virtual void initialize_solution (FEVector& initial_guess,
289  std::shared_ptr<Function<dim> > initial_function = std::shared_ptr<Function<dim> >());
290 
292 
295 
305  virtual double estimate(const FEVectors& src);
306 
310  virtual double evaluate(const FEVectors& src);
311 
319  virtual double residual(FEVector& dst,
320  const FEVectors& src,
321  bool apply_boundaries = true);
322 
336  virtual void residual_constraints(FEVector& dst) const;
337 
338  #ifdef OPENFCST_WITH_PETSC
339  virtual void residual_constraints(PETScWrappers::MPI::Vector& dst, const std::vector<unsigned int>&) const;
340  #endif
341 
345  void store_triangulation(Triangulation<dim>& new_tr);
346 
350  void add_vector_for_transfer(FEVector* src);
351 
355  void delete_vector_for_transfer();
356 
360  void transfer_solution_to_coarse_mesh(Triangulation<dim>& tr_coarse,
361  FEVector& coarse_solution,
362  FEVector& refined_solution);
363 
367  unsigned int memory_consumption() const;
369 
372 
382  std::string filename_initial_sol;
383 
407 
412 
425 
427 
430 
433  virtual void grid_out(const std::string& basename);
434 
438  virtual void data_out(const std::string& basename,
439  const FEVectors& src);
440 
448  void print(const std::string& basename,
449  const FEVector& src,
450  const std::vector<unsigned int>& src_indices = std::vector<unsigned int>()) const;
452 
455 
459  std::vector< DataComponentInterpretation::DataComponentInterpretation > solution_interpretations;
460 
465  std::vector< DataComponentInterpretation::DataComponentInterpretation > postprocessing_interpretations;
466 
470  std::vector<DataComponentInterpretation::DataComponentInterpretation> data_interpretation;
471 
477 
482  Vector<double> output_materials;
483 
488  Vector<double> output_levels;
489 
500 
508 
516 
524  std::vector<unsigned int> solution_printing_indices;
525 
533  std::vector<unsigned int> postprocessing_printing_indices;
534 
542 
552 
556  boost::shared_ptr< Boundary<dim> > curved_boundary;
557 
561  types::boundary_id curved_bdry_id;
562 
563  protected:
566 
571  void _initialize(ParameterHandler& param);
572 
582  virtual void initialize_triangulation(ParameterHandler& param);
583 
587  //virtual void initialize_grid(ParameterHandler& param){};
588 
605  void read_init_solution(FEVector& dst,
606  bool& good_solution) const;
608 
611 
614  virtual void cell_residual(FEVector& cell_vector,
615  const CellInfo& cell);
616 
620  virtual void bdry_residual(FEVector& face_vector,
621  const FaceInfo& face);
622 
626  virtual void face_residual(FEVector& face_vector1,
627  FEVector& face_vector2,
628  const FaceInfo& face1,
629  const FaceInfo& face2);
630 
634  virtual double cell_estimate(const CellInfo& src);
635 
639  virtual double bdry_estimate(const FaceInfo& src);
640 
644  virtual double face_estimate(const FaceInfo& src1,
645  const FaceInfo& src2);
647 
650 
658  std::vector< component_materialID_value_map > component_materialID_value_maps;
659 
668  std::vector< component_boundaryID_value_map > component_boundaryID_value_maps;
669 
673 
676  boost::shared_ptr< FuelCellShop::Geometry::GridBase<dim> > mesh_generator;
677 
682  boost::shared_ptr<Triangulation<dim> > tr;
683 
685 
688  GridOut g_out;
689 
693  DataOut<dim, DoFHandler<dim> > d_out;
694 
744  virtual void data_out(const std::string& basename,
745  const FEVector& solution,
746  const std::vector<std::string>& solution_names,
747  const std::vector< DataPostprocessor<dim>* >& PostProcessing);
748 
763  virtual void data_out(const std::string& basename,
764 
765  const FEVector& solution,
766  const std::vector<std::string>& solution_names,
767 
768  const FEVector& postprocessing = FEVector(),
769  const std::vector<std::string>& postprocessing_names = std::vector<std::string>());
770 
775  void constrain_boundary(FEVector& v,
776  bool homogeneous) const;
777 
783 
791  std::map<unsigned int, double> boundary_constraints;
792 
809  ConstraintMatrix hanging_node_constraints;
810 
821  boost::shared_ptr<Mapping<dim> > mapping;
822 
844  unsigned int mapping_degree;
845 
849  boost::shared_ptr<FiniteElement<dim> > element;
850 
854  boost::shared_ptr<DoFHandler<dim> > dof;
855 
857 
861  Vector<float> cell_errors;
862 
866  Vector<float> face_errors;
867 
871  std::string refinement;
872 
876  unsigned int initial_refinement;
877 
882 
887 
894 
901  Point<dim> sort_direction;
902 
906  std::vector<FEVector*> transfer_vectors;
907 
911  Quadrature<dim> quadrature_residual_cell;
912 
917 
923 
953  Table<2, DoFTools::Coupling> cell_couplings;
954 
959  Table<2, DoFTools::Coupling> flux_couplings;
960 
966 
972 
977  unsigned int verbosity;
978 
979  private:
980 
986  virtual void sort_dofs(DoFHandler<dim>* dof_handler) const;
987 
998  virtual void distribute_face_to_cell_errors();
999 
1013  virtual double global_from_local_errors() const;
1014 
1023  unsigned int n_ref;
1024  };
1025 
1026  } // ApplicationCore
1027 
1028 } // FuelCell
1029 
1030 #endif
GridOut g_out
The object for writing grids.
Definition: dof_application.h:688
Definition: dof_application.h:67
FuelCell::ApplicationCore::IntegrationInfo< dim, FEFaceValuesBase< dim > > FaceInfo
Shortcut.
Definition: dof_application.h:119
boost::shared_ptr< FuelCellShop::Geometry::GridBase< dim > > mesh_generator
Grid.
Definition: dof_application.h:676
const unsigned int dim
Definition: fcst_constants.h:23
unsigned int mapping_degree
Degree used for polynomial mapping of arbitrary order.
Definition: dof_application.h:844
Vector< double > output_materials
Vector that will be used by data_out to store the material ids.
Definition: dof_application.h:482
DataOut< dim, DoFHandler< dim > > d_out
The object for writing data.
Definition: dof_application.h:693
ConstraintMatrix hanging_node_constraints
Constraint Matrix object.
Definition: dof_application.h:809
bool output_initial_sol
Flag to output the initial solution used to start the solving process.
Definition: dof_application.h:396
Definition: dof_application.h:68
BlockInfo block_info
Definition: dof_application.h:856
std::vector< component_boundaryID_value_map > component_boundaryID_value_maps
Each entry of this std::vector reflects the following structure (see FuelCell::InitialAndBoundaryData...
Definition: dof_application.h:668
A small structure collecting the different BlockIndices of FEVector vectors (for instance, solution) involved in the computations.
Definition: mesh_loop_info_objects.h:173
bool output_coarse_solution
Bool flag used to specify if the final solution should be stored in the coarse mesh in order to be us...
Definition: dof_application.h:424
Quadrature< dim-1 > quadrature_residual_face
Quadrature rule for residual computation on faces.
Definition: dof_application.h:922
std::vector< FEVector * > transfer_vectors
List of vector names to be transfered from one grid to the next.
Definition: dof_application.h:906
Vector< double > output_levels
Vector that will be used by data_out to store the refinement levels at each cell. ...
Definition: dof_application.h:488
bool output_actual_degree
true, if you want to output solution and postprocessing data using actual finite element fields Q_n w...
Definition: dof_application.h:499
bool print_solution
true, if you want to print FEVector solution to a text file.
Definition: dof_application.h:507
std::vector< unsigned int > postprocessing_printing_indices
The indices of the FEVector postprocessing to be printed to a text file.
Definition: dof_application.h:533
bool sort_cuthill
Flag for sorting with Cuthill McKee algorithm.
Definition: dof_application.h:893
Definition: dof_application.h:69
std::string refinement
Refinement parameter from parameter file.
Definition: dof_application.h:871
std::vector< DataComponentInterpretation::DataComponentInterpretation > data_interpretation
Definition: dof_application.h:470
FuelCell::SystemManagement system_management
This object knows everything about FCST equations, variables, couplings, etc.
Definition: dof_application.h:782
Vector< float > cell_errors
The result of error estimation by cell.
Definition: dof_application.h:861
bool interior_fluxes
Extend the integration loops in assemble() and residual() also to interior faces. ...
Definition: dof_application.h:971
std::vector< component_materialID_value_map > component_materialID_value_maps
Each entry of this std::vector reflects the following structure (see FuelCell::InitialAndBoundaryData...
Definition: dof_application.h:658
std::string filename_initial_sol
Filename where to output the initial grid.
Definition: dof_application.h:382
boost::shared_ptr< Boundary< dim > > curved_boundary
Curved boundary.
Definition: dof_application.h:556
types::boundary_id curved_bdry_id
Curved boundary ID.
Definition: dof_application.h:561
bool use_predefined_solution
Use user pre-defined initial solution.
Definition: dof_application.h:411
FuelCell::ApplicationCore::IntegrationInfo< dim, FEValuesBase< dim > > CellInfo
Shortcut.
Definition: dof_application.h:114
This class is created for the objects handed to the mesh loops.
Definition: mesh_loop_info_objects.h:544
Vector< float > face_errors
The result of error estimation by face.
Definition: dof_application.h:866
double coarsening_threshold
Coarsening threshold for adaptive method from parameter file.
Definition: dof_application.h:886
boost::shared_ptr< Triangulation< dim > > tr
Pointer to the Triangulation object.
Definition: dof_application.h:682
Quadrature< dim > quadrature_residual_cell
Quadrature rule for residual computation on cells.
Definition: dof_application.h:911
bool output_materials_and_levels
output_materials_and_levels if true then visualized, otherwise suppressed.
Definition: dof_application.h:476
bool print_blocks_instead_of_indices
true, if the whole blocks of FEVector solution or FEVector postprocessing to be printed to a text fil...
Definition: dof_application.h:541
Base class for applications.
Definition: application_base.h:113
bool output_matrices_and_rhs
If true, all cell matrices and right hand sides will be output.
Definition: dof_application.h:550
unsigned int initial_refinement
Initial refinement from parameter file.
Definition: dof_application.h:876
std::vector< DataComponentInterpretation::DataComponentInterpretation > postprocessing_interpretations
postprocessing_interpretations identifies whether some postprocessing_names are scalars or parts of a...
Definition: dof_application.h:465
boost::shared_ptr< DoFHandler< dim > > dof
Pointer to the DoFHandler object.
Definition: dof_application.h:854
bool read_in_initial_solution
Bool flag used to specify if the initial solution to the problem, specially important for non-linear ...
Definition: dof_application.h:406
std::vector< unsigned int > solution_printing_indices
The indices of the FEVector solution to be printed to a text file.
Definition: dof_application.h:524
Point< dim > sort_direction
Direction for downstream sorting.
Definition: dof_application.h:901
IMPORTANT: Add all new solution variables and equations here !
Definition: system_management.h:300
boost::shared_ptr< FiniteElement< dim > > element
The finite element used in dof.
Definition: dof_application.h:849
Quadrature< dim-1 > quadrature_residual_bdry
Quadrature rule for residual computation on boundary faces.
Definition: dof_application.h:916
Table< 2, DoFTools::Coupling > flux_couplings
Couplings through flux bilinear forms.
Definition: dof_application.h:959
unsigned int verbosity
Controls verbosity of certain functions.
Definition: dof_application.h:977
Definition: dof_application.h:70
bool boundary_fluxes
Extend the integration loops in assemble() and residual() also to boundary faces. ...
Definition: dof_application.h:965
BlockVector< double > FEVector
The vector class used by applications.
Definition: application_data.h:46
Table< 2, DoFTools::Coupling > cell_couplings
Couplings through cell bilinear forms.
Definition: dof_application.h:953
The data type used in function calls of Application.
Definition: fe_vectors.h:59
boost::shared_ptr< Mapping< dim > > mapping
The mapping used for the transformation of mesh cells.
Definition: dof_application.h:821
double refinement_threshold
Refinement threshold for adaptive method from parameter file.
Definition: dof_application.h:881
Base class for all linear applications, i.e., all applications requiring Triangulation and DoFHandler...
Definition: dof_application.h:107
bool print_postprocessing
true, if you want to print FEVector postprocessing to a text file.
Definition: dof_application.h:515
std::vector< DataComponentInterpretation::DataComponentInterpretation > solution_interpretations
solution_interpretations identifies whether some solution_names are scalars or parts of a vector...
Definition: dof_application.h:459
std::map< unsigned int, double > boundary_constraints
List of all nodes constrained by a strong boundary condition, together with a value to be assigned...
Definition: dof_application.h:791
unsigned int n_ref
Number of refinements.
Definition: dof_application.h:1023