Reference documentation for deal.II version GIT c00406db16 2023-09-28 18:00:02+00:00
\(\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 - 2023 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/mpi_stub.h>
26 
29 
30 #include <deal.II/grid/tria.h>
31 
32 #include <boost/range/iterator_range.hpp>
33 
34 #include <functional>
35 #include <list>
36 #include <set>
37 #include <type_traits>
38 #include <utility>
39 #include <vector>
40 
41 #ifdef DEAL_II_WITH_P4EST
42 # include <p4est.h>
43 # include <p4est_connectivity.h>
44 # include <p4est_ghost.h>
45 # include <p8est.h>
46 # include <p8est_connectivity.h>
47 # include <p8est_ghost.h>
48 #endif
49 
51 
52 #ifdef DEAL_II_WITH_P4EST
53 
54 // Forward declarations
55 # ifndef DOXYGEN
56 
57 namespace FETools
58 {
59  namespace internal
60  {
61  template <int, int, class>
62  class ExtrapolateImplementation;
63  }
64 } // namespace FETools
65 
66 // forward declaration of the data type for periodic face pairs
67 namespace GridTools
68 {
69  template <typename CellIterator>
70  struct PeriodicFacePair;
71 }
72 
73 namespace parallel
74 {
75  namespace distributed
76  {
77  template <int, int>
78  class TemporarilyMatchRefineFlags;
79  }
80 } // namespace parallel
81 # endif
82 
83 namespace parallel
84 {
85  namespace distributed
86  {
246  template <int dim, int spacedim = dim>
247  DEAL_II_CXX20_REQUIRES((concepts::is_valid_dim_spacedim<dim, spacedim>))
249  : public ::parallel::DistributedTriangulationBase<dim, spacedim>
250  {
251  public:
270  typename ::Triangulation<dim, spacedim>::cell_iterator;
271 
291  typename ::Triangulation<dim, spacedim>::active_cell_iterator;
292 
297  enum Settings
298  {
311  mesh_reconstruction_after_repartitioning = 0x1,
323  no_automatic_repartitioning = 0x4,
330  communicate_vertices_to_p4est = 0x8
331  };
332 
333 
334 
366  explicit Triangulation(
367  const MPI_Comm mpi_communicator,
368  const typename ::Triangulation<dim, spacedim>::MeshSmoothing
369  smooth_grid = (::Triangulation<dim, spacedim>::none),
371 
375  virtual ~Triangulation() override;
376 
383  virtual void
384  clear() override;
385 
389  bool
390  is_multilevel_hierarchy_constructed() const override;
391 
395  bool
396  are_vertices_communicated_to_p4est() const;
397 
411  void
412  execute_transfer(
413  const typename ::internal::p4est::types<dim>::forest
414  *parallel_forest,
415  const typename ::internal::p4est::types<dim>::gloidx
416  *previous_global_first_quadrant);
417 
425  virtual void
426  copy_triangulation(
427  const ::Triangulation<dim, spacedim> &other_tria) override;
428 
438  virtual void
439  create_triangulation(const std::vector<Point<spacedim>> &vertices,
440  const std::vector<CellData<dim>> &cells,
441  const SubCellData &subcelldata) override;
442 
448  virtual void
451  &construction_data) override;
452 
462  find_point_owner_rank(const Point<dim> &p);
463 
480  std::vector<types::subdomain_id>
481  find_point_owner_rank(const std::vector<Point<dim>> &points);
482 
512  virtual void
513  execute_coarsening_and_refinement() override;
514 
521  virtual bool
522  prepare_coarsening_and_refinement() override;
523 
564  void
565  repartition();
566 
570  virtual std::size_t
571  memory_consumption() const override;
572 
578  virtual std::size_t
579  memory_consumption_p4est() const;
580 
591  void
592  write_mesh_vtk(const std::string &file_basename) const;
593 
598  unsigned int
599  get_checksum() const;
600 
609  virtual void
610  save(const std::string &filename) const override;
611 
631  virtual void
632  load(const std::string &filename) override;
633 
640  virtual void
641  load(const std::string &filename, const bool autopartition) override;
642 
648  void
649  load(const typename ::internal::p4est::types<dim>::forest *forest);
650 
657  const std::vector<types::global_dof_index> &
658  get_p4est_tree_to_coarse_cell_permutation() const;
659 
665  const std::vector<types::global_dof_index> &
666  get_coarse_cell_to_p4est_tree_permutation() const;
667 
675  const typename ::internal::p4est::types<dim>::forest *
676  get_p4est() const;
677 
697  virtual void
698  add_periodicity(
699  const std::vector<::GridTools::PeriodicFacePair<cell_iterator>> &)
700  override;
701 
702 
703  private:
708 
713 
719  typename ::internal::p4est::types<dim>::connectivity *connectivity;
720 
725  typename ::internal::p4est::types<dim>::forest *parallel_forest;
726 
731  typename ::internal::p4est::types<dim>::ghost *parallel_ghost;
732 
754  virtual void
755  update_cell_relations() override;
756 
770  std::vector<types::global_dof_index>
772  std::vector<types::global_dof_index>
774 
779  typename ::internal::p4est::types<dim>::tree *
780  init_tree(const int dealii_coarse_cell_index) const;
781 
786  void
787  setup_coarse_cell_to_p4est_tree_permutation();
788 
795  void copy_new_triangulation_to_p4est(std::integral_constant<int, 2>);
796  void copy_new_triangulation_to_p4est(std::integral_constant<int, 3>);
797 
802  void
803  copy_local_forest_to_triangulation();
804 
818  std::vector<unsigned int>
819  get_cell_weights() const;
820 
830  std::vector<bool>
831  mark_locally_active_vertices_on_level(const int level) const;
832 
833  virtual unsigned int
834  coarse_cell_id_to_coarse_cell_index(
835  const types::coarse_cell_id coarse_cell_id) const override;
836 
837  virtual types::coarse_cell_id
839  const unsigned int coarse_cell_index) const override;
840 
841  template <int, int, class>
842  friend class ::FETools::internal::ExtrapolateImplementation;
843 
844  template <int, int>
846  };
847 
848 
856  template <int spacedim>
857  DEAL_II_CXX20_REQUIRES((concepts::is_valid_dim_spacedim<1, spacedim>))
858  class Triangulation<1, spacedim>
859  : public ::parallel::DistributedTriangulationBase<1, spacedim>
860  {
861  public:
865  enum Settings
866  {
868  mesh_reconstruction_after_repartitioning = 0x1,
870  no_automatic_repartitioning = 0x4,
871  communicate_vertices_to_p4est = 0x8
872  };
873 
879  const MPI_Comm mpi_communicator,
880  const typename ::Triangulation<1, spacedim>::MeshSmoothing
881  smooth_grid = (::Triangulation<1, spacedim>::none),
883 
887  virtual ~Triangulation() override;
888 
895  const std::vector<types::global_dof_index> &
896  get_p4est_tree_to_coarse_cell_permutation() const;
897 
902  virtual void
903  load(const std::string &filename) override;
904 
910  virtual void
911  load(const std::string &filename, const bool autopartition) override;
912 
917  virtual void
918  save(const std::string &filename) const override;
919 
924  virtual bool
925  is_multilevel_hierarchy_constructed() const override;
926 
931  bool
932  are_vertices_communicated_to_p4est() const;
933 
938  virtual void
939  update_cell_relations() override;
940 
945  std::vector<types::global_dof_index>
947  std::vector<types::global_dof_index>
949 
954  virtual std::map<unsigned int, std::set<::types::subdomain_id>>
955  compute_level_vertices_with_ghost_neighbors(
956  const unsigned int level) const;
957 
962  virtual std::vector<bool>
963  mark_locally_active_vertices_on_level(const unsigned int level) const;
964 
965  virtual unsigned int
966  coarse_cell_id_to_coarse_cell_index(
967  const types::coarse_cell_id coarse_cell_id) const override;
968 
969  virtual types::coarse_cell_id
971  const unsigned int coarse_cell_index) const override;
972 
973  template <int, int>
975  };
976  } // namespace distributed
977 } // namespace parallel
978 
979 
980 #else // DEAL_II_WITH_P4EST
981 
982 namespace parallel
983 {
984  namespace distributed
985  {
999  template <int dim, int spacedim = dim>
1000  DEAL_II_CXX20_REQUIRES((concepts::is_valid_dim_spacedim<dim, spacedim>))
1001  class Triangulation
1002  : public ::parallel::DistributedTriangulationBase<dim, spacedim>
1003  {
1004  public:
1008  enum Settings
1009  {
1010  default_setting = 0x0,
1015  };
1016 
1021  explicit Triangulation(
1022  const MPI_Comm /*mpi_communicator*/,
1023  const typename ::Triangulation<dim, spacedim>::MeshSmoothing
1024  /*smooth_grid*/
1026  const Settings /*settings*/ = default_setting) = delete;
1027 
1032  virtual bool
1033  is_multilevel_hierarchy_constructed() const override
1034  {
1035  return false;
1036  }
1037 
1042  bool
1044  {
1045  return false;
1046  }
1047 
1052  virtual void
1053  save(const std::string & /*filename*/) const override
1054  {}
1055 
1060  virtual void
1061  load(const std::string & /*filename*/) override
1062  {}
1063 
1069  virtual void
1070  load(const std::string & /*filename*/,
1071  const bool /*autopartition*/) override
1072  {}
1073 
1078  virtual void
1079  update_cell_relations() override
1080  {}
1081  };
1082  } // namespace distributed
1083 } // namespace parallel
1084 
1085 
1086 #endif
1087 
1088 
1089 namespace parallel
1090 {
1091  namespace distributed
1092  {
1110  template <int dim, int spacedim = dim>
1112  {
1113  public:
1124 
1132 
1133  private:
1137  const SmartPointer<
1140 
1145  std::vector<bool> saved_refine_flags;
1146 
1151  std::vector<bool> saved_coarsen_flags;
1152  };
1153  } // namespace distributed
1154 } // namespace parallel
1155 
1156 
1158 
1159 #endif
TemporarilyMatchRefineFlags(::Triangulation< dim, spacedim > &tria)
Definition: tria.cc:4226
const SmartPointer< ::parallel::distributed::Triangulation< dim, spacedim > > distributed_tria
Definition: tria.h:1139
std::vector< types::global_dof_index > p4est_tree_to_coarse_cell_permutation
Definition: tria.h:948
std::vector< types::global_dof_index > coarse_cell_to_p4est_tree_permutation
Definition: tria.h:946
bool are_vertices_communicated_to_p4est() const
Definition: tria.cc:1860
typename ::internal::p4est::types< dim >::ghost * parallel_ghost
Definition: tria.h:731
std::vector< types::global_dof_index > p4est_tree_to_coarse_cell_permutation
Definition: tria.h:773
virtual void update_cell_relations() override
Definition: tria.cc:4008
void copy_new_triangulation_to_p4est(std::integral_constant< int, 3 >)
void copy_new_triangulation_to_p4est(std::integral_constant< int, 2 >)
Triangulation(const MPI_Comm mpi_communicator, const typename ::Triangulation< dim, spacedim >::MeshSmoothing smooth_grid=(::Triangulation< dim, spacedim >::none), const Settings settings=default_setting)
Definition: tria.cc:1697
virtual void save(const std::string &filename) const override
Definition: tria.cc:2003
bool is_multilevel_hierarchy_constructed() const override
Definition: tria.cc:1849
typename ::internal::p4est::types< dim >::connectivity * connectivity
Definition: tria.h:719
std::vector< types::global_dof_index > coarse_cell_to_p4est_tree_permutation
Definition: tria.h:771
virtual void load(const std::string &filename) override
Definition: tria.cc:2057
typename ::internal::p4est::types< dim >::forest * parallel_forest
Definition: tria.h:725
#define DEAL_II_DEPRECATED
Definition: config.h:178
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:477
#define DEAL_II_CXX20_REQUIRES(condition)
Definition: config.h:166
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:478
Point< 3 > vertices[4]
unsigned int level
Definition: grid_out.cc:4617
typename ::Triangulation< dim, spacedim >::cell_iterator cell_iterator
Definition: tria.h:270
typename ::Triangulation< dim, spacedim >::active_cell_iterator active_cell_iterator
Definition: tria.h:291
void create_triangulation(Triangulation< dim, dim > &tria, const AdditionalData &additional_data=AdditionalData())
std::enable_if_t< std::is_fundamental_v< T >, std::size_t > memory_consumption(const T &t)
global_cell_index coarse_cell_id
Definition: types.h:127
unsigned int subdomain_id
Definition: types.h:44
const TriangulationDescription::Settings settings
std::vector< types::coarse_cell_id > coarse_cell_index_to_coarse_cell_id
const ::Triangulation< dim, spacedim > & tria