Reference documentation for deal.II version 8.4.2
tria.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2008 - 2016 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii__distributed_tria_h
17 #define dealii__distributed_tria_h
18 
19 
20 #include <deal.II/base/config.h>
21 #include <deal.II/base/subscriptor.h>
22 #include <deal.II/base/smartpointer.h>
23 #include <deal.II/base/template_constraints.h>
24 #include <deal.II/grid/tria.h>
25 
26 #include <deal.II/base/std_cxx11/function.h>
27 #include <deal.II/base/std_cxx11/tuple.h>
28 
29 #include <deal.II/distributed/tria_base.h>
30 
31 #include <set>
32 #include <vector>
33 #include <list>
34 #include <utility>
35 
36 #ifdef DEAL_II_WITH_MPI
37 # include <mpi.h>
38 #endif
39 
40 #ifdef DEAL_II_WITH_P4EST
41 #include <p4est_connectivity.h>
42 #include <p4est.h>
43 #include <p4est_ghost.h>
44 
45 #include <p8est_connectivity.h>
46 #include <p8est.h>
47 #include <p8est_ghost.h>
48 #endif
49 
50 
51 DEAL_II_NAMESPACE_OPEN
52 
53 template <int, int> class Triangulation;
54 
55 #ifdef DEAL_II_WITH_P4EST
56 
57 namespace internal
58 {
59  namespace DoFHandler
60  {
61  namespace Policy
62  {
63  template <int, int> class ParallelDistributed;
64  }
65  }
66 }
67 
68 
69 namespace internal
70 {
71  namespace p4est
72  {
80  template <int> struct types;
81 
82  template <>
83  struct types<2>
84  {
85  typedef p4est_connectivity_t connectivity;
86  typedef p4est_t forest;
87  typedef p4est_tree_t tree;
88  typedef p4est_quadrant_t quadrant;
89  typedef p4est_topidx_t topidx;
90  typedef p4est_locidx_t locidx;
91 #if DEAL_II_P4EST_VERSION_GTE(0,3,4,3)
92  typedef p4est_connect_type_t balance_type;
93 #else
94  typedef p4est_balance_type_t balance_type;
95 #endif
96  typedef p4est_ghost_t ghost;
97  };
98 
99  template <>
100  struct types<3>
101  {
102  typedef p8est_connectivity_t connectivity;
103  typedef p8est_t forest;
104  typedef p8est_tree_t tree;
105  typedef p8est_quadrant_t quadrant;
106  typedef p4est_topidx_t topidx;
107  typedef p4est_locidx_t locidx;
108 #if DEAL_II_P4EST_VERSION_GTE(0,3,4,3)
109  typedef p8est_connect_type_t balance_type;
110 #else
111  typedef p8est_balance_type_t balance_type;
112 #endif
113  typedef p8est_ghost_t ghost;
114  };
115 
116 
121  template <int dim>
122  void
123  init_quadrant_children
124  (const typename types<dim>::quadrant &p4est_cell,
126 
127 
131  template <int dim>
132  void
133  init_coarse_quadrant(typename types<dim>::quadrant &quad);
134 
135 
136 
140  template <int dim>
141  bool
142  quadrant_is_equal (const typename types<dim>::quadrant &q1,
143  const typename types<dim>::quadrant &q2);
144 
145  //TODO: remove these functions from
146  //public interface somehow? [TH]
147 
151  template <int dim>
152  bool
153  quadrant_is_ancestor (const typename types<dim>::quadrant &q1,
154  const typename types<dim>::quadrant &q2);
155  }
156 }
157 
158 //forward declaration of the data type for periodic face pairs
159 namespace GridTools
160 {
161  template <typename CellIterator> struct PeriodicFacePair;
162 }
163 
164 namespace parallel
165 {
166  namespace distributed
167  {
168 
169 
327  template <int dim, int spacedim = dim>
328  class Triangulation : public ::parallel::Triangulation<dim,spacedim>
329  {
330  public:
348  typedef typename ::Triangulation<dim,spacedim>::cell_iterator cell_iterator;
349 
368  typedef typename ::Triangulation<dim,spacedim>::active_cell_iterator active_cell_iterator;
369 
370  typedef typename ::Triangulation<dim,spacedim>::CellStatus CellStatus;
371 
376  enum Settings
377  {
381  default_setting = 0x0,
390  mesh_reconstruction_after_repartitioning = 0x1,
397  construct_multigrid_hierarchy = 0x2,
403  no_automatic_repartitioning = 0x4
404  };
405 
406 
407 
436  Triangulation (MPI_Comm mpi_communicator,
437  const typename ::Triangulation<dim,spacedim>::MeshSmoothing
438  smooth_grid = (::Triangulation<dim,spacedim>::none),
439  const Settings settings = default_setting);
440 
444  virtual ~Triangulation ();
445 
452  virtual void clear ();
453 
457  virtual void copy_triangulation (const ::Triangulation<dim, spacedim> &old_tria);
458 
468  virtual void create_triangulation (const std::vector<Point<spacedim> > &vertices,
469  const std::vector<CellData<dim> > &cells,
470  const SubCellData &subcelldata);
471 
501  virtual void execute_coarsening_and_refinement ();
502 
509  virtual bool prepare_coarsening_and_refinement ();
510 
551  void repartition ();
552 
605  void
606  communicate_locally_moved_vertices (const std::vector<bool> &vertex_locally_moved);
607 
608 
624  virtual
625  bool has_hanging_nodes() const;
626 
630  virtual std::size_t memory_consumption () const;
631 
637  virtual std::size_t memory_consumption_p4est () const;
638 
646  void write_mesh_vtk (const char *file_basename) const;
647 
652  unsigned int get_checksum () const;
653 
661  void save(const char *filename) const;
662 
681  void load(const char *filename,
682  const bool autopartition = true);
683 
718  unsigned int
719  register_data_attach (const std::size_t size,
720  const std_cxx11::function<void (const cell_iterator &,
721  const CellStatus,
722  void *)> &pack_callback);
723 
738  void
739  notify_ready_to_unpack (const unsigned int offset,
740  const std_cxx11::function<void (const cell_iterator &,
741  const CellStatus,
742  const void *)> &unpack_callback);
743 
750  const std::vector<types::global_dof_index> &
751  get_p4est_tree_to_coarse_cell_permutation() const;
752 
758  const std::vector<types::global_dof_index> &
759  get_coarse_cell_to_p4est_tree_permutation() const;
760 
778  void
779  add_periodicity
780  (const std::vector<GridTools::PeriodicFacePair<cell_iterator> > &);
781 
782 
783  private:
784 
790  virtual void update_number_cache ();
791 
796 
801 
807  typename ::internal::p4est::types<dim>::connectivity *connectivity;
808 
813  typename ::internal::p4est::types<dim>::forest *parallel_forest;
818  typename ::internal::p4est::types<dim>::ghost *parallel_ghost;
819 
831 
832 
837  unsigned int attached_data_size;
838 
843  unsigned int n_attached_datas;
844 
850 
851  typedef std_cxx11::function<
852  void(typename Triangulation<dim,spacedim>::cell_iterator, CellStatus, void *)
853  > pack_callback_t;
854 
855  typedef std::pair<unsigned int, pack_callback_t> callback_pair_t;
856 
857  typedef std::list<callback_pair_t> callback_list_t;
858 
864 
865 
879  std::vector<types::global_dof_index> coarse_cell_to_p4est_tree_permutation;
880  std::vector<types::global_dof_index> p4est_tree_to_coarse_cell_permutation;
881 
887  std::vector<GridTools::PeriodicFacePair<cell_iterator> > periodic_face_pairs_level_0;
888 
893  typename ::internal::p4est::types<dim>::tree *
894  init_tree(const int dealii_coarse_cell_index) const;
895 
900  void setup_coarse_cell_to_p4est_tree_permutation ();
901 
908  void copy_new_triangulation_to_p4est (::internal::int2type<2>);
909  void copy_new_triangulation_to_p4est (::internal::int2type<3>);
910 
915  void copy_local_forest_to_triangulation ();
916 
922  void attach_mesh_data();
923 
937  std::vector<unsigned int>
938  get_cell_weights();
939 
945  void
946  fill_vertices_with_ghost_neighbors
947  (std::map<unsigned int, std::set<::types::subdomain_id> >
948  &vertices_with_ghost_neighbors);
949 
955  void
956  fill_level_vertices_with_ghost_neighbors
957  (const unsigned int level,
958  std::map<unsigned int, std::set<::types::subdomain_id> >
959  &vertices_with_ghost_neighbors);
960 
970  std::vector<bool>
971  mark_locally_active_vertices_on_level(const unsigned int level) const;
972 
973  template <int, int> friend class ::internal::DoFHandler::Policy::ParallelDistributed;
974  };
975 
976 
982  template <int spacedim>
983  class Triangulation<1,spacedim> : public ::parallel::Triangulation<1,spacedim>
984  {
985  public:
990  Triangulation (MPI_Comm mpi_communicator);
991 
995  virtual ~Triangulation ();
996 
1003  const std::vector<types::global_dof_index> &
1004  get_p4est_tree_to_coarse_cell_permutation() const;
1005 
1039  void
1040  communicate_locally_moved_vertices (const std::vector<bool> &vertex_locally_moved);
1041 
1046  std::vector<types::global_dof_index> coarse_cell_to_p4est_tree_permutation;
1047  std::vector<types::global_dof_index> p4est_tree_to_coarse_cell_permutation;
1048 
1053  {
1054  default_setting = 0x0,
1055  mesh_reconstruction_after_repartitioning = 0x1,
1056  construct_multigrid_hierarchy = 0x2
1057  };
1058 
1059 
1060 //TODO: The following variable should really be private, but it is used in dof_handler_policy.cc ...
1065 
1070  void
1071  fill_vertices_with_ghost_neighbors
1072  (std::map<unsigned int, std::set<::types::subdomain_id> >
1073  &vertices_with_ghost_neighbors);
1074 
1079  void
1080  fill_level_vertices_with_ghost_neighbors
1081  (const unsigned int level,
1082  std::map<unsigned int, std::set<::types::subdomain_id> >
1083  &vertices_with_ghost_neighbors);
1084 
1089  std::vector<bool>
1090  mark_locally_active_vertices_on_level(const unsigned int level) const;
1091 
1092  };
1093  }
1094 }
1095 
1096 
1097 #else // DEAL_II_WITH_P4EST
1098 
1099 namespace parallel
1100 {
1101  namespace distributed
1102  {
1113  template <int dim, int spacedim = dim>
1114  class Triangulation : public ::parallel::Triangulation<dim,spacedim>
1115  {
1116  private:
1120  Triangulation ();
1121 
1122  };
1123  }
1124 }
1125 
1126 
1127 #endif
1128 
1129 
1130 DEAL_II_NAMESPACE_CLOSE
1131 
1132 #endif
typename ::internal::p4est::types< dim >::connectivity * connectivity
Definition: tria.h:807
std::vector< types::global_dof_index > coarse_cell_to_p4est_tree_permutation
Definition: tria.h:1046
callback_list_t attached_data_pack_callbacks
Definition: tria.h:863
typename ::internal::p4est::types< dim >::ghost * parallel_ghost
Definition: tria.h:818
typename ::internal::p4est::types< dim >::forest * parallel_forest
Definition: tria.h:813
Definition: types.h:30
::Triangulation< dim, spacedim >::active_cell_iterator active_cell_iterator
Definition: tria.h:368
::Triangulation< dim, spacedim >::cell_iterator cell_iterator
Definition: tria.h:348
std::vector< GridTools::PeriodicFacePair< cell_iterator > > periodic_face_pairs_level_0
Definition: tria.h:887
unsigned int n_attached_deserialize
Definition: tria.h:849
std::vector< types::global_dof_index > coarse_cell_to_p4est_tree_permutation
Definition: tria.h:879