Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
tria.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2008 - 2019 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.md at
12 // the top level directory of deal.II.
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 
22 #include <deal.II/base/smartpointer.h>
23 #include <deal.II/base/subscriptor.h>
24 #include <deal.II/base/template_constraints.h>
25 
26 #include <deal.II/distributed/p4est_wrappers.h>
27 #include <deal.II/distributed/tria_base.h>
28 
29 #include <deal.II/grid/tria.h>
30 
31 #include <boost/range/iterator_range.hpp>
32 
33 #include <functional>
34 #include <list>
35 #include <set>
36 #include <tuple>
37 #include <type_traits>
38 #include <utility>
39 #include <vector>
40 
41 #ifdef DEAL_II_WITH_MPI
42 # include <mpi.h>
43 #endif
44 
45 #ifdef DEAL_II_WITH_P4EST
46 # include <p4est.h>
47 # include <p4est_connectivity.h>
48 # include <p4est_ghost.h>
49 # include <p8est.h>
50 # include <p8est_connectivity.h>
51 # include <p8est_ghost.h>
52 #endif
53 
54 
55 DEAL_II_NAMESPACE_OPEN
56 
57 #ifdef DEAL_II_WITH_P4EST
58 
59 namespace internal
60 {
61  namespace DoFHandlerImplementation
62  {
63  namespace Policy
64  {
65  template <typename>
67  }
68  } // namespace DoFHandlerImplementation
69 } // namespace internal
70 
71 namespace FETools
72 {
73  namespace internal
74  {
75  template <int, int, class>
76  class ExtrapolateImplementation;
77  }
78 } // namespace FETools
79 
80 // forward declaration of the data type for periodic face pairs
81 namespace GridTools
82 {
83  template <typename CellIterator>
85 }
86 
87 namespace parallel
88 {
89  namespace distributed
90  {
247  template <int dim, int spacedim = dim>
248  class Triangulation : public ::parallel::Triangulation<dim, spacedim>
249  {
250  public:
268  using cell_iterator =
269  typename ::Triangulation<dim, spacedim>::cell_iterator;
270 
289  using active_cell_iterator =
290  typename ::Triangulation<dim, spacedim>::active_cell_iterator;
291 
292  using CellStatus =
293  typename ::Triangulation<dim, spacedim>::CellStatus;
294 
299  enum Settings
300  {
304  default_setting = 0x0,
313  mesh_reconstruction_after_repartitioning = 0x1,
320  construct_multigrid_hierarchy = 0x2,
326  no_automatic_repartitioning = 0x4
327  };
328 
329 
330 
363  MPI_Comm mpi_communicator,
364  const typename ::Triangulation<dim, spacedim>::MeshSmoothing
365  smooth_grid = (::Triangulation<dim, spacedim>::none),
366  const Settings settings = default_setting);
367 
371  virtual ~Triangulation() override;
372 
379  virtual void
380  clear() override;
381 
391  virtual void
392  copy_triangulation(
393  const ::Triangulation<dim, spacedim> &other_tria) override;
394 
404  virtual void
405  create_triangulation(const std::vector<Point<spacedim>> &vertices,
406  const std::vector<CellData<dim>> & cells,
407  const SubCellData &subcelldata) override;
408 
438  virtual void
439  execute_coarsening_and_refinement() override;
440 
447  virtual bool
448  prepare_coarsening_and_refinement() override;
449 
490  void
491  repartition();
492 
545  void
546  communicate_locally_moved_vertices(
547  const std::vector<bool> &vertex_locally_moved);
548 
549 
565  virtual bool
566  has_hanging_nodes() const override;
567 
571  virtual std::size_t
572  memory_consumption() const override;
573 
579  virtual std::size_t
580  memory_consumption_p4est() const;
581 
589  void
590  write_mesh_vtk(const std::string &file_basename) const;
591 
596  unsigned int
597  get_checksum() const;
598 
606  void
607  save(const std::string &filename) const;
608 
627  void
628  load(const std::string &filename, const bool autopartition = true);
629 
738  unsigned int
739  register_data_attach(
740  const std::function<std::vector<char>(const cell_iterator &,
741  const CellStatus)> &pack_callback,
742  const bool returns_variable_size_data);
743 
792  void
793  notify_ready_to_unpack(
794  const unsigned int handle,
795  const std::function<void(
796  const cell_iterator &,
797  const CellStatus,
798  const boost::iterator_range<std::vector<char>::const_iterator> &)>
799  &unpack_callback);
800 
807  const std::vector<types::global_dof_index> &
808  get_p4est_tree_to_coarse_cell_permutation() const;
809 
815  const std::vector<types::global_dof_index> &
816  get_coarse_cell_to_p4est_tree_permutation() const;
817 
825  const typename ::internal::p4est::types<dim>::forest *
826  get_p4est() const;
827 
847  virtual void
848  add_periodicity(
849  const std::vector<::GridTools::PeriodicFacePair<cell_iterator>> &)
850  override;
851 
852 
853  private:
858  virtual void
859  update_number_cache() override;
860 
865 
870 
876  typename ::internal::p4est::types<dim>::connectivity *connectivity;
877 
882  typename ::internal::p4est::types<dim>::forest *parallel_forest;
883 
888  typename ::internal::p4est::types<dim>::ghost *parallel_ghost;
889 
896  {
901  unsigned int n_attached_data_sets;
902 
908 
909  using pack_callback_t = std::function<std::vector<char>(
911  CellStatus)>;
912 
917  std::vector<pack_callback_t> pack_callbacks_fixed;
918  std::vector<pack_callback_t> pack_callbacks_variable;
919  };
920 
921  CellAttachedData cell_attached_data;
922 
929  using quadrant_cell_relation_t = typename std::tuple<
930  typename ::internal::p4est::types<dim>::quadrant *,
931  CellStatus,
933 
942  std::vector<quadrant_cell_relation_t> local_quadrant_cell_relations;
943 
953  void
954  update_quadrant_cell_relations();
955 
966  {
967  public:
968  DataTransfer(MPI_Comm mpi_communicator);
969 
979  void
980  pack_data(
981  const std::vector<quadrant_cell_relation_t> &quad_cell_relations,
982  const std::vector<typename CellAttachedData::pack_callback_t>
983  &pack_callbacks_fixed,
984  const std::vector<typename CellAttachedData::pack_callback_t>
985  &pack_callbacks_variable);
986 
999  void
1000  execute_transfer(
1001  const typename ::internal::p4est::types<dim>::forest
1002  *parallel_forest,
1003  const typename ::internal::p4est::types<dim>::gloidx
1004  *previous_global_first_quadrant);
1005 
1013  void
1014  unpack_cell_status(
1015  std::vector<quadrant_cell_relation_t> &quad_cell_relations) const;
1016 
1029  void
1030  unpack_data(
1031  const std::vector<quadrant_cell_relation_t> &quad_cell_relations,
1032  const unsigned int handle,
1033  const std::function<void(
1034  const typename ::Triangulation<dim, spacedim>::cell_iterator
1035  &,
1036  const typename ::Triangulation<dim, spacedim>::CellStatus &,
1037  const boost::iterator_range<std::vector<char>::const_iterator> &)>
1038  &unpack_callback) const;
1039 
1054  void
1055  save(const typename ::internal::p4est::types<dim>::forest
1056  * parallel_forest,
1057  const std::string &filename) const;
1058 
1077  void
1078  load(const typename ::internal::p4est::types<dim>::forest
1079  * parallel_forest,
1080  const std::string &filename,
1081  const unsigned int n_attached_deserialize_fixed,
1082  const unsigned int n_attached_deserialize_variable);
1083 
1090  void
1091  clear();
1092 
1093  private:
1094  MPI_Comm mpi_communicator;
1095 
1100 
1111  std::vector<unsigned int> sizes_fixed_cumulative;
1112 
1117  std::vector<char> src_data_fixed;
1118  std::vector<char> dest_data_fixed;
1119 
1124  std::vector<int> src_sizes_variable;
1125  std::vector<int> dest_sizes_variable;
1126  std::vector<char> src_data_variable;
1127  std::vector<char> dest_data_variable;
1128  };
1129 
1130  DataTransfer data_transfer;
1131 
1145  std::vector<types::global_dof_index>
1147  std::vector<types::global_dof_index>
1148  p4est_tree_to_coarse_cell_permutation;
1149 
1154  typename ::internal::p4est::types<dim>::tree *
1155  init_tree(const int dealii_coarse_cell_index) const;
1156 
1161  void
1162  setup_coarse_cell_to_p4est_tree_permutation();
1163 
1170  void
1171  copy_new_triangulation_to_p4est(std::integral_constant<int, 2>);
1172  void
1173  copy_new_triangulation_to_p4est(std::integral_constant<int, 3>);
1174 
1179  void
1180  copy_local_forest_to_triangulation();
1181 
1195  std::vector<unsigned int>
1196  get_cell_weights() const;
1197 
1205  virtual std::map<unsigned int, std::set<::types::subdomain_id>>
1206  compute_vertices_with_ghost_neighbors() const override;
1207 
1217  std::vector<bool>
1218  mark_locally_active_vertices_on_level(const int level) const;
1219 
1220  template <typename>
1221  friend class ::internal::DoFHandlerImplementation::Policy::
1222  ParallelDistributed;
1223 
1224  template <int, int, class>
1225  friend class ::FETools::internal::ExtrapolateImplementation;
1226  };
1227 
1228 
1234  template <int spacedim>
1235  class Triangulation<1, spacedim>
1236  : public ::parallel::Triangulation<1, spacedim>
1237  {
1238  public:
1243  {
1244  default_setting = 0x0,
1245  mesh_reconstruction_after_repartitioning = 0x1,
1246  construct_multigrid_hierarchy = 0x2
1247  };
1248 
1253  Triangulation(
1254  MPI_Comm mpi_communicator,
1255  const typename ::Triangulation<1, spacedim>::MeshSmoothing
1256  smooth_grid = (::Triangulation<1, spacedim>::none),
1257  const Settings settings = default_setting);
1258 
1262  virtual ~Triangulation() override;
1263 
1270  const std::vector<types::global_dof_index> &
1271  get_p4est_tree_to_coarse_cell_permutation() const;
1272 
1306  void
1307  communicate_locally_moved_vertices(
1308  const std::vector<bool> &vertex_locally_moved);
1309 
1314  void
1315  load(const std::string &filename, const bool autopartition = true);
1316 
1321  void
1322  save(const std::string &filename) const;
1323 
1328  unsigned int
1329  register_data_attach(
1330  const std::function<std::vector<char>(
1331  const typename ::Triangulation<1, spacedim>::cell_iterator &,
1332  const typename ::Triangulation<1, spacedim>::CellStatus)>
1333  & pack_callback,
1334  const bool returns_variable_size_data);
1335 
1340  void
1341  notify_ready_to_unpack(
1342  const unsigned int handle,
1343  const std::function<void(
1344  const typename ::Triangulation<1, spacedim>::cell_iterator &,
1345  const typename ::Triangulation<1, spacedim>::CellStatus,
1346  const boost::iterator_range<std::vector<char>::const_iterator> &)>
1347  &unpack_callback);
1348 
1353  std::vector<types::global_dof_index>
1355  std::vector<types::global_dof_index>
1356  p4est_tree_to_coarse_cell_permutation;
1357 
1358 
1359  // TODO: The following variable should really be private, but it is used
1360  // in dof_handler_policy.cc ...
1365 
1370  virtual std::map<unsigned int, std::set<::types::subdomain_id>>
1371  compute_vertices_with_ghost_neighbors() const override;
1372 
1377  virtual std::map<unsigned int, std::set<::types::subdomain_id>>
1378  compute_level_vertices_with_ghost_neighbors(
1379  const unsigned int level) const;
1380 
1385  virtual std::vector<bool>
1386  mark_locally_active_vertices_on_level(const unsigned int level) const;
1387  };
1388  } // namespace distributed
1389 } // namespace parallel
1390 
1391 
1392 #else // DEAL_II_WITH_P4EST
1393 
1394 namespace parallel
1395 {
1396  namespace distributed
1397  {
1409  template <int dim, int spacedim = dim>
1410  class Triangulation : public ::parallel::Triangulation<dim, spacedim>
1411  {
1412  public:
1417  Triangulation() = delete;
1418  };
1419  } // namespace distributed
1420 } // namespace parallel
1421 
1422 
1423 #endif
1424 
1425 
1426 DEAL_II_NAMESPACE_CLOSE
1427 
1428 #endif
Definition: tria.h:71
typename ::internal::p4est::types< dim >::connectivity * connectivity
Definition: tria.h:876
std::vector< types::global_dof_index > coarse_cell_to_p4est_tree_permutation
Definition: tria.h:1354
typename std::tuple< typename ::internal::p4est::types< dim >::quadrant *, CellStatus, cell_iterator > quadrant_cell_relation_t
Definition: tria.h:932
typename ::internal::p4est::types< dim >::ghost * parallel_ghost
Definition: tria.h:888
typename ::internal::p4est::types< dim >::forest * parallel_forest
Definition: tria.h:882
Definition: tria.h:81
std::vector< pack_callback_t > pack_callbacks_fixed
Definition: tria.h:917
std::vector< quadrant_cell_relation_t > local_quadrant_cell_relations
Definition: tria.h:942
std::vector< unsigned int > sizes_fixed_cumulative
Definition: tria.h:1111
typename ::Triangulation< dim, spacedim >::cell_iterator cell_iterator
Definition: tria.h:269
std::vector< types::global_dof_index > coarse_cell_to_p4est_tree_permutation
Definition: tria.h:1146