Reference documentation for deal.II version 8.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
tria.h
1 // ---------------------------------------------------------------------
2 // @f$Id: tria.h 31932 2013-12-08 02:15:54Z heister @f$
3 //
4 // Copyright (C) 2008 - 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16 
17 #ifndef __deal2__distributed_tria_h
18 #define __deal2__distributed_tria_h
19 
20 
21 #include <deal.II/base/config.h>
22 #include <deal.II/base/subscriptor.h>
23 #include <deal.II/base/smartpointer.h>
24 #include <deal.II/base/template_constraints.h>
25 #include <deal.II/grid/tria.h>
26 
27 #include <deal.II/base/std_cxx1x/function.h>
28 #include <deal.II/base/std_cxx1x/tuple.h>
29 
30 #include <set>
31 #include <vector>
32 #include <list>
33 #include <utility>
34 
35 #ifdef DEAL_II_WITH_MPI
36 # include <mpi.h>
37 #endif
38 
39 #ifdef DEAL_II_WITH_P4EST
40 #include <p4est_connectivity.h>
41 #include <p4est.h>
42 #include <p4est_ghost.h>
43 
44 #include <p8est_connectivity.h>
45 #include <p8est.h>
46 #include <p8est_ghost.h>
47 #endif
48 
49 
50 DEAL_II_NAMESPACE_OPEN
51 
52 template <int, int> class Triangulation;
53 
54 #ifdef DEAL_II_WITH_P4EST
55 
56 namespace internal
57 {
58  namespace DoFHandler
59  {
60  namespace Policy
61  {
62  template <int, int> class ParallelDistributed;
63  }
64  }
65 }
66 
67 
68 namespace internal
69 {
70  namespace p4est
71  {
89  template <int> struct types;
90 
91  template <>
92  struct types<2>
93  {
94  typedef p4est_connectivity_t connectivity;
95  typedef p4est_t forest;
96  typedef p4est_tree_t tree;
97  typedef p4est_quadrant_t quadrant;
98  typedef p4est_topidx_t topidx;
99  typedef p4est_locidx_t locidx;
100  typedef p4est_balance_type_t balance_type;
101  typedef p4est_ghost_t ghost;
102  };
103 
104  template <>
105  struct types<3>
106  {
107  typedef p8est_connectivity_t connectivity;
108  typedef p8est_t forest;
109  typedef p8est_tree_t tree;
110  typedef p8est_quadrant_t quadrant;
111  typedef p4est_topidx_t topidx;
112  typedef p4est_locidx_t locidx;
113  typedef p8est_balance_type_t balance_type;
114  typedef p8est_ghost_t ghost;
115  };
116 
117 
124  template <int dim>
125  void
126  init_quadrant_children
127  (const typename types<dim>::quadrant &p4est_cell,
129 
130 
134  template <int dim>
135  void
136  init_coarse_quadrant(typename types<dim>::quadrant &quad);
137 
138 
139 
143  template <int dim>
144  bool
145  quadrant_is_equal (const typename types<dim>::quadrant &q1,
146  const typename types<dim>::quadrant &q2);
147 
148  //TODO: remove these functions from
149  //public interface somehow? [TH]
150 
154  template <int dim>
155  bool
156  quadrant_is_ancestor (const typename types<dim>::quadrant &q1,
157  const typename types<dim>::quadrant &q2);
158  }
159 }
160 
161 //forward declaration of the data type for periodic face pairs
162 namespace GridTools
163 {
164  template <typename CellIterator> struct PeriodicFacePair;
165 }
166 
167 namespace parallel
168 {
169  namespace distributed
170  {
171 
172 
318  template <int dim, int spacedim = dim>
319  class Triangulation : public ::Triangulation<dim,spacedim>
320  {
321  public:
327  typedef typename ::Triangulation<dim,spacedim>::active_cell_iterator active_cell_iterator;
328  typedef typename ::Triangulation<dim,spacedim>::cell_iterator cell_iterator;
329 
353  enum Settings
354  {
355  default_setting = 0x0,
356  mesh_reconstruction_after_repartitioning = 0x1,
357  construct_multigrid_hierarchy = 0x2
358  };
359 
360 
361 
413  const typename ::Triangulation<dim,spacedim>::MeshSmoothing
415  const Settings settings = default_setting);
416 
420  virtual ~Triangulation ();
421 
431  virtual void clear ();
432 
438  virtual void copy_triangulation (const ::Triangulation<dim, spacedim> &old_tria);
439 
458  virtual void create_triangulation (const std::vector<Point<spacedim> > &vertices,
459  const std::vector<CellData<dim> > &cells,
460  const SubCellData &subcelldata);
461 
490  virtual void execute_coarsening_and_refinement ();
491 
505 
541  unsigned int n_locally_owned_active_cells () const;
542 
553 
557  virtual unsigned int n_global_levels () const;
558 
570  const std::vector<unsigned int> &
572 
578  MPI_Comm get_communicator () const;
579 
584  virtual std::size_t memory_consumption () const;
585 
595  virtual std::size_t memory_consumption_p4est () const;
596 
607  void write_mesh_vtk (const char *file_basename) const;
608 
616  unsigned int get_checksum () const;
617 
624  void save(const char *filename) const;
625 
634  void load(const char *filename);
635 
649  {
650  CELL_PERSIST, CELL_REFINE, CELL_COARSEN, CELL_INVALID
651  };
652 
681  unsigned int
682  register_data_attach (const std::size_t size,
683  const std_cxx1x::function<void (const cell_iterator &,
684  const CellStatus,
685  void *)> &pack_callback);
686 
693  void
694  notify_ready_to_unpack (const unsigned int offset,
695  const std_cxx1x::function<void (const cell_iterator &,
696  const CellStatus,
697  const void *)> &unpack_callback);
698 
706  const std::vector<types::global_dof_index> &
708 
709 
710 
727  void
729  (const std::vector<GridTools::PeriodicFacePair<cell_iterator> > &);
730 
731 
732 
733  private:
744 
749 
756 
762 
768  struct NumberCache
769  {
770  std::vector<unsigned int> n_locally_owned_active_cells;
771  types::global_dof_index n_global_active_cells;
772  unsigned int n_global_levels;
773 
774  NumberCache();
775  };
776 
777  NumberCache number_cache;
778 
787  typename ::internal::p4est::types<dim>::connectivity *connectivity;
788 
794  typename ::internal::p4est::types<dim>::forest *parallel_forest;
799  typename ::internal::p4est::types<dim>::ghost *parallel_ghost;
800 
822 
823 
829  unsigned int attached_data_size;
830 
836  unsigned int n_attached_datas;
837 
843 
844  typedef std_cxx1x::function<
845  void(typename Triangulation<dim,spacedim>::cell_iterator, CellStatus, void *)
846  > pack_callback_t;
847 
848  typedef std::pair<unsigned int, pack_callback_t> callback_pair_t;
849 
850  typedef std::list<callback_pair_t> callback_list_t;
851 
858 
859 
880  std::vector<types::global_dof_index> coarse_cell_to_p4est_tree_permutation;
881  std::vector<types::global_dof_index> p4est_tree_to_coarse_cell_permutation;
882 
888  typename ::internal::p4est::types<dim>::tree *
889  init_tree(const int dealii_coarse_cell_index) const;
890 
897 
908 
915 
916 
922  void update_number_cache ();
923 
931  void attach_mesh_data();
932 
938  void
940  (std::map<unsigned int, std::set<::types::subdomain_id> >
941  &vertices_with_ghost_neighbors);
942 
943  template <int, int> friend class ::internal::DoFHandler::Policy::ParallelDistributed;
944  };
945 
946 
954  template <int spacedim>
955  class Triangulation<1,spacedim> : public ::Triangulation<1,spacedim>
956  {
957  public:
963  Triangulation (MPI_Comm mpi_communicator);
964 
968  virtual ~Triangulation ();
969 
975  MPI_Comm get_communicator () const;
976 
987  virtual unsigned int n_global_levels () const;
988 
996  const std::vector<types::global_dof_index> &
998 
1012 
1020  std::vector<types::global_dof_index> coarse_cell_to_p4est_tree_permutation;
1021  std::vector<types::global_dof_index> p4est_tree_to_coarse_cell_permutation;
1022 
1027  {
1028  default_setting = 0x0,
1029  mesh_reconstruction_after_repartitioning = 0x1,
1030  construct_multigrid_hierarchy = 0x2
1031  };
1032 
1033 
1034 //TODO: The following variable should really be private, but it is used in dof_handler_policy.cc ...
1039 
1044  void
1046  (std::map<unsigned int, std::set<::types::subdomain_id> >
1047  &vertices_with_ghost_neighbors);
1048 
1049  };
1050  }
1051 }
1052 
1053 
1054 #else // DEAL_II_WITH_P4EST
1055 
1056 namespace parallel
1057 {
1058  namespace distributed
1059  {
1075  template <int dim, int spacedim = dim>
1076  class Triangulation : public ::Triangulation<dim,spacedim>
1077  {
1078  private:
1082  Triangulation ();
1083 
1084  public:
1085 
1089  virtual ~Triangulation ();
1090 
1104 
1110 #ifdef DEAL_II_WITH_MPI
1111  MPI_Comm get_communicator () const;
1112 #endif
1113  };
1114  }
1115 }
1116 
1117 
1118 #endif
1119 
1120 
1121 DEAL_II_NAMESPACE_CLOSE
1122 
1123 #endif
const std::vector< types::global_dof_index > & get_p4est_tree_to_coarse_cell_permutation() const
const std::vector< unsigned int > & n_locally_owned_active_cells_per_processor() const
typename::internal::p4est::types< dim >::connectivity * connectivity
Definition: tria.h:787
virtual std::size_t memory_consumption() const
void fill_vertices_with_ghost_neighbors(std::map< unsigned int, std::set<::types::subdomain_id > > &vertices_with_ghost_neighbors)
virtual void create_triangulation(const std::vector< Point< spacedim > > &vertices, const std::vector< CellData< dim > > &cells, const SubCellData &subcelldata)
virtual std::size_t memory_consumption_p4est() const
std::vector< types::global_dof_index > coarse_cell_to_p4est_tree_permutation
Definition: tria.h:1020
void save(const char *filename) const
std::vector< Point< spacedim > > vertices
Definition: tria.h:3539
void notify_ready_to_unpack(const unsigned int offset, const std_cxx1x::function< void(const cell_iterator &, const CellStatus, const void *)> &unpack_callback)
void load(const char *filename)
types::subdomain_id my_subdomain
Definition: tria.h:755
void copy_new_triangulation_to_p4est(::internal::int2type< 2 >)
unsigned int get_checksum() const
callback_list_t attached_data_pack_callbacks
Definition: tria.h:857
typename::internal::p4est::types< dim >::ghost * parallel_ghost
Definition: tria.h:799
typename::internal::p4est::types< dim >::forest * parallel_forest
Definition: tria.h:794
types::subdomain_id locally_owned_subdomain() const
typename::internal::p4est::types< dim >::tree * init_tree(const int dealii_coarse_cell_index) const
Triangulation(MPI_Comm mpi_communicator, const typename::Triangulation< dim, spacedim >::MeshSmoothing smooth_grid=(::Triangulation< dim, spacedim >::none), const Settings settings=default_setting)
unsigned int global_dof_index
Definition: types.h:100
unsigned int register_data_attach(const std::size_t size, const std_cxx1x::function< void(const cell_iterator &, const CellStatus, void *)> &pack_callback)
unsigned int n_locally_owned_active_cells() const
void add_periodicity(const std::vector< GridTools::PeriodicFacePair< cell_iterator > > &)
virtual unsigned int n_global_levels() const
unsigned int subdomain_id
Definition: types.h:43
virtual void copy_triangulation(const ::Triangulation< dim, spacedim > &old_tria)
types::global_dof_index n_global_active_cells() const
void write_mesh_vtk(const char *file_basename) const
MeshSmoothing smooth_grid
Definition: tria.h:3243
unsigned int n_attached_deserialize
Definition: tria.h:842
virtual void execute_coarsening_and_refinement()
::Triangulation< dim, spacedim >::active_cell_iterator active_cell_iterator
Definition: tria.h:327
std::vector< types::global_dof_index > coarse_cell_to_p4est_tree_permutation
Definition: tria.h:880