Reference documentation for deal.II version 9.0.0
tria.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2008 - 2018 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/distributed/tria_base.h>
27 #include <deal.II/distributed/p4est_wrappers.h>
28 
29 #include <set>
30 #include <vector>
31 #include <list>
32 #include <utility>
33 #include <functional>
34 #include <tuple>
35 #include <type_traits>
36 
37 #ifdef DEAL_II_WITH_MPI
38 # include <mpi.h>
39 #endif
40 
41 #ifdef DEAL_II_WITH_P4EST
42 #include <p4est_connectivity.h>
43 #include <p4est.h>
44 #include <p4est_ghost.h>
45 
46 #include <p8est_connectivity.h>
47 #include <p8est.h>
48 #include <p8est_ghost.h>
49 #endif
50 
51 
52 DEAL_II_NAMESPACE_OPEN
53 
54 #ifdef DEAL_II_WITH_P4EST
55 
56 namespace internal
57 {
58  namespace DoFHandlerImplementation
59  {
60  namespace Policy
61  {
62  template <typename> class ParallelDistributed;
63  }
64  }
65 }
66 
67 namespace FETools
68 {
69  namespace internal
70  {
71  template <int, int, class> class ExtrapolateImplementation;
72  }
73 }
74 
75 //forward declaration of the data type for periodic face pairs
76 namespace GridTools
77 {
78  template <typename CellIterator> struct PeriodicFacePair;
79 }
80 
81 namespace parallel
82 {
83  namespace distributed
84  {
85 
86 
244  template <int dim, int spacedim = dim>
245  class Triangulation : public ::parallel::Triangulation<dim,spacedim>
246  {
247  public:
265  typedef typename ::Triangulation<dim,spacedim>::cell_iterator cell_iterator;
266 
285  typedef typename ::Triangulation<dim,spacedim>::active_cell_iterator active_cell_iterator;
286 
287  typedef typename ::Triangulation<dim,spacedim>::CellStatus CellStatus;
288 
293  enum Settings
294  {
321  };
322 
323 
324 
357  const typename ::Triangulation<dim,spacedim>::MeshSmoothing
360 
364  virtual ~Triangulation ();
365 
372  virtual void clear ();
373 
383  virtual void copy_triangulation (const ::Triangulation<dim, spacedim> &other_tria);
384 
394  virtual void create_triangulation (const std::vector<Point<spacedim> > &vertices,
395  const std::vector<CellData<dim> > &cells,
396  const SubCellData &subcelldata);
397 
427  virtual void execute_coarsening_and_refinement ();
428 
435  virtual bool prepare_coarsening_and_refinement ();
436 
477  void repartition ();
478 
531  void
532  communicate_locally_moved_vertices (const std::vector<bool> &vertex_locally_moved);
533 
534 
550  virtual
551  bool has_hanging_nodes() const;
552 
556  virtual std::size_t memory_consumption () const;
557 
563  virtual std::size_t memory_consumption_p4est () const;
564 
572  void write_mesh_vtk (const char *file_basename) const;
573 
578  unsigned int get_checksum () const;
579 
587  void save(const char *filename) const;
588 
607  void load(const char *filename,
608  const bool autopartition = true);
609 
705  unsigned int
706  register_data_attach (const std::size_t size,
707  const std::function<void (const cell_iterator &,
708  const CellStatus,
709  void *)> &pack_callback);
710 
759  void
760  notify_ready_to_unpack (const unsigned int handle,
761  const std::function<void (const cell_iterator &,
762  const CellStatus,
763  const void *)> &unpack_callback);
764 
771  const std::vector<types::global_dof_index> &
773 
779  const std::vector<types::global_dof_index> &
781 
800  virtual void
802  (const std::vector<::GridTools::PeriodicFacePair<cell_iterator> > &);
803 
804 
805  private:
806 
811  virtual void update_number_cache ();
812 
817 
822 
828  typename ::internal::p4est::types<dim>::connectivity *connectivity;
829 
834  typename ::internal::p4est::types<dim>::forest *parallel_forest;
835 
840  typename ::internal::p4est::types<dim>::ghost *parallel_ghost;
841 
848  {
856 
861  unsigned int n_attached_datas;
862 
868 
869  using pack_callback_t = std::function<void (typename Triangulation<dim,spacedim>::cell_iterator,
870  CellStatus,
871  void *)>;
872 
880  std::map<unsigned int, pack_callback_t> pack_callbacks;
881  };
882 
883  CellAttachedData cell_attached_data;
884 
898  std::vector<types::global_dof_index> coarse_cell_to_p4est_tree_permutation;
899  std::vector<types::global_dof_index> p4est_tree_to_coarse_cell_permutation;
900 
905  typename ::internal::p4est::types<dim>::tree *
906  init_tree(const int dealii_coarse_cell_index) const;
907 
913 
920  void copy_new_triangulation_to_p4est (std::integral_constant<int, 2>);
921  void copy_new_triangulation_to_p4est (std::integral_constant<int, 3>);
922 
928 
947  void attach_mesh_data();
948 
962  std::vector<unsigned int>
964 
972  virtual std::map<unsigned int, std::set<::types::subdomain_id> >
974 
984  std::vector<bool>
985  mark_locally_active_vertices_on_level(const int level) const;
986 
987  template <typename> friend class ::internal::DoFHandlerImplementation::Policy::ParallelDistributed;
988 
989  template <int,int,class> friend class ::FETools::internal::ExtrapolateImplementation;
990  };
991 
992 
998  template <int spacedim>
999  class Triangulation<1,spacedim> : public ::parallel::Triangulation<1,spacedim>
1000  {
1001  public:
1002 
1007  {
1008  default_setting = 0x0,
1011  };
1012 
1017  Triangulation (MPI_Comm mpi_communicator,
1018  const typename ::Triangulation<1,spacedim>::MeshSmoothing
1021 
1025  virtual ~Triangulation ();
1026 
1033  const std::vector<types::global_dof_index> &
1035 
1069  void
1070  communicate_locally_moved_vertices (const std::vector<bool> &vertex_locally_moved);
1071 
1075  void load(const char *filename,
1076  const bool autopartition = true);
1077 
1081  void save(const char *filename) const;
1082 
1086  unsigned int
1087  register_data_attach (const std::size_t size,
1088  const std::function<void (const typename ::Triangulation<1,spacedim>::cell_iterator &,
1089  const typename ::Triangulation<1,spacedim>::CellStatus,
1090  void *)> &pack_callback);
1091 
1095  void
1096  notify_ready_to_unpack (const unsigned int offset,
1097  const std::function<void (const typename ::Triangulation<1,spacedim>::cell_iterator &,
1098  const typename ::Triangulation<1,spacedim>::CellStatus,
1099  const void *)> &unpack_callback);
1100 
1105  std::vector<types::global_dof_index> coarse_cell_to_p4est_tree_permutation;
1106  std::vector<types::global_dof_index> p4est_tree_to_coarse_cell_permutation;
1107 
1108 
1109 //TODO: The following variable should really be private, but it is used in dof_handler_policy.cc ...
1114 
1119  std::map<unsigned int, std::set<::types::subdomain_id> >
1121 
1126  std::map<unsigned int, std::set<::types::subdomain_id> >
1127  compute_level_vertices_with_ghost_neighbors (const unsigned int level) const;
1128 
1133  std::vector<bool>
1134  mark_locally_active_vertices_on_level(const unsigned int level) const;
1135 
1136  };
1137  }
1138 }
1139 
1140 
1141 #else // DEAL_II_WITH_P4EST
1142 
1143 namespace parallel
1144 {
1145  namespace distributed
1146  {
1158  template <int dim, int spacedim = dim>
1159  class Triangulation : public ::parallel::Triangulation<dim,spacedim>
1160  {
1161  public:
1166  Triangulation () = delete;
1167  };
1168  }
1169 }
1170 
1171 
1172 #endif
1173 
1174 
1175 DEAL_II_NAMESPACE_CLOSE
1176 
1177 #endif
std::vector< unsigned int > get_cell_weights()
Definition: tria.cc:3715
Definition: tria.h:67
typename ::internal::p4est::types< dim >::connectivity * connectivity
Definition: tria.h:828
std::vector< types::global_dof_index > coarse_cell_to_p4est_tree_permutation
Definition: tria.h:1105
std::vector< Point< spacedim > > vertices
Definition: tria.h:3587
virtual std::size_t memory_consumption() const
Definition: tria.cc:3575
virtual std::map< unsigned int, std::set<::types::subdomain_id > > compute_vertices_with_ghost_neighbors() const
Definition: tria.cc:3347
virtual std::size_t memory_consumption_p4est() const
Definition: tria.cc:3596
void load(const char *filename, const bool autopartition=true)
Definition: tria.cc:1835
const std::vector< types::global_dof_index > & get_p4est_tree_to_coarse_cell_permutation() const
Definition: tria.cc:3329
typename ::internal::p4est::types< dim >::ghost * parallel_ghost
Definition: tria.h:840
typename ::internal::p4est::types< dim >::forest * parallel_forest
Definition: tria.h:834
virtual void copy_triangulation(const ::Triangulation< dim, spacedim > &other_tria)
Definition: tria.cc:3607
virtual void create_triangulation(const std::vector< Point< spacedim > > &vertices, const std::vector< CellData< dim > > &cells, const SubCellData &subcelldata)
Definition: tria.cc:1337
virtual bool prepare_coarsening_and_refinement()
Definition: tria.cc:2452
virtual void add_periodicity(const std::vector<::GridTools::PeriodicFacePair< cell_iterator > > &)
Definition: tria.cc:3427
unsigned int register_data_attach(const std::size_t size, const std::function< void(const cell_iterator &, const CellStatus, void *)> &pack_callback)
Definition: tria.cc:3224
Definition: tria.h:76
const std::vector< types::global_dof_index > & get_coarse_cell_to_p4est_tree_permutation() const
Definition: tria.cc:3338
virtual bool has_hanging_nodes() const
Definition: tria.cc:1716
void copy_new_triangulation_to_p4est(std::integral_constant< int, 2 >)
void notify_ready_to_unpack(const unsigned int handle, const std::function< void(const cell_iterator &, const CellStatus, const void *)> &unpack_callback)
Definition: tria.cc:3248
void save(const char *filename) const
Definition: tria.cc:1775
typename ::internal::p4est::types< dim >::tree * init_tree(const int dealii_coarse_cell_index) const
Definition: tria.cc:1951
virtual void execute_coarsening_and_refinement()
Definition: tria.cc:2792
::Triangulation< dim, spacedim >::active_cell_iterator active_cell_iterator
Definition: tria.h:285
std::map< unsigned int, pack_callback_t > pack_callbacks
Definition: tria.h:880
void communicate_locally_moved_vertices(const std::vector< bool > &vertex_locally_moved)
Definition: tria.cc:3074
unsigned int get_checksum() const
Definition: tria.cc:1926
MeshSmoothing smooth_grid
Definition: tria.h:3325
void setup_coarse_cell_to_p4est_tree_permutation()
Definition: tria.cc:1745
::Triangulation< dim, spacedim >::cell_iterator cell_iterator
Definition: tria.h:265
Triangulation(MPI_Comm mpi_communicator, const typename ::Triangulation< dim, spacedim >::MeshSmoothing smooth_grid=(::Triangulation< dim, spacedim >::none), const Settings settings=default_setting)
Definition: tria.cc:1287
virtual void update_number_cache()
Definition: tria.cc:1938
std::vector< bool > mark_locally_active_vertices_on_level(const int level) const
Definition: tria.cc:3361
std::vector< types::global_dof_index > coarse_cell_to_p4est_tree_permutation
Definition: tria.h:898
void write_mesh_vtk(const char *file_basename) const
Definition: tria.cc:1762