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  {
327  };
328 
329 
330 
363  MPI_Comm mpi_communicator,
364  const typename ::Triangulation<dim, spacedim>::MeshSmoothing
367 
371  virtual ~Triangulation() override;
372 
379  virtual void
380  clear() override;
381 
391  virtual void
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
440 
447  virtual bool
449 
490  void
491  repartition();
492 
545  void
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
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
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> &
809 
815  const std::vector<types::global_dof_index> &
817 
825  const typename ::internal::p4est::types<dim>::forest *
826  get_p4est() const;
827 
847  virtual void
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
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
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
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
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
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,
1247  };
1248 
1253  Triangulation(
1254  MPI_Comm mpi_communicator,
1255  const typename ::Triangulation<1, spacedim>::MeshSmoothing
1258 
1262  virtual ~Triangulation() override;
1263 
1270  const std::vector<types::global_dof_index> &
1272 
1306  void
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
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
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
unsigned int register_data_attach(const std::function< std::vector< char >(const cell_iterator &, const CellStatus)> &pack_callback, const bool returns_variable_size_data)
Definition: tria.cc:4357
Definition: tria.h:71
typename ::internal::p4est::types< dim >::connectivity * connectivity
Definition: tria.h:876
void load(const std::string &filename, const bool autopartition=true)
Definition: tria.cc:2765
void save(const typename ::internal::p4est::types< dim >::forest *parallel_forest, const std::string &filename) const
Definition: tria.cc:1775
void unpack_cell_status(std::vector< quadrant_cell_relation_t > &quad_cell_relations) const
Definition: tria.cc:1572
std::vector< types::global_dof_index > coarse_cell_to_p4est_tree_permutation
Definition: tria.h:1354
void write_mesh_vtk(const std::string &file_basename) const
Definition: tria.cc:2672
std::vector< Point< spacedim > > vertices
Definition: tria.h:3963
virtual bool has_hanging_nodes() const override
Definition: tria.cc:2624
void pack_data(const std::vector< quadrant_cell_relation_t > &quad_cell_relations, const std::vector< typename CellAttachedData::pack_callback_t > &pack_callbacks_fixed, const std::vector< typename CellAttachedData::pack_callback_t > &pack_callbacks_variable)
Definition: tria.cc:1146
typename std::tuple< typename ::internal::p4est::types< dim >::quadrant *, CellStatus, cell_iterator > quadrant_cell_relation_t
Definition: tria.h:932
void save(const std::string &filename) const
Definition: tria.cc:2685
virtual std::size_t memory_consumption_p4est() const
Definition: tria.cc:4775
virtual std::size_t memory_consumption() const override
Definition: tria.cc:4747
const std::vector< types::global_dof_index > & get_p4est_tree_to_coarse_cell_permutation() const
Definition: tria.cc:4469
std::vector< unsigned int > get_cell_weights() const
Definition: tria.cc:4891
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
virtual bool prepare_coarsening_and_refinement() override
Definition: tria.cc:3431
void load(const typename ::internal::p4est::types< dim >::forest *parallel_forest, const std::string &filename, const unsigned int n_attached_deserialize_fixed, const unsigned int n_attached_deserialize_variable)
Definition: tria.cc:1950
const std::vector< types::global_dof_index > & get_coarse_cell_to_p4est_tree_permutation() const
Definition: tria.cc:4479
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 boost::iterator_range< std::vector< char >::const_iterator > &)> &unpack_callback)
Definition: tria.cc:4387
typename ::internal::p4est::types< dim >::tree * init_tree(const int dealii_coarse_cell_index) const
Definition: tria.cc:2915
std::vector< pack_callback_t > pack_callbacks_fixed
Definition: tria.h:917
virtual void update_number_cache() override
Definition: tria.cc:2903
std::vector< quadrant_cell_relation_t > local_quadrant_cell_relations
Definition: tria.h:942
void communicate_locally_moved_vertices(const std::vector< bool > &vertex_locally_moved)
Definition: tria.cc:4186
void unpack_data(const std::vector< quadrant_cell_relation_t > &quad_cell_relations, const unsigned int handle, const std::function< void(const typename ::Triangulation< dim, spacedim >::cell_iterator &, const typename ::Triangulation< dim, spacedim >::CellStatus &, const boost::iterator_range< std::vector< char >::const_iterator > &)> &unpack_callback) const
Definition: tria.cc:1608
virtual ~Triangulation() override
Definition: tria.cc:2174
unsigned int get_checksum() const
Definition: tria.cc:2880
MeshSmoothing smooth_grid
Definition: tria.h:3568
void setup_coarse_cell_to_p4est_tree_permutation()
Definition: tria.cc:2655
void execute_transfer(const typename ::internal::p4est::types< dim >::forest *parallel_forest, const typename ::internal::p4est::types< dim >::gloidx *previous_global_first_quadrant)
Definition: tria.cc:1479
virtual void copy_triangulation(const ::Triangulation< dim, spacedim > &other_tria) override
Definition: tria.cc:4787
std::vector< unsigned int > sizes_fixed_cumulative
Definition: tria.h:1111
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:2144
virtual void execute_coarsening_and_refinement() override
Definition: tria.cc:3820
typename ::Triangulation< dim, spacedim >::cell_iterator cell_iterator
Definition: tria.h:269
virtual void create_triangulation(const std::vector< Point< spacedim >> &vertices, const std::vector< CellData< dim >> &cells, const SubCellData &subcelldata) override
Definition: tria.cc:2195
std::vector< bool > mark_locally_active_vertices_on_level(const int level) const
Definition: tria.cc:4502
const ::internal::p4est::types< dim >::forest * get_p4est() const
Definition: tria.cc:2892
std::vector< types::global_dof_index > coarse_cell_to_p4est_tree_permutation
Definition: tria.h:1146
virtual void clear() override
Definition: tria.cc:2585
virtual std::map< unsigned int, std::set<::types::subdomain_id > > compute_vertices_with_ghost_neighbors() const override
Definition: tria.cc:4489
virtual void add_periodicity(const std::vector<::GridTools::PeriodicFacePair< cell_iterator >> &) override
Definition: tria.cc:4578