Reference documentation for deal.II version Git e3a3ec7800 2020-08-07 14:08:19 +0200
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
tria.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2008 - 2020 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 
25 
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 
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  {
240  template <int dim, int spacedim = dim>
242  : public ::parallel::DistributedTriangulationBase<dim, spacedim>
243  {
244  public:
262  using cell_iterator =
263  typename ::Triangulation<dim, spacedim>::cell_iterator;
264 
283  using active_cell_iterator =
284  typename ::Triangulation<dim, spacedim>::active_cell_iterator;
285 
286  using CellStatus =
287  typename ::Triangulation<dim, spacedim>::CellStatus;
288 
293  enum Settings
294  {
307  mesh_reconstruction_after_repartitioning = 0x1,
319  no_automatic_repartitioning = 0x4
320  };
321 
322 
323 
355  explicit Triangulation(
356  MPI_Comm mpi_communicator,
357  const typename ::Triangulation<dim, spacedim>::MeshSmoothing
358  smooth_grid = (::Triangulation<dim, spacedim>::none),
359  const Settings settings = default_setting);
360 
364  virtual ~Triangulation() override;
365 
372  virtual void
373  clear() override;
374 
378  bool
379  is_multilevel_hierarchy_constructed() const override;
380 
390  virtual void
391  copy_triangulation(
392  const ::Triangulation<dim, spacedim> &other_tria) override;
393 
403  virtual void
404  create_triangulation(const std::vector<Point<spacedim>> &vertices,
405  const std::vector<CellData<dim>> & cells,
406  const SubCellData &subcelldata) override;
407 
408  /*
409  * @copydoc Triangulation::create_triangulation()
410  *
411  * @note Not inmplemented yet.
412  */
413  virtual void
416  &construction_data) override;
417 
447  virtual void
448  execute_coarsening_and_refinement() override;
449 
456  virtual bool
457  prepare_coarsening_and_refinement() override;
458 
499  void
500  repartition();
501 
554  void
555  communicate_locally_moved_vertices(
556  const std::vector<bool> &vertex_locally_moved);
557 
558 
574  virtual bool
575  has_hanging_nodes() const override;
576 
580  virtual std::size_t
581  memory_consumption() const override;
582 
588  virtual std::size_t
589  memory_consumption_p4est() const;
590 
598  void
599  write_mesh_vtk(const std::string &file_basename) const;
600 
605  unsigned int
606  get_checksum() const;
607 
615  void
616  save(const std::string &filename) const;
617 
636  void
637  load(const std::string &filename, const bool autopartition = true);
638 
747  unsigned int
748  register_data_attach(
749  const std::function<std::vector<char>(const cell_iterator &,
750  const CellStatus)> &pack_callback,
751  const bool returns_variable_size_data);
752 
801  void
802  notify_ready_to_unpack(
803  const unsigned int handle,
804  const std::function<void(
805  const cell_iterator &,
806  const CellStatus,
807  const boost::iterator_range<std::vector<char>::const_iterator> &)>
808  &unpack_callback);
809 
816  const std::vector<types::global_dof_index> &
817  get_p4est_tree_to_coarse_cell_permutation() const;
818 
824  const std::vector<types::global_dof_index> &
825  get_coarse_cell_to_p4est_tree_permutation() const;
826 
834  const typename ::internal::p4est::types<dim>::forest *
835  get_p4est() const;
836 
856  virtual void
857  add_periodicity(
858  const std::vector<::GridTools::PeriodicFacePair<cell_iterator>> &)
859  override;
860 
861 
862  private:
867 
872 
878  typename ::internal::p4est::types<dim>::connectivity *connectivity;
879 
884  typename ::internal::p4est::types<dim>::forest *parallel_forest;
885 
890  typename ::internal::p4est::types<dim>::ghost *parallel_ghost;
891 
898  {
903  unsigned int n_attached_data_sets;
904 
910 
911  using pack_callback_t = std::function<std::vector<char>(
914 
919  std::vector<pack_callback_t> pack_callbacks_fixed;
920  std::vector<pack_callback_t> pack_callbacks_variable;
921  };
922 
923  CellAttachedData cell_attached_data;
924 
931  using quadrant_cell_relation_t = typename std::tuple<
932  typename ::internal::p4est::types<dim>::quadrant *,
933  CellStatus,
935 
944  std::vector<quadrant_cell_relation_t> local_quadrant_cell_relations;
945 
955  void
956  update_quadrant_cell_relations();
957 
968  {
969  public:
970  DataTransfer(MPI_Comm mpi_communicator);
971 
981  void
982  pack_data(
983  const std::vector<quadrant_cell_relation_t> &quad_cell_relations,
984  const std::vector<typename CellAttachedData::pack_callback_t>
985  &pack_callbacks_fixed,
986  const std::vector<typename CellAttachedData::pack_callback_t>
987  &pack_callbacks_variable);
988 
1001  void
1002  execute_transfer(
1003  const typename ::internal::p4est::types<dim>::forest
1004  *parallel_forest,
1005  const typename ::internal::p4est::types<dim>::gloidx
1006  *previous_global_first_quadrant);
1007 
1015  void
1016  unpack_cell_status(
1017  std::vector<quadrant_cell_relation_t> &quad_cell_relations) const;
1018 
1031  void
1032  unpack_data(
1033  const std::vector<quadrant_cell_relation_t> &quad_cell_relations,
1034  const unsigned int handle,
1035  const std::function<void(
1036  const typename ::Triangulation<dim, spacedim>::cell_iterator
1037  &,
1038  const typename ::Triangulation<dim, spacedim>::CellStatus &,
1039  const boost::iterator_range<std::vector<char>::const_iterator> &)>
1040  &unpack_callback) const;
1041 
1056  void
1057  save(const typename ::internal::p4est::types<dim>::forest
1058  * parallel_forest,
1059  const std::string &filename) const;
1060 
1079  void
1080  load(const typename ::internal::p4est::types<dim>::forest
1081  * parallel_forest,
1082  const std::string &filename,
1083  const unsigned int n_attached_deserialize_fixed,
1084  const unsigned int n_attached_deserialize_variable);
1085 
1092  void
1093  clear();
1094 
1095  private:
1097 
1102 
1113  std::vector<unsigned int> sizes_fixed_cumulative;
1114 
1119  std::vector<char> src_data_fixed;
1120  std::vector<char> dest_data_fixed;
1121 
1126  std::vector<int> src_sizes_variable;
1127  std::vector<int> dest_sizes_variable;
1128  std::vector<char> src_data_variable;
1129  std::vector<char> dest_data_variable;
1130  };
1131 
1132  DataTransfer data_transfer;
1133 
1147  std::vector<types::global_dof_index>
1149  std::vector<types::global_dof_index>
1151 
1156  typename ::internal::p4est::types<dim>::tree *
1157  init_tree(const int dealii_coarse_cell_index) const;
1158 
1163  void
1164  setup_coarse_cell_to_p4est_tree_permutation();
1165 
1172  void
1173  copy_new_triangulation_to_p4est(std::integral_constant<int, 2>);
1174  void
1175  copy_new_triangulation_to_p4est(std::integral_constant<int, 3>);
1176 
1181  void
1182  copy_local_forest_to_triangulation();
1183 
1197  std::vector<unsigned int>
1198  get_cell_weights() const;
1199 
1209  std::vector<bool>
1210  mark_locally_active_vertices_on_level(const int level) const;
1211 
1212  virtual unsigned int
1213  coarse_cell_id_to_coarse_cell_index(
1214  const types::coarse_cell_id coarse_cell_id) const override;
1215 
1216  virtual types::coarse_cell_id
1217  coarse_cell_index_to_coarse_cell_id(
1218  const unsigned int coarse_cell_index) const override;
1219 
1220  template <int, int, class>
1221  friend class ::FETools::internal::ExtrapolateImplementation;
1222  };
1223 
1224 
1230  template <int spacedim>
1231  class Triangulation<1, spacedim>
1232  : public ::parallel::DistributedTriangulationBase<1, spacedim>
1233  {
1234  public:
1239  {
1241  mesh_reconstruction_after_repartitioning = 0x1,
1243  };
1244 
1249  Triangulation(
1250  MPI_Comm mpi_communicator,
1251  const typename ::Triangulation<1, spacedim>::MeshSmoothing
1252  smooth_grid = (::Triangulation<1, spacedim>::none),
1253  const Settings settings = default_setting);
1254 
1258  virtual ~Triangulation() override;
1259 
1266  const std::vector<types::global_dof_index> &
1267  get_p4est_tree_to_coarse_cell_permutation() const;
1268 
1302  void
1303  communicate_locally_moved_vertices(
1304  const std::vector<bool> &vertex_locally_moved);
1305 
1310  void
1311  load(const std::string &filename, const bool autopartition = true);
1312 
1317  void
1318  save(const std::string &filename) const;
1319 
1320  bool
1321  is_multilevel_hierarchy_constructed() const override;
1322 
1327  unsigned int
1328  register_data_attach(
1329  const std::function<std::vector<char>(
1330  const typename ::Triangulation<1, spacedim>::cell_iterator &,
1331  const typename ::Triangulation<1, spacedim>::CellStatus)>
1332  & pack_callback,
1333  const bool returns_variable_size_data);
1334 
1339  void
1340  notify_ready_to_unpack(
1341  const unsigned int handle,
1342  const std::function<void(
1343  const typename ::Triangulation<1, spacedim>::cell_iterator &,
1344  const typename ::Triangulation<1, spacedim>::CellStatus,
1345  const boost::iterator_range<std::vector<char>::const_iterator> &)>
1346  &unpack_callback);
1347 
1352  std::vector<types::global_dof_index>
1354  std::vector<types::global_dof_index>
1356 
1361  virtual std::map<unsigned int, std::set<::types::subdomain_id>>
1362  compute_level_vertices_with_ghost_neighbors(
1363  const unsigned int level) const;
1364 
1369  virtual std::vector<bool>
1370  mark_locally_active_vertices_on_level(const unsigned int level) const;
1371 
1372  virtual unsigned int
1373  coarse_cell_id_to_coarse_cell_index(
1374  const types::coarse_cell_id coarse_cell_id) const override;
1375 
1376  virtual types::coarse_cell_id
1377  coarse_cell_index_to_coarse_cell_id(
1378  const unsigned int coarse_cell_index) const override;
1379  };
1380  } // namespace distributed
1381 } // namespace parallel
1382 
1383 
1384 #else // DEAL_II_WITH_P4EST
1385 
1386 namespace parallel
1387 {
1388  namespace distributed
1389  {
1401  template <int dim, int spacedim = dim>
1402  class Triangulation
1403  : public ::parallel::TriangulationBase<dim, spacedim>
1404  {
1405  public:
1410  Triangulation() = delete;
1411  };
1412  } // namespace distributed
1413 } // namespace parallel
1414 
1415 
1416 #endif
1417 
1418 
1420 
1421 #endif
typename ::internal::p4est::types< dim >::connectivity * connectivity
Definition: tria.h:878
std::vector< types::global_dof_index > coarse_cell_to_p4est_tree_permutation
Definition: tria.h:1353
typename std::tuple< typename ::internal::p4est::types< dim >::quadrant *, CellStatus, cell_iterator > quadrant_cell_relation_t
Definition: tria.h:934
typename ::internal::p4est::types< dim >::ghost * parallel_ghost
Definition: tria.h:890
std::vector< pack_callback_t > pack_callbacks_variable
Definition: tria.h:920
typename ::internal::p4est::types< dim >::forest * parallel_forest
Definition: tria.h:884
void create_triangulation(Triangulation< dim, dim > &tria, const AdditionalData &additional_data=AdditionalData())
std::vector< types::global_dof_index > p4est_tree_to_coarse_cell_permutation
Definition: tria.h:1355
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:363
unsigned int level
Definition: grid_out.cc:4341
Point< 3 > vertices[4]
std::function< std::vector< char >(typename Triangulation< dim, spacedim >::cell_iterator, CellStatus)> pack_callback_t
Definition: tria.h:913
TriangulationBase< dim, spacedim > Triangulation
Definition: tria_base.h:302
std::vector< pack_callback_t > pack_callbacks_fixed
Definition: tria.h:919
std::vector< quadrant_cell_relation_t > local_quadrant_cell_relations
Definition: tria.h:944
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:362
std::vector< types::global_dof_index > p4est_tree_to_coarse_cell_permutation
Definition: tria.h:1150
std::vector< unsigned int > sizes_fixed_cumulative
Definition: tria.h:1113
typename ::Triangulation< dim, spacedim >::cell_iterator cell_iterator
Definition: tria.h:263
global_cell_index coarse_cell_id
Definition: types.h:114
CellAttachedData cell_attached_data
Definition: tria.h:923
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
std::vector< types::global_dof_index > coarse_cell_to_p4est_tree_permutation
Definition: tria.h:1148