Reference documentation for deal.II version Git 6c3defc1fd 2020-06-02 18:18:21 -0400
\(\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  {
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  {
308  mesh_reconstruction_after_repartitioning = 0x1,
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
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 
873 
879  typename ::internal::p4est::types<dim>::connectivity *connectivity;
880 
885  typename ::internal::p4est::types<dim>::forest *parallel_forest;
886 
891  typename ::internal::p4est::types<dim>::ghost *parallel_ghost;
892 
899  {
904  unsigned int n_attached_data_sets;
905 
911 
912  using pack_callback_t = std::function<std::vector<char>(
915 
920  std::vector<pack_callback_t> pack_callbacks_fixed;
921  std::vector<pack_callback_t> pack_callbacks_variable;
922  };
923 
924  CellAttachedData cell_attached_data;
925 
932  using quadrant_cell_relation_t = typename std::tuple<
933  typename ::internal::p4est::types<dim>::quadrant *,
934  CellStatus,
936 
945  std::vector<quadrant_cell_relation_t> local_quadrant_cell_relations;
946 
956  void
957  update_quadrant_cell_relations();
958 
969  {
970  public:
971  DataTransfer(MPI_Comm mpi_communicator);
972 
982  void
983  pack_data(
984  const std::vector<quadrant_cell_relation_t> &quad_cell_relations,
985  const std::vector<typename CellAttachedData::pack_callback_t>
986  &pack_callbacks_fixed,
987  const std::vector<typename CellAttachedData::pack_callback_t>
988  &pack_callbacks_variable);
989 
1002  void
1003  execute_transfer(
1004  const typename ::internal::p4est::types<dim>::forest
1005  *parallel_forest,
1006  const typename ::internal::p4est::types<dim>::gloidx
1007  *previous_global_first_quadrant);
1008 
1016  void
1017  unpack_cell_status(
1018  std::vector<quadrant_cell_relation_t> &quad_cell_relations) const;
1019 
1032  void
1033  unpack_data(
1034  const std::vector<quadrant_cell_relation_t> &quad_cell_relations,
1035  const unsigned int handle,
1036  const std::function<void(
1037  const typename ::Triangulation<dim, spacedim>::cell_iterator
1038  &,
1039  const typename ::Triangulation<dim, spacedim>::CellStatus &,
1040  const boost::iterator_range<std::vector<char>::const_iterator> &)>
1041  &unpack_callback) const;
1042 
1057  void
1058  save(const typename ::internal::p4est::types<dim>::forest
1059  * parallel_forest,
1060  const std::string &filename) const;
1061 
1080  void
1081  load(const typename ::internal::p4est::types<dim>::forest
1082  * parallel_forest,
1083  const std::string &filename,
1084  const unsigned int n_attached_deserialize_fixed,
1085  const unsigned int n_attached_deserialize_variable);
1086 
1093  void
1094  clear();
1095 
1096  private:
1098 
1103 
1114  std::vector<unsigned int> sizes_fixed_cumulative;
1115 
1120  std::vector<char> src_data_fixed;
1121  std::vector<char> dest_data_fixed;
1122 
1127  std::vector<int> src_sizes_variable;
1128  std::vector<int> dest_sizes_variable;
1129  std::vector<char> src_data_variable;
1130  std::vector<char> dest_data_variable;
1131  };
1132 
1133  DataTransfer data_transfer;
1134 
1148  std::vector<types::global_dof_index>
1150  std::vector<types::global_dof_index>
1152 
1157  typename ::internal::p4est::types<dim>::tree *
1158  init_tree(const int dealii_coarse_cell_index) const;
1159 
1164  void
1165  setup_coarse_cell_to_p4est_tree_permutation();
1166 
1173  void
1174  copy_new_triangulation_to_p4est(std::integral_constant<int, 2>);
1175  void
1176  copy_new_triangulation_to_p4est(std::integral_constant<int, 3>);
1177 
1182  void
1183  copy_local_forest_to_triangulation();
1184 
1198  std::vector<unsigned int>
1199  get_cell_weights() const;
1200 
1210  std::vector<bool>
1211  mark_locally_active_vertices_on_level(const int level) const;
1212 
1213  virtual unsigned int
1214  coarse_cell_id_to_coarse_cell_index(
1215  const types::coarse_cell_id coarse_cell_id) const override;
1216 
1217  virtual types::coarse_cell_id
1218  coarse_cell_index_to_coarse_cell_id(
1219  const unsigned int coarse_cell_index) const override;
1220 
1221  template <int, int, class>
1222  friend class ::FETools::internal::ExtrapolateImplementation;
1223  };
1224 
1225 
1231  template <int spacedim>
1232  class Triangulation<1, spacedim>
1233  : public ::parallel::DistributedTriangulationBase<1, spacedim>
1234  {
1235  public:
1240  {
1242  mesh_reconstruction_after_repartitioning = 0x1,
1244  };
1245 
1250  Triangulation(
1251  MPI_Comm mpi_communicator,
1252  const typename ::Triangulation<1, spacedim>::MeshSmoothing
1253  smooth_grid = (::Triangulation<1, spacedim>::none),
1254  const Settings settings = default_setting);
1255 
1259  virtual ~Triangulation() override;
1260 
1267  const std::vector<types::global_dof_index> &
1268  get_p4est_tree_to_coarse_cell_permutation() const;
1269 
1303  void
1304  communicate_locally_moved_vertices(
1305  const std::vector<bool> &vertex_locally_moved);
1306 
1311  void
1312  load(const std::string &filename, const bool autopartition = true);
1313 
1318  void
1319  save(const std::string &filename) const;
1320 
1321  bool
1322  is_multilevel_hierarchy_constructed() const override;
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>
1357 
1362  virtual std::map<unsigned int, std::set<::types::subdomain_id>>
1363  compute_level_vertices_with_ghost_neighbors(
1364  const unsigned int level) const;
1365 
1370  virtual std::vector<bool>
1371  mark_locally_active_vertices_on_level(const unsigned int level) const;
1372 
1373  virtual unsigned int
1374  coarse_cell_id_to_coarse_cell_index(
1375  const types::coarse_cell_id coarse_cell_id) const override;
1376 
1377  virtual types::coarse_cell_id
1378  coarse_cell_index_to_coarse_cell_id(
1379  const unsigned int coarse_cell_index) const override;
1380  };
1381  } // namespace distributed
1382 } // namespace parallel
1383 
1384 
1385 #else // DEAL_II_WITH_P4EST
1386 
1387 namespace parallel
1388 {
1389  namespace distributed
1390  {
1402  template <int dim, int spacedim = dim>
1403  class Triangulation
1404  : public ::parallel::TriangulationBase<dim, spacedim>
1405  {
1406  public:
1411  Triangulation() = delete;
1412  };
1413  } // namespace distributed
1414 } // namespace parallel
1415 
1416 
1417 #endif
1418 
1419 
1421 
1422 #endif
typename ::internal::p4est::types< dim >::connectivity * connectivity
Definition: tria.h:879
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:935
typename ::internal::p4est::types< dim >::ghost * parallel_ghost
Definition: tria.h:891
std::vector< pack_callback_t > pack_callbacks_variable
Definition: tria.h:921
typename ::internal::p4est::types< dim >::forest * parallel_forest
Definition: tria.h:885
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:1356
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:361
unsigned int level
Definition: grid_out.cc:4355
Point< 3 > vertices[4]
std::function< std::vector< char >(typename Triangulation< dim, spacedim >::cell_iterator, CellStatus)> pack_callback_t
Definition: tria.h:914
TriangulationBase< dim, spacedim > Triangulation
Definition: tria_base.h:302
std::vector< pack_callback_t > pack_callbacks_fixed
Definition: tria.h:920
std::vector< quadrant_cell_relation_t > local_quadrant_cell_relations
Definition: tria.h:945
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:360
std::vector< types::global_dof_index > p4est_tree_to_coarse_cell_permutation
Definition: tria.h:1151
std::vector< unsigned int > sizes_fixed_cumulative
Definition: tria.h:1114
typename ::Triangulation< dim, spacedim >::cell_iterator cell_iterator
Definition: tria.h:264
global_cell_index coarse_cell_id
Definition: types.h:114
CellAttachedData cell_attached_data
Definition: tria.h:924
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:1149