Reference documentation for deal.II version Git 3d170a2f6b 2020-04-03 17:03:45 -0400
\(\newcommand{\vcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\vcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
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 // Forward declarations
60 # ifndef DOXYGEN
61 
62 namespace FETools
63 {
64  namespace internal
65  {
66  template <int, int, class>
67  class ExtrapolateImplementation;
68  }
69 } // namespace FETools
70 
71 // forward declaration of the data type for periodic face pairs
72 namespace GridTools
73 {
74  template <typename CellIterator>
75  struct PeriodicFacePair;
76 }
77 # endif
78 
79 namespace parallel
80 {
81  namespace distributed
82  {
241  template <int dim, int spacedim = dim>
243  : public ::parallel::DistributedTriangulationBase<dim, spacedim>
244  {
245  public:
263  using cell_iterator =
264  typename ::Triangulation<dim, spacedim>::cell_iterator;
265 
284  using active_cell_iterator =
285  typename ::Triangulation<dim, spacedim>::active_cell_iterator;
286 
287  using CellStatus =
288  typename ::Triangulation<dim, spacedim>::CellStatus;
289 
294  enum Settings
295  {
299  default_setting = 0x0,
308  mesh_reconstruction_after_repartitioning = 0x1,
314  construct_multigrid_hierarchy = 0x2,
320  no_automatic_repartitioning = 0x4
321  };
322 
323 
324 
356  explicit Triangulation(
357  MPI_Comm mpi_communicator,
358  const typename ::Triangulation<dim, spacedim>::MeshSmoothing
359  smooth_grid = (::Triangulation<dim, spacedim>::none),
360  const Settings settings = default_setting);
361 
365  virtual ~Triangulation() override;
366 
373  virtual void
374  clear() override;
375 
379  bool
380  is_multilevel_hierarchy_constructed() const 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 
409  /*
410  * @copydoc Triangulation::create_triangulation()
411  *
412  * @note Not inmplemented yet.
413  */
414  virtual void
415  create_triangulation(
417  &construction_data) override;
418 
448  virtual void
449  execute_coarsening_and_refinement() override;
450 
457  virtual bool
458  prepare_coarsening_and_refinement() override;
459 
500  void
501  repartition();
502 
555  void
556  communicate_locally_moved_vertices(
557  const std::vector<bool> &vertex_locally_moved);
558 
559 
575  virtual bool
576  has_hanging_nodes() const override;
577 
581  virtual std::size_t
582  memory_consumption() const override;
583 
589  virtual std::size_t
590  memory_consumption_p4est() const;
591 
599  void
600  write_mesh_vtk(const std::string &file_basename) const;
601 
606  unsigned int
607  get_checksum() const;
608 
616  void
617  save(const std::string &filename) const;
618 
637  void
638  load(const std::string &filename, const bool autopartition = true);
639 
748  unsigned int
749  register_data_attach(
750  const std::function<std::vector<char>(const cell_iterator &,
751  const CellStatus)> &pack_callback,
752  const bool returns_variable_size_data);
753 
802  void
803  notify_ready_to_unpack(
804  const unsigned int handle,
805  const std::function<void(
806  const cell_iterator &,
807  const CellStatus,
808  const boost::iterator_range<std::vector<char>::const_iterator> &)>
809  &unpack_callback);
810 
817  const std::vector<types::global_dof_index> &
818  get_p4est_tree_to_coarse_cell_permutation() const;
819 
825  const std::vector<types::global_dof_index> &
826  get_coarse_cell_to_p4est_tree_permutation() const;
827 
835  const typename ::internal::p4est::types<dim>::forest *
836  get_p4est() const;
837 
857  virtual void
858  add_periodicity(
859  const std::vector<::GridTools::PeriodicFacePair<cell_iterator>> &)
860  override;
861 
862 
863  private:
868  virtual void
869  update_number_cache() override;
870 
875 
880 
886  typename ::internal::p4est::types<dim>::connectivity *connectivity;
887 
892  typename ::internal::p4est::types<dim>::forest *parallel_forest;
893 
898  typename ::internal::p4est::types<dim>::ghost *parallel_ghost;
899 
906  {
911  unsigned int n_attached_data_sets;
912 
918 
919  using pack_callback_t = std::function<std::vector<char>(
921  CellStatus)>;
922 
927  std::vector<pack_callback_t> pack_callbacks_fixed;
928  std::vector<pack_callback_t> pack_callbacks_variable;
929  };
930 
931  CellAttachedData cell_attached_data;
932 
939  using quadrant_cell_relation_t = typename std::tuple<
940  typename ::internal::p4est::types<dim>::quadrant *,
941  CellStatus,
943 
952  std::vector<quadrant_cell_relation_t> local_quadrant_cell_relations;
953 
963  void
964  update_quadrant_cell_relations();
965 
976  {
977  public:
978  DataTransfer(MPI_Comm mpi_communicator);
979 
989  void
990  pack_data(
991  const std::vector<quadrant_cell_relation_t> &quad_cell_relations,
992  const std::vector<typename CellAttachedData::pack_callback_t>
993  &pack_callbacks_fixed,
994  const std::vector<typename CellAttachedData::pack_callback_t>
995  &pack_callbacks_variable);
996 
1009  void
1010  execute_transfer(
1011  const typename ::internal::p4est::types<dim>::forest
1012  *parallel_forest,
1013  const typename ::internal::p4est::types<dim>::gloidx
1014  *previous_global_first_quadrant);
1015 
1023  void
1024  unpack_cell_status(
1025  std::vector<quadrant_cell_relation_t> &quad_cell_relations) const;
1026 
1039  void
1040  unpack_data(
1041  const std::vector<quadrant_cell_relation_t> &quad_cell_relations,
1042  const unsigned int handle,
1043  const std::function<void(
1044  const typename ::Triangulation<dim, spacedim>::cell_iterator
1045  &,
1046  const typename ::Triangulation<dim, spacedim>::CellStatus &,
1047  const boost::iterator_range<std::vector<char>::const_iterator> &)>
1048  &unpack_callback) const;
1049 
1064  void
1065  save(const typename ::internal::p4est::types<dim>::forest
1066  * parallel_forest,
1067  const std::string &filename) const;
1068 
1087  void
1088  load(const typename ::internal::p4est::types<dim>::forest
1089  * parallel_forest,
1090  const std::string &filename,
1091  const unsigned int n_attached_deserialize_fixed,
1092  const unsigned int n_attached_deserialize_variable);
1093 
1100  void
1101  clear();
1102 
1103  private:
1104  MPI_Comm mpi_communicator;
1105 
1110 
1121  std::vector<unsigned int> sizes_fixed_cumulative;
1122 
1127  std::vector<char> src_data_fixed;
1128  std::vector<char> dest_data_fixed;
1129 
1134  std::vector<int> src_sizes_variable;
1135  std::vector<int> dest_sizes_variable;
1136  std::vector<char> src_data_variable;
1137  std::vector<char> dest_data_variable;
1138  };
1139 
1140  DataTransfer data_transfer;
1141 
1155  std::vector<types::global_dof_index>
1157  std::vector<types::global_dof_index>
1158  p4est_tree_to_coarse_cell_permutation;
1159 
1164  typename ::internal::p4est::types<dim>::tree *
1165  init_tree(const int dealii_coarse_cell_index) const;
1166 
1171  void
1172  setup_coarse_cell_to_p4est_tree_permutation();
1173 
1180  void
1181  copy_new_triangulation_to_p4est(std::integral_constant<int, 2>);
1182  void
1183  copy_new_triangulation_to_p4est(std::integral_constant<int, 3>);
1184 
1189  void
1190  copy_local_forest_to_triangulation();
1191 
1205  std::vector<unsigned int>
1206  get_cell_weights() const;
1207 
1217  std::vector<bool>
1218  mark_locally_active_vertices_on_level(const int level) const;
1219 
1220  virtual unsigned int
1221  coarse_cell_id_to_coarse_cell_index(
1222  const types::coarse_cell_id coarse_cell_id) const override;
1223 
1224  virtual types::coarse_cell_id
1225  coarse_cell_index_to_coarse_cell_id(
1226  const unsigned int coarse_cell_index) const override;
1227 
1228  template <int, int, class>
1229  friend class ::FETools::internal::ExtrapolateImplementation;
1230  };
1231 
1232 
1238  template <int spacedim>
1239  class Triangulation<1, spacedim>
1240  : public ::parallel::DistributedTriangulationBase<1, spacedim>
1241  {
1242  public:
1247  {
1248  default_setting = 0x0,
1249  mesh_reconstruction_after_repartitioning = 0x1,
1250  construct_multigrid_hierarchy = 0x2
1251  };
1252 
1257  Triangulation(
1258  MPI_Comm mpi_communicator,
1259  const typename ::Triangulation<1, spacedim>::MeshSmoothing
1260  smooth_grid = (::Triangulation<1, spacedim>::none),
1261  const Settings settings = default_setting);
1262 
1266  virtual ~Triangulation() override;
1267 
1274  const std::vector<types::global_dof_index> &
1275  get_p4est_tree_to_coarse_cell_permutation() const;
1276 
1310  void
1311  communicate_locally_moved_vertices(
1312  const std::vector<bool> &vertex_locally_moved);
1313 
1318  void
1319  load(const std::string &filename, const bool autopartition = true);
1320 
1325  void
1326  save(const std::string &filename) const;
1327 
1328  bool
1329  is_multilevel_hierarchy_constructed() const override;
1330 
1335  unsigned int
1336  register_data_attach(
1337  const std::function<std::vector<char>(
1338  const typename ::Triangulation<1, spacedim>::cell_iterator &,
1339  const typename ::Triangulation<1, spacedim>::CellStatus)>
1340  & pack_callback,
1341  const bool returns_variable_size_data);
1342 
1347  void
1348  notify_ready_to_unpack(
1349  const unsigned int handle,
1350  const std::function<void(
1351  const typename ::Triangulation<1, spacedim>::cell_iterator &,
1352  const typename ::Triangulation<1, spacedim>::CellStatus,
1353  const boost::iterator_range<std::vector<char>::const_iterator> &)>
1354  &unpack_callback);
1355 
1360  std::vector<types::global_dof_index>
1362  std::vector<types::global_dof_index>
1363  p4est_tree_to_coarse_cell_permutation;
1364 
1365 
1366  // TODO: The following variable should really be private, but it is used
1367  // in dof_handler_policy.cc ...
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  virtual unsigned int
1389  coarse_cell_id_to_coarse_cell_index(
1390  const types::coarse_cell_id coarse_cell_id) const override;
1391 
1392  virtual types::coarse_cell_id
1393  coarse_cell_index_to_coarse_cell_id(
1394  const unsigned int coarse_cell_index) const override;
1395  };
1396  } // namespace distributed
1397 } // namespace parallel
1398 
1399 
1400 #else // DEAL_II_WITH_P4EST
1401 
1402 namespace parallel
1403 {
1404  namespace distributed
1405  {
1417  template <int dim, int spacedim = dim>
1418  class Triangulation
1419  : public ::parallel::TriangulationBase<dim, spacedim>
1420  {
1421  public:
1426  Triangulation() = delete;
1427  };
1428  } // namespace distributed
1429 } // namespace parallel
1430 
1431 
1432 #endif
1433 
1434 
1435 DEAL_II_NAMESPACE_CLOSE
1436 
1437 #endif
typename ::internal::p4est::types< dim >::connectivity * connectivity
Definition: tria.h:886
std::vector< types::global_dof_index > coarse_cell_to_p4est_tree_permutation
Definition: tria.h:1361
typename std::tuple< typename ::internal::p4est::types< dim >::quadrant *, CellStatus, cell_iterator > quadrant_cell_relation_t
Definition: tria.h:942
typename ::internal::p4est::types< dim >::ghost * parallel_ghost
Definition: tria.h:898
typename ::internal::p4est::types< dim >::forest * parallel_forest
Definition: tria.h:892
std::vector< pack_callback_t > pack_callbacks_fixed
Definition: tria.h:927
std::vector< quadrant_cell_relation_t > local_quadrant_cell_relations
Definition: tria.h:952
std::vector< unsigned int > sizes_fixed_cumulative
Definition: tria.h:1121
typename ::Triangulation< dim, spacedim >::cell_iterator cell_iterator
Definition: tria.h:264
global_cell_index coarse_cell_id
Definition: types.h:113
std::vector< types::global_dof_index > coarse_cell_to_p4est_tree_permutation
Definition: tria.h:1156