deal.II version GIT relicensing-7182-g951947b1c4 2026-11-26 10:30:01+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\}}\)
Loading...
Searching...
No Matches
grid_tools.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2001 - 2026 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_grid_tools_h
14#define dealii_grid_tools_h
15
16
17#include <deal.II/base/config.h>
18
21#include <deal.II/base/point.h>
22
24
26
28
30#include <deal.II/fe/mapping.h>
31
35#include <deal.II/grid/tria.h>
38
43
45
46#include <boost/archive/binary_iarchive.hpp>
47#include <boost/archive/binary_oarchive.hpp>
48#include <boost/random/mersenne_twister.hpp>
49#include <boost/serialization/array.hpp>
50#include <boost/serialization/vector.hpp>
51
52#ifdef DEAL_II_WITH_ZLIB
53# include <boost/iostreams/device/back_inserter.hpp>
54# include <boost/iostreams/filter/gzip.hpp>
55# include <boost/iostreams/filtering_stream.hpp>
56# include <boost/iostreams/stream.hpp>
57#endif
58
59#include <optional>
60#include <set>
61
62#ifdef DEAL_II_HAVE_CXX20
63# include <concepts>
64#endif
65
66
68
69// Forward declarations
70#ifndef DOXYGEN
71namespace parallel
72{
73 namespace distributed
74 {
75 template <int dim, int spacedim>
77 class Triangulation;
78 }
79} // namespace parallel
80
81namespace hp
82{
83 template <int, int>
84 class MappingCollection;
85}
86
87class SparsityPattern;
88
89namespace GridTools
90{
91 template <int dim, int spacedim>
92 class Cache;
93}
94#endif
95
96namespace internal
97{
98 template <int dim, int spacedim, typename MeshType>
101 {
102 public:
103#ifndef _MSC_VER
104 using type = typename MeshType::active_cell_iterator;
105#else
107#endif
108 };
109
110#ifdef _MSC_VER
111 template <int dim, int spacedim>
112 class ActiveCellIterator<dim, spacedim, DoFHandler<dim, spacedim>>
113 {
114 public:
115 using type =
117 };
118#endif
119} // namespace internal
120
129namespace GridTools
130{
217 template <int dim, typename Transformation, int spacedim>
219 (std::invocable<Transformation, Point<spacedim>> &&
220 std::assignable_from<
222 std::invoke_result_t<Transformation, Point<spacedim>>>))
223 void transform(const Transformation &transformation,
224 Triangulation<dim, spacedim> &triangulation);
225
232 template <int dim, int spacedim>
233 void
234 shift(const Tensor<1, spacedim> &shift_vector,
235 Triangulation<dim, spacedim> &triangulation);
236
237
248 template <int dim, int spacedim>
249 void
250 rotate(const double angle, Triangulation<dim, spacedim> &triangulation);
251
264 template <int dim>
265 void
266 rotate(const Tensor<1, 3, double> &axis,
267 const double angle,
268 Triangulation<dim, 3> &triangulation);
269
327 template <int dim>
328 void
329 laplace_transform(const std::map<unsigned int, Point<dim>> &new_points,
330 Triangulation<dim> &tria,
331 const Function<dim, double> *coefficient = nullptr,
332 const bool solve_for_absolute_positions = false);
333
341 template <int dim, int spacedim>
342 void
343 scale(const double scaling_factor,
344 Triangulation<dim, spacedim> &triangulation);
345
375 template <int dim, int spacedim>
376 void
378 const double factor,
379 Triangulation<dim, spacedim> &triangulation,
380 const bool keep_boundary = true,
381 const unsigned int seed = boost::random::mt19937::default_seed);
382
472 template <int dim, int spacedim>
473 void
474 regularize_corner_cells(Triangulation<dim, spacedim> &tria,
475 const double limit_angle_fraction = .75);
476
540 template <int dim, int spacedim>
541#ifndef DOXYGEN
542 std::tuple<
543 std::vector<typename Triangulation<dim, spacedim>::active_cell_iterator>,
544 std::vector<std::vector<Point<dim>>>,
545 std::vector<std::vector<unsigned int>>>
546#else
547 return_type
548#endif
550 const Cache<dim, spacedim> &cache,
551 const std::vector<Point<spacedim>> &points,
553 &cell_hint =
555
589 template <int dim, int spacedim>
590#ifndef DOXYGEN
591 std::tuple<
592 std::vector<typename Triangulation<dim, spacedim>::active_cell_iterator>,
593 std::vector<std::vector<Point<dim>>>,
594 std::vector<std::vector<unsigned int>>,
595 std::vector<unsigned int>>
596#else
597 return_type
598#endif
600 const Cache<dim, spacedim> &cache,
601 const std::vector<Point<spacedim>> &points,
603 &cell_hint =
605
694 template <int dim, int spacedim>
695#ifndef DOXYGEN
696 std::tuple<
697 std::vector<typename Triangulation<dim, spacedim>::active_cell_iterator>,
698 std::vector<std::vector<Point<dim>>>,
699 std::vector<std::vector<unsigned int>>,
700 std::vector<std::vector<Point<spacedim>>>,
701 std::vector<std::vector<unsigned int>>>
702#else
703 return_type
704#endif
707 const std::vector<Point<spacedim>> &local_points,
708 const std::vector<std::vector<BoundingBox<spacedim>>> &global_bboxes,
709 const double tolerance = 1e-10,
710 const std::vector<bool> &marked_vertices = {},
711 const bool enforce_unique_mapping = true);
712
713 namespace internal
714 {
729 template <int dim, int spacedim>
731 {
733
740 void
742
746 unsigned int n_searched_points;
747
754 std::vector<std::tuple<std::pair<int, int>,
755 unsigned int,
756 unsigned int,
759 unsigned int>>
761
765 std::vector<unsigned int> send_ranks;
766
772 std::vector<unsigned int> send_ptrs;
773
784 std::vector<std::tuple<unsigned int, unsigned int, unsigned int>>
786
790 std::vector<unsigned int> recv_ranks;
791
797 std::vector<unsigned int> recv_ptrs;
798 };
799
809 template <int dim, int spacedim>
813 const std::vector<Point<spacedim>> &points,
814 const std::vector<std::vector<BoundingBox<spacedim>>> &global_bboxes,
815 const std::vector<bool> &marked_vertices,
816 const double tolerance,
817 const bool perform_handshake,
818 const bool enforce_unique_mapping = false);
819
820
828 template <int structdim, int spacedim>
830 {
835 std::array<::Point<spacedim>, structdim + 1>;
836
845 std::vector<std::tuple<std::pair<int, int>,
846 unsigned int,
847 unsigned int,
850
859 std::vector<std::tuple<unsigned int, unsigned int, IntersectionType>>
861
865 std::vector<unsigned int> recv_ptrs;
866
887 template <int dim>
889 spacedim>
891 const unsigned int n_points_1D,
893 const Mapping<dim, spacedim> &mapping,
894 std::vector<Quadrature<spacedim>> *mapped_quadratures_recv_comp =
895 nullptr,
896 const bool consistent_numbering_of_sender_and_receiver = false) const;
897
898 private:
906 std::map<unsigned int, std::vector<unsigned int>>
908 const std::vector<std::tuple<unsigned int, unsigned int, unsigned int>>
909 &point_recv_components,
910 const MPI_Comm comm) const;
911 };
912
920 template <int structdim, int dim, int spacedim>
923 const Cache<dim, spacedim> &cache,
924 const std::vector<std::vector<Point<spacedim>>> &intersection_requests,
925 const std::vector<std::vector<BoundingBox<spacedim>>> &global_bboxes,
926 const std::vector<bool> &marked_vertices,
927 const double tolerance);
928
929 } // namespace internal
930
940 template <int spacedim>
941 unsigned int
942 find_closest_vertex(const std::map<unsigned int, Point<spacedim>> &vertices,
943 const Point<spacedim> &p);
944
971 template <int dim, template <int, int> class MeshType, int spacedim>
973 (concepts::is_triangulation_or_dof_handler<MeshType<dim, spacedim>>))
974 unsigned int find_closest_vertex(
975 const MeshType<dim, spacedim> &mesh,
976 const Point<spacedim> &p,
977 const std::vector<bool> &marked_vertices = {});
978
1005 template <int dim, template <int, int> class MeshType, int spacedim>
1007 (concepts::is_triangulation_or_dof_handler<MeshType<dim, spacedim>>))
1008 unsigned int find_closest_vertex(
1009 const Mapping<dim, spacedim> &mapping,
1010 const MeshType<dim, spacedim> &mesh,
1011 const Point<spacedim> &p,
1012 const std::vector<bool> &marked_vertices = {});
1013
1014
1037 template <typename MeshType>
1039#ifndef _MSC_VER
1040 std::vector<typename MeshType::active_cell_iterator>
1041#else
1042 std::vector<
1043 typename ::internal::ActiveCellIterator<MeshType::dimension,
1044 MeshType::space_dimension,
1045 MeshType>::type>
1046#endif
1047 find_cells_adjacent_to_vertex(const MeshType &container,
1048 const unsigned int vertex_index);
1049
1115 template <int dim, template <int, int> class MeshType, int spacedim>
1117 (concepts::is_triangulation_or_dof_handler<MeshType<dim, spacedim>>))
1118#ifndef _MSC_VER
1119 std::pair<typename MeshType<dim, spacedim>::active_cell_iterator, Point<dim>>
1120#else
1121 std::pair<typename ::internal::
1122 ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim>>::type,
1123 Point<dim>>
1124#endif
1126 const MeshType<dim, spacedim> &mesh,
1127 const Point<spacedim> &p,
1128 const std::vector<bool> &marked_vertices = {},
1129 const double tolerance = 1.e-10);
1130
1141 template <int dim, template <int, int> class MeshType, int spacedim>
1143 (concepts::is_triangulation_or_dof_handler<MeshType<dim, spacedim>>))
1144#ifndef _MSC_VER
1145 typename MeshType<dim, spacedim>::active_cell_iterator
1146#else
1147 typename ::internal::
1148 ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim>>::type
1149#endif
1150 find_active_cell_around_point(const MeshType<dim, spacedim> &mesh,
1151 const Point<spacedim> &p,
1152 const std::vector<bool> &marked_vertices = {},
1153 const double tolerance = 1.e-10);
1154
1161 template <int dim, int spacedim>
1162 std::pair<typename DoFHandler<dim, spacedim>::active_cell_iterator,
1163 Point<dim>>
1166 const DoFHandler<dim, spacedim> &mesh,
1167 const Point<spacedim> &p,
1168 const double tolerance = 1.e-10);
1169
1221 template <int dim, int spacedim>
1222 std::pair<typename Triangulation<dim, spacedim>::active_cell_iterator,
1223 Point<dim>>
1225 const Cache<dim, spacedim> &cache,
1226 const Point<spacedim> &p,
1229 const std::vector<bool> &marked_vertices = {},
1230 const double tolerance = 1.e-10);
1231
1248 template <int dim, template <int, int> class MeshType, int spacedim>
1250 (concepts::is_triangulation_or_dof_handler<MeshType<dim, spacedim>>))
1251#ifndef _MSC_VER
1252 std::pair<typename MeshType<dim, spacedim>::active_cell_iterator, Point<dim>>
1253#else
1254 std::pair<typename ::internal::
1255 ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim>>::type,
1256 Point<dim>>
1257#endif
1259 const Mapping<dim, spacedim> &mapping,
1260 const MeshType<dim, spacedim> &mesh,
1261 const Point<spacedim> &p,
1262 const std::vector<
1263 std::set<typename MeshType<dim, spacedim>::active_cell_iterator>>
1265 const std::vector<std::vector<Tensor<1, spacedim>>>
1266 &vertex_to_cell_centers,
1267 const typename MeshType<dim, spacedim>::active_cell_iterator &cell_hint =
1268 typename MeshType<dim, spacedim>::active_cell_iterator(),
1269 const std::vector<bool> &marked_vertices = {},
1270 const RTree<std::pair<Point<spacedim>, unsigned int>> &
1271 used_vertices_rtree = RTree<std::pair<Point<spacedim>, unsigned int>>{},
1272 const double tolerance = 1.e-10,
1273 const RTree<
1274 std::pair<BoundingBox<spacedim>,
1276 *relevant_cell_bounding_boxes_rtree = nullptr);
1277
1307 template <int dim, template <int, int> class MeshType, int spacedim>
1309 (concepts::is_triangulation_or_dof_handler<MeshType<dim, spacedim>>))
1310#ifndef _MSC_VER
1311 std::vector<std::pair<typename MeshType<dim, spacedim>::active_cell_iterator,
1312 Point<dim>>>
1313#else
1314 std::vector<std::pair<
1315 typename ::internal::
1316 ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim>>::type,
1317 Point<dim>>>
1318#endif
1320 const Mapping<dim, spacedim> &mapping,
1321 const MeshType<dim, spacedim> &mesh,
1322 const Point<spacedim> &p,
1323 const double tolerance,
1324 const std::pair<typename MeshType<dim, spacedim>::active_cell_iterator,
1325 Point<dim>> &first_cell,
1326 const std::vector<
1327 std::set<typename MeshType<dim, spacedim>::active_cell_iterator>>
1328 *vertex_to_cells = nullptr);
1329
1339 template <int dim, template <int, int> class MeshType, int spacedim>
1341 (concepts::is_triangulation_or_dof_handler<MeshType<dim, spacedim>>))
1342#ifndef _MSC_VER
1343 std::vector<std::pair<typename MeshType<dim, spacedim>::active_cell_iterator,
1344 Point<dim>>>
1345#else
1346 std::vector<std::pair<
1347 typename ::internal::
1348 ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim>>::type,
1349 Point<dim>>>
1350#endif
1352 const Mapping<dim, spacedim> &mapping,
1353 const MeshType<dim, spacedim> &mesh,
1354 const Point<spacedim> &p,
1355 const double tolerance = 1e-10,
1356 const std::vector<bool> &marked_vertices = {});
1357
1381 template <typename MeshType>
1383 std::vector<typename MeshType::active_cell_iterator> get_active_child_cells(
1384 const typename MeshType::cell_iterator &cell);
1385
1412 template <typename MeshType>
1413 DEAL_II_CXX20_REQUIRES(concepts::is_triangulation_or_dof_handler<MeshType>)
1415 const typename MeshType::active_cell_iterator &cell,
1416 std::vector<typename MeshType::active_cell_iterator> &active_neighbors);
1417
1469 template <typename MeshType>
1470 DEAL_II_CXX20_REQUIRES(concepts::is_triangulation_or_dof_handler<MeshType>)
1471 std::
1472 vector<typename MeshType::active_cell_iterator> compute_active_cell_halo_layer(
1473 const MeshType &mesh,
1474 const std::function<bool(const typename MeshType::active_cell_iterator &)>
1475 &predicate);
1476
1477
1487 template <typename MeshType>
1488 DEAL_II_CXX20_REQUIRES(concepts::is_triangulation_or_dof_handler<MeshType>)
1489 std::
1490 vector<typename MeshType::cell_iterator> compute_cell_halo_layer_on_level(
1491 const MeshType &mesh,
1492 const std::function<bool(const typename MeshType::cell_iterator &)>
1493 &predicate,
1494 const unsigned int level);
1495
1496
1511 template <typename MeshType>
1512 DEAL_II_CXX20_REQUIRES(concepts::is_triangulation_or_dof_handler<MeshType>)
1513 std::vector<
1514 typename MeshType::
1515 active_cell_iterator> compute_ghost_cell_halo_layer(const MeshType &mesh);
1516
1567 template <typename MeshType>
1568 DEAL_II_CXX20_REQUIRES(concepts::is_triangulation_or_dof_handler<MeshType>)
1569 std::
1570 vector<typename MeshType::active_cell_iterator> compute_active_cell_layer_within_distance(
1571 const MeshType &mesh,
1572 const std::function<bool(const typename MeshType::active_cell_iterator &)>
1573 &predicate,
1574 const double layer_thickness);
1575
1600 template <typename MeshType>
1601 DEAL_II_CXX20_REQUIRES(concepts::is_triangulation_or_dof_handler<MeshType>)
1602 std::
1603 vector<typename MeshType::active_cell_iterator> compute_ghost_cell_layer_within_distance(
1604 const MeshType &mesh,
1605 const double layer_thickness);
1606
1679 template <typename MeshType>
1680 DEAL_II_CXX20_REQUIRES(concepts::is_triangulation_or_dof_handler<MeshType>)
1681 std::
1682 vector<BoundingBox<MeshType::space_dimension>> compute_mesh_predicate_bounding_box(
1683 const MeshType &mesh,
1684 const std::function<bool(const typename MeshType::active_cell_iterator &)>
1685 &predicate,
1686 const unsigned int refinement_level = 0,
1687 const bool allow_merge = false,
1688 const unsigned int max_boxes = numbers::invalid_unsigned_int);
1689
1717 template <int spacedim>
1718#ifndef DOXYGEN
1719 std::tuple<std::vector<std::vector<unsigned int>>,
1720 std::map<unsigned int, unsigned int>,
1721 std::map<unsigned int, std::vector<unsigned int>>>
1722#else
1723 return_type
1724#endif
1726 const std::vector<std::vector<BoundingBox<spacedim>>> &global_bboxes,
1727 const std::vector<Point<spacedim>> &points);
1728
1729
1764 template <int spacedim>
1765#ifndef DOXYGEN
1766 std::tuple<std::map<unsigned int, std::vector<unsigned int>>,
1767 std::map<unsigned int, unsigned int>,
1768 std::map<unsigned int, std::vector<unsigned int>>>
1769#else
1770 return_type
1771#endif
1773 const RTree<std::pair<BoundingBox<spacedim>, unsigned int>> &covering_rtree,
1774 const std::vector<Point<spacedim>> &points);
1775
1788 template <int dim, int spacedim>
1789 std::vector<std::vector<Tensor<1, spacedim>>>
1791 const Triangulation<dim, spacedim> &mesh,
1792 const std::vector<
1794 &vertex_to_cells);
1795
1796
1804 template <int dim, int spacedim>
1805 unsigned int
1808 const Point<spacedim> &position,
1809 const Mapping<dim, spacedim> &mapping =
1810 (ReferenceCells::get_hypercube<dim>()
1811#ifndef _MSC_VER
1812 .template get_default_linear_mapping<spacedim>()
1813#else
1815#endif
1816 ));
1817
1829 template <int dim, int spacedim>
1830 std::map<unsigned int, types::global_vertex_index>
1832 const Triangulation<dim, spacedim> &triangulation);
1833
1862 template <int dim, int spacedim>
1863 std::vector<types::global_vertex_index>
1865 const Triangulation<dim, spacedim> &serial_tria,
1866 const Triangulation<dim, spacedim> &parallel_tria);
1867
1894 template <int dim, int spacedim>
1895 void
1896 partition_triangulation(const unsigned int n_partitions,
1897 Triangulation<dim, spacedim> &triangulation,
1898 const SparsityTools::Partitioner partitioner =
1900
1911 template <int dim, int spacedim>
1912 void
1913 partition_triangulation(const unsigned int n_partitions,
1914 const std::vector<unsigned int> &cell_weights,
1915 Triangulation<dim, spacedim> &triangulation,
1916 const SparsityTools::Partitioner partitioner =
1918
1964 template <int dim, int spacedim>
1965 void
1966 partition_triangulation(const unsigned int n_partitions,
1967 const SparsityPattern &cell_connection_graph,
1968 Triangulation<dim, spacedim> &triangulation,
1969 const SparsityTools::Partitioner partitioner =
1971
1982 template <int dim, int spacedim>
1983 void
1984 partition_triangulation(const unsigned int n_partitions,
1985 const std::vector<unsigned int> &cell_weights,
1986 const SparsityPattern &cell_connection_graph,
1987 Triangulation<dim, spacedim> &triangulation,
1988 const SparsityTools::Partitioner partitioner =
1990
2005 template <int dim, int spacedim>
2006 void
2007 partition_triangulation_zorder(const unsigned int n_partitions,
2008 Triangulation<dim, spacedim> &triangulation,
2009 const bool group_siblings = true);
2010
2022 template <int dim, int spacedim>
2023 void
2025
2033 template <int dim, int spacedim>
2034 std::vector<types::subdomain_id>
2036 const std::vector<CellId> &cell_ids);
2037
2048 template <int dim, int spacedim>
2049 void
2051 std::vector<types::subdomain_id> &subdomain);
2052
2067 template <int dim, int spacedim>
2068 unsigned int
2070 const Triangulation<dim, spacedim> &triangulation,
2071 const types::subdomain_id subdomain);
2072
2102 template <int dim, int spacedim>
2103 std::vector<bool>
2105
2155 template <typename MeshType>
2157 std::vector<typename MeshType::active_cell_iterator> get_patch_around_cell(
2158 const typename MeshType::active_cell_iterator &cell);
2159
2160
2182 template <class Container>
2183 std::vector<typename Container::cell_iterator>
2185 const std::vector<typename Container::active_cell_iterator> &patch_cells);
2186
2253 template <class Container>
2254 void
2256 const std::vector<typename Container::active_cell_iterator> &patch,
2258 &local_triangulation,
2259 std::map<
2260 typename Triangulation<Container::dimension,
2261 Container::space_dimension>::active_cell_iterator,
2262 typename Container::active_cell_iterator> &patch_to_global_tria_map);
2263
2295 template <int dim, int spacedim>
2296 std::map<
2298 std::vector<typename DoFHandler<dim, spacedim>::active_cell_iterator>>
2300
2301
2316 template <typename CellIterator>
2318 {
2322 CellIterator cell[2];
2323
2328 unsigned int face_idx[2];
2329
2336
2350
2354 std::size_t
2356 };
2357
2358
2382 template <typename FaceIterator>
2383 std::optional<types::geometric_orientation>
2385 const FaceIterator &face1,
2386 const FaceIterator &face2,
2387 const unsigned int direction,
2390 const FullMatrix<double> &matrix = FullMatrix<double>(),
2391 const double abs_tol = 1e-10);
2392
2452 template <typename MeshType>
2455 const MeshType &mesh,
2456 const types::boundary_id b_id1,
2457 const types::boundary_id b_id2,
2458 const unsigned int direction,
2460 &matched_pairs,
2463 const FullMatrix<double> &matrix = FullMatrix<double>(),
2464 const double abs_tol = 1e-10);
2465
2466
2492 template <typename MeshType>
2495 const MeshType &mesh,
2496 const types::boundary_id b_id,
2497 const unsigned int direction,
2498 std::vector<PeriodicFacePair<typename MeshType::cell_iterator>>
2499 &matched_pairs,
2500 const ::Tensor<1, MeshType::space_dimension> &offset =
2501 ::Tensor<1, MeshType::space_dimension>(),
2502 const FullMatrix<double> &matrix = FullMatrix<double>(),
2503 const double abs_tol = 1e-10);
2504
2531 template <int dim, int spacedim>
2532 void
2533 copy_boundary_to_manifold_id(Triangulation<dim, spacedim> &tria,
2534 const bool reset_boundary_ids = false);
2535
2557 template <int dim, int spacedim>
2558 void
2560 const std::vector<types::boundary_id> &src_boundary_ids,
2561 const std::vector<types::manifold_id> &dst_manifold_ids,
2562 Triangulation<dim, spacedim> &tria,
2563 const std::vector<types::boundary_id> &reset_boundary_ids = {});
2564
2594 template <int dim, int spacedim>
2595 void
2597 const bool compute_face_ids = false);
2598
2623 template <int dim, int spacedim>
2624 void
2627 const std::function<types::manifold_id(
2628 const std::set<types::manifold_id> &)> &disambiguation_function =
2629 [](const std::set<types::manifold_id> &manifold_ids) {
2630 if (manifold_ids.size() == 1)
2631 return *manifold_ids.begin();
2632 else
2634 },
2635 bool overwrite_only_flat_manifold_ids = true);
2724 template <typename DataType, typename MeshType>
2727 const MeshType &mesh,
2728 const std::function<std::optional<DataType>(
2729 const typename MeshType::active_cell_iterator &)> &pack,
2730 const std::function<void(const typename MeshType::active_cell_iterator &,
2731 const DataType &)> &unpack,
2732 const std::function<bool(const typename MeshType::active_cell_iterator &)>
2733 &cell_filter =
2734 always_return<typename MeshType::active_cell_iterator, bool>{true});
2735
2748 template <typename DataType, typename MeshType>
2751 const MeshType &mesh,
2752 const std::function<std::optional<DataType>(
2753 const typename MeshType::level_cell_iterator &)> &pack,
2754 const std::function<void(const typename MeshType::level_cell_iterator &,
2755 const DataType &)> &unpack,
2756 const std::function<bool(const typename MeshType::level_cell_iterator &)> &
2757 cell_filter = always_return<typename MeshType::level_cell_iterator, bool>{
2758 true});
2759
2760 /* Exchange with all processors of the MPI communicator @p mpi_communicator the vector of bounding
2761 * boxes @p local_bboxes.
2762 *
2763 * This function is meant to exchange bounding boxes describing the locally
2764 * owned cells in a distributed triangulation obtained with the function
2765 * GridTools::compute_mesh_predicate_bounding_box .
2766 *
2767 * The output vector's size is the number of processes of the MPI
2768 * communicator:
2769 * its i-th entry contains the vector @p local_bboxes of the i-th process.
2770 */
2771 template <int spacedim>
2772 std::vector<std::vector<BoundingBox<spacedim>>>
2774 const std::vector<BoundingBox<spacedim>> &local_bboxes,
2775 const MPI_Comm mpi_communicator);
2776
2809 template <int spacedim>
2812 const std::vector<BoundingBox<spacedim>> &local_description,
2813 const MPI_Comm mpi_communicator);
2814
2832 template <int dim, int spacedim>
2833 void
2835 const Triangulation<dim, spacedim> &tria,
2836 std::map<unsigned int, std::vector<unsigned int>> &coinciding_vertex_groups,
2837 std::map<unsigned int, unsigned int> &vertex_to_coinciding_vertex_group);
2838
2858 template <int dim, int spacedim>
2859 std::map<unsigned int, std::set<::types::subdomain_id>>
2861 const Triangulation<dim, spacedim> &tria);
2862
2883 template <int dim, typename VectorType>
2885 {
2886 public:
2890 using value_type = typename VectorType::value_type;
2891
2896 const FiniteElement<dim, dim> &fe,
2897 const unsigned int n_subdivisions = 1,
2898 const double tolerance = 1e-10);
2899
2910 void
2911 process(const DoFHandler<dim> &background_dof_handler,
2912 const VectorType &ls_vector,
2913 const double iso_level,
2914 std::vector<Point<dim>> &vertices,
2915 std::vector<CellData<dim == 1 ? 1 : dim - 1>> &cells) const;
2916
2921 void
2922 process(const DoFHandler<dim> &background_dof_handler,
2923 const VectorType &ls_vector,
2924 const double iso_level,
2925 std::vector<Point<dim>> &vertices) const;
2926
2936 void
2938 const VectorType &ls_vector,
2939 const double iso_level,
2940 std::vector<Point<dim>> &vertices,
2941 std::vector<CellData<dim == 1 ? 1 : dim - 1>> &cells) const;
2947 void
2949 const VectorType &ls_vector,
2950 const double iso_level,
2951 std::vector<Point<dim>> &vertices) const;
2952
2953 private:
2958 static Quadrature<dim>
2959 create_quadrature_rule(const unsigned int n_subdivisions);
2960
2964 void
2965 process_cell(std::vector<value_type> &ls_values,
2966 const std::vector<Point<dim>> &points,
2967 const double iso_level,
2968 std::vector<Point<dim>> &vertices,
2969 std::vector<CellData<dim == 1 ? 1 : dim - 1>> &cells,
2970 const bool write_back_cell_data = true) const;
2971
2975 void
2976 process_sub_cell(const std::vector<value_type> &,
2977 const std::vector<Point<1>> &,
2978 const std::vector<unsigned int> &,
2979 const double,
2980 std::vector<Point<1>> &,
2981 std::vector<CellData<1>> &,
2982 const bool) const
2983 {
2985 }
2986
2993 void
2994 process_sub_cell(const std::vector<value_type> &ls_values,
2995 const std::vector<Point<2>> &points,
2996 const std::vector<unsigned int> &mask,
2997 const double iso_level,
2998 std::vector<Point<2>> &vertices,
2999 std::vector<CellData<1>> &cells,
3000 const bool write_back_cell_data) const;
3001
3005 void
3006 process_sub_cell(const std::vector<value_type> &ls_values,
3007 const std::vector<Point<3>> &points,
3008 const std::vector<unsigned int> &mask,
3009 const double iso_level,
3010 std::vector<Point<3>> &vertices,
3011 std::vector<CellData<2>> &cells,
3012 const bool write_back_cell_data) const;
3013
3018 const unsigned int n_subdivisions;
3019
3024 const double tolerance;
3025
3031 };
3032
3033
3034
3044 int,
3045 << "The number of partitions you gave is " << arg1
3046 << ", but must be greater than zero.");
3051 int,
3052 << "The subdomain id " << arg1
3053 << " has no cells associated with it.");
3058
3063 double,
3064 << "The scaling factor must be positive, but it is " << arg1
3065 << '.');
3066
3071 unsigned int,
3072 << "The given vertex with index " << arg1
3073 << " is not used in the given triangulation.");
3074
3077} /*namespace GridTools*/
3078
3079/* ----------------- Template function --------------- */
3080
3081#ifndef DOXYGEN
3082
3083namespace GridTools
3084{
3085 template <int dim>
3086 double
3088 const std::vector<Point<dim>> &all_vertices,
3089 const unsigned int (&indices)[GeometryInfo<dim>::vertices_per_cell])
3090 {
3091 // We forward call to the ArrayView version:
3094 return cell_measure(all_vertices, view);
3095 }
3096
3097
3098
3099 template <int dim, typename Transformation, int spacedim>
3101 (std::invocable<Transformation, Point<spacedim>> &&
3102 std::assignable_from<
3104 std::invoke_result_t<Transformation, Point<spacedim>>>))
3105 void transform(const Transformation &transformation,
3106 Triangulation<dim, spacedim> &triangulation)
3107 {
3108 std::vector<bool> treated_vertices(triangulation.n_vertices(), false);
3109
3110 // loop over all active cells, and
3111 // transform those vertices that
3112 // have not yet been touched. note
3113 // that we get to all vertices in
3114 // the triangulation by only
3115 // visiting the active cells.
3117 cell = triangulation.begin_active(),
3118 endc = triangulation.end();
3119 for (; cell != endc; ++cell)
3120 for (const unsigned int v : cell->vertex_indices())
3121 if (treated_vertices[cell->vertex_index(v)] == false)
3122 {
3123 // transform this vertex
3124 cell->vertex(v) = transformation(cell->vertex(v));
3125 // and mark it as treated
3126 treated_vertices[cell->vertex_index(v)] = true;
3127 };
3128
3129
3130 // now fix any vertices on hanging nodes so that we don't create any holes
3131 if (dim == 2)
3132 {
3134 cell = triangulation.begin_active(),
3135 endc = triangulation.end();
3136 for (; cell != endc; ++cell)
3137 for (const unsigned int face : cell->face_indices())
3138 if (cell->face(face)->has_children() &&
3139 !cell->face(face)->at_boundary())
3140 {
3141 Assert(cell->reference_cell() ==
3142 ReferenceCells::get_hypercube<dim>(),
3144
3145 // this line has children
3146 cell->face(face)->child(0)->vertex(1) =
3147 (cell->face(face)->vertex(0) + cell->face(face)->vertex(1)) /
3148 2.0;
3149 }
3150 }
3151 else if (dim == 3)
3152 {
3154 cell = triangulation.begin_active(),
3155 endc = triangulation.end();
3156 for (; cell != endc; ++cell)
3157 for (const unsigned int face : cell->face_indices())
3158 if (cell->face(face)->has_children() &&
3159 !cell->face(face)->at_boundary())
3160 {
3161 if (static_cast<std::uint8_t>(
3162 cell->face(face)->refinement_case()) ==
3164 {
3165 Assert(cell->reference_cell() ==
3166 ReferenceCells::get_hypercube<dim>(),
3168
3169 // this face has hanging nodes
3170 cell->face(face)->child(0)->vertex(1) =
3171 (cell->face(face)->vertex(0) +
3172 cell->face(face)->vertex(1)) /
3173 2.0;
3174 cell->face(face)->child(0)->vertex(2) =
3175 (cell->face(face)->vertex(0) +
3176 cell->face(face)->vertex(2)) /
3177 2.0;
3178 cell->face(face)->child(1)->vertex(3) =
3179 (cell->face(face)->vertex(1) +
3180 cell->face(face)->vertex(3)) /
3181 2.0;
3182 cell->face(face)->child(2)->vertex(3) =
3183 (cell->face(face)->vertex(2) +
3184 cell->face(face)->vertex(3)) /
3185 2.0;
3186
3187 // center of the face
3188 cell->face(face)->child(0)->vertex(3) =
3189 (cell->face(face)->vertex(0) +
3190 cell->face(face)->vertex(1) +
3191 cell->face(face)->vertex(2) +
3192 cell->face(face)->vertex(3)) /
3193 4.0;
3194 }
3195 else
3196 {
3197 // Special case for anisotropic refinement
3198 for (unsigned int line = 0;
3199 line < GeometryInfo<dim - 1>::faces_per_cell;
3200 line++)
3201 if (cell->face(face)->line(line)->has_children())
3202 cell->face(face)->line(line)->child(0)->vertex(1) =
3203 (cell->face(face)->line(line)->vertex(0) +
3204 cell->face(face)->line(line)->vertex(1)) /
3205 2.0;
3206 }
3207 }
3208 }
3209
3210 // Make sure FEValues notices that the mesh has changed
3211 triangulation.signals.mesh_movement();
3212 }
3213
3214
3215
3216 template <typename MeshType>
3218 std::vector<typename MeshType::active_cell_iterator> get_active_child_cells(
3219 const typename MeshType::cell_iterator &cell)
3220 {
3221 std::vector<typename MeshType::active_cell_iterator> child_cells;
3222
3223 if (cell->has_children())
3224 {
3225 for (unsigned int child = 0; child < cell->n_children(); ++child)
3226 if (cell->child(child)->has_children())
3227 {
3228 const std::vector<typename MeshType::active_cell_iterator>
3229 children = get_active_child_cells<MeshType>(cell->child(child));
3230 child_cells.insert(child_cells.end(),
3231 children.begin(),
3232 children.end());
3233 }
3234 else
3235 child_cells.push_back(cell->child(child));
3236 }
3237
3238 return child_cells;
3239 }
3240
3241
3242
3243 template <typename MeshType>
3246 const typename MeshType::active_cell_iterator &cell,
3247 std::vector<typename MeshType::active_cell_iterator> &active_neighbors)
3248 {
3249 active_neighbors.clear();
3250 for (const unsigned int n : cell->face_indices())
3251 if (!cell->at_boundary(n))
3252 {
3253 if (MeshType::dimension == 1)
3254 {
3255 // check children of neighbor. note
3256 // that in 1d children of the neighbor
3257 // may be further refined. In 1d the
3258 // case is simple since we know what
3259 // children bound to the present cell
3260 typename MeshType::cell_iterator neighbor_child =
3261 cell->neighbor(n);
3262 if (!neighbor_child->is_active())
3263 {
3264 while (neighbor_child->has_children())
3265 neighbor_child = neighbor_child->child(n == 0 ? 1 : 0);
3266
3267 Assert(neighbor_child->neighbor(n == 0 ? 1 : 0) == cell,
3269 }
3270 active_neighbors.push_back(neighbor_child);
3271 }
3272 else
3273 {
3274 if (cell->face(n)->has_children())
3275 // this neighbor has children. find
3276 // out which border to the present
3277 // cell
3278 for (unsigned int c = 0;
3279 c < cell->face(n)->n_active_descendants();
3280 ++c)
3281 active_neighbors.push_back(
3282 cell->neighbor_child_on_subface(n, c));
3283 else
3284 {
3285 // the neighbor must be active
3286 // himself
3287 Assert(cell->neighbor(n)->is_active(), ExcInternalError());
3288 active_neighbors.push_back(cell->neighbor(n));
3289 }
3290 }
3291 }
3292 }
3293
3294
3295
3296 template <typename CellIterator>
3297 std::size_t
3299 {
3300 return sizeof(*this) + matrix.memory_consumption();
3301 }
3302
3303
3304
3305 namespace internal
3306 {
3307 template <typename DataType,
3308 typename MeshType,
3309 typename MeshCellIteratorType>
3311 inline void exchange_cell_data(
3312 const MeshType &mesh,
3313 const std::function<std::optional<DataType>(const MeshCellIteratorType &)>
3314 &pack,
3315 const std::function<void(const MeshCellIteratorType &, const DataType &)>
3316 &unpack,
3317 const std::function<bool(const MeshCellIteratorType &)> &cell_filter,
3318 const std::function<void(
3319 const std::function<void(const MeshCellIteratorType &,
3320 const types::subdomain_id)> &)> &process_cells,
3321 const std::function<std::set<types::subdomain_id>(
3322 const parallel::TriangulationBase<MeshType::dimension,
3323 MeshType::space_dimension> &)>
3324 &compute_ghost_owners)
3325 {
3326# ifndef DEAL_II_WITH_MPI
3327 (void)mesh;
3328 (void)pack;
3329 (void)unpack;
3330 (void)cell_filter;
3331 (void)process_cells;
3332 (void)compute_ghost_owners;
3333 Assert(false, ExcNeedsMPI());
3334# else
3335 constexpr int dim = MeshType::dimension;
3336 constexpr int spacedim = MeshType::space_dimension;
3337 auto tria =
3338 dynamic_cast<const parallel::TriangulationBase<dim, spacedim> *>(
3339 &mesh.get_triangulation());
3340 Assert(
3341 tria != nullptr,
3342 ExcMessage(
3343 "The function exchange_cell_data_to_ghosts() only works with parallel triangulations."));
3344
3345 if (const auto tria = dynamic_cast<
3347 &mesh.get_triangulation()))
3348 {
3349 Assert(
3350 tria->with_artificial_cells(),
3351 ExcMessage(
3352 "The functions GridTools::exchange_cell_data_to_ghosts() and "
3353 "GridTools::exchange_cell_data_to_level_ghosts() can only "
3354 "operate on a single layer of ghost cells. However, you have "
3355 "given a Triangulation object of type "
3356 "parallel::shared::Triangulation without artificial cells "
3357 "resulting in an arbitrary number of ghost layers. "
3358 "To use this function for a Triangulation object of type "
3359 "parallel::shared::Triangulation, make sure to create the "
3360 "Triangulation object with allow_artificial_cells set to true. "
3361 "This results in a parallel::shared::Triangulation with only "
3362 "a single layer of ghost cells."));
3363 }
3364
3365 // build list of cells to request for each neighbor
3366 std::set<types::subdomain_id> ghost_owners = compute_ghost_owners(*tria);
3367 std::map<types::subdomain_id, std::vector<CellId::binary_type>>
3368 neighbor_cell_list;
3369
3370 for (const auto ghost_owner : ghost_owners)
3371 neighbor_cell_list[ghost_owner] = {};
3372
3373 process_cells([&](const auto &cell, const auto key) -> void {
3374 if (cell_filter(cell))
3375 {
3376 neighbor_cell_list[key].emplace_back(
3377 cell->id().template to_binary<spacedim>());
3378 }
3379 });
3380
3381 Assert(ghost_owners.size() == neighbor_cell_list.size(),
3383
3384
3385 // Before sending & receiving, make sure we protect this section with
3386 // a mutex:
3389 mutex, tria->get_mpi_communicator());
3390
3391 const int mpi_tag =
3393 const int mpi_tag_reply =
3395
3396 // send our requests
3397 std::vector<MPI_Request> requests(ghost_owners.size());
3398 {
3399 unsigned int idx = 0;
3400 for (const auto &it : neighbor_cell_list)
3401 {
3402 // send the data about the relevant cells
3403 const int ierr = MPI_Isend(it.second.data(),
3404 it.second.size() * sizeof(it.second[0]),
3405 MPI_BYTE,
3406 it.first,
3407 mpi_tag,
3408 tria->get_mpi_communicator(),
3409 &requests[idx]);
3410 AssertThrowMPI(ierr);
3411 ++idx;
3412 }
3413 }
3414
3415 // receive requests and reply with the results
3416 std::vector<MPI_Request> reply_requests(ghost_owners.size());
3417 std::vector<std::vector<char>> sendbuffers(ghost_owners.size());
3418
3419 for (unsigned int idx = 0; idx < ghost_owners.size(); ++idx)
3420 {
3421 MPI_Status status;
3422 int ierr = MPI_Probe(MPI_ANY_SOURCE,
3423 mpi_tag,
3424 tria->get_mpi_communicator(),
3425 &status);
3426 AssertThrowMPI(ierr);
3427
3428 int len;
3429 ierr = MPI_Get_count(&status, MPI_BYTE, &len);
3430 AssertThrowMPI(ierr);
3431 Assert(len % sizeof(typename CellId::binary_type) == 0,
3433
3434 const unsigned int n_cells = len / sizeof(CellId::binary_type);
3435 std::vector<CellId::binary_type> cells_with_requests(n_cells);
3436 std::vector<DataType> data_to_send;
3437 data_to_send.reserve(n_cells);
3438 std::vector<bool> cell_carries_data(n_cells, false);
3439
3440 ierr = MPI_Recv(cells_with_requests.data(),
3441 len,
3442 MPI_BYTE,
3443 status.MPI_SOURCE,
3444 status.MPI_TAG,
3445 tria->get_mpi_communicator(),
3446 &status);
3447 AssertThrowMPI(ierr);
3448
3449 // store data for each cell
3450 for (unsigned int c = 0; c < n_cells; ++c)
3451 {
3452 const auto cell =
3453 tria->create_cell_iterator(CellId(cells_with_requests[c]));
3454
3455 MeshCellIteratorType mesh_it(tria,
3456 cell->level(),
3457 cell->index(),
3458 &mesh);
3459
3460 std::optional<DataType> data = pack(mesh_it);
3461 if (data)
3462 {
3463 data_to_send.emplace_back(std::move(*data));
3464 cell_carries_data[c] = true;
3465 }
3466 }
3467
3468 // collect data for sending the reply in a buffer
3469
3470 // (a) make room for storing the local offsets in case we receive
3471 // other data
3472 sendbuffers[idx].resize(sizeof(std::size_t));
3473
3474 // (b) append the actual data and store how much memory it
3475 // corresponds to, which we then insert into the leading position of
3476 // the sendbuffer
3477 std::size_t size_of_send =
3478 Utilities::pack(data_to_send,
3479 sendbuffers[idx],
3480 /*enable_compression*/ false);
3481 std::memcpy(sendbuffers[idx].data(),
3482 &size_of_send,
3483 sizeof(std::size_t));
3484
3485 // (c) append information of certain cells that got left out in case
3486 // we need it
3487 if (data_to_send.size() < n_cells)
3488 Utilities::pack(cell_carries_data,
3489 sendbuffers[idx],
3490 /*enable_compression*/ false);
3491
3492 // send data
3493 ierr = MPI_Isend(sendbuffers[idx].data(),
3494 sendbuffers[idx].size(),
3495 MPI_BYTE,
3496 status.MPI_SOURCE,
3497 mpi_tag_reply,
3498 tria->get_mpi_communicator(),
3499 &reply_requests[idx]);
3500 AssertThrowMPI(ierr);
3501 }
3502
3503 // finally receive the replies
3504 std::vector<char> receive;
3505 for (unsigned int id = 0; id < neighbor_cell_list.size(); ++id)
3506 {
3507 MPI_Status status;
3508 int ierr = MPI_Probe(MPI_ANY_SOURCE,
3509 mpi_tag_reply,
3510 tria->get_mpi_communicator(),
3511 &status);
3512 AssertThrowMPI(ierr);
3513
3514 int len;
3515 ierr = MPI_Get_count(&status, MPI_BYTE, &len);
3516 AssertThrowMPI(ierr);
3517
3518 receive.resize(len);
3519
3520 ierr = MPI_Recv(receive.data(),
3521 len,
3522 MPI_BYTE,
3523 status.MPI_SOURCE,
3524 status.MPI_TAG,
3525 tria->get_mpi_communicator(),
3526 &status);
3527 AssertThrowMPI(ierr);
3528
3529 // (a) first determine the length of the data section in the
3530 // received buffer
3531 auto data_iterator = receive.begin();
3532 std::size_t size_of_received_data =
3533 Utilities::unpack<std::size_t>(data_iterator,
3534 data_iterator + sizeof(std::size_t));
3535 data_iterator += sizeof(std::size_t);
3536
3537 // (b) unpack the data section in the indicated region
3538 auto received_data = Utilities::unpack<std::vector<DataType>>(
3539 data_iterator,
3540 data_iterator + size_of_received_data,
3541 /*enable_compression*/ false);
3542 data_iterator += size_of_received_data;
3543
3544 // (c) check if the received data contained fewer entries than the
3545 // number of cells we identified in the beginning, in which case we
3546 // need to extract the boolean vector with the relevant information
3547 const std::vector<CellId::binary_type> &this_cell_list =
3548 neighbor_cell_list[status.MPI_SOURCE];
3549 AssertIndexRange(received_data.size(), this_cell_list.size() + 1);
3550 std::vector<bool> cells_with_data;
3551 if (received_data.size() < this_cell_list.size())
3552 {
3553 cells_with_data = Utilities::unpack<std::vector<bool>>(
3554 data_iterator, receive.end(), /*enable_compression*/ false);
3555 AssertDimension(cells_with_data.size(), this_cell_list.size());
3556 }
3557
3558 // (d) go through the received data and call the user-provided
3559 // unpack function
3560 auto received_data_iterator = received_data.begin();
3561 for (unsigned int c = 0; c < this_cell_list.size(); ++c)
3562 if (cells_with_data.empty() || cells_with_data[c])
3563 {
3565 tria_cell = tria->create_cell_iterator(this_cell_list[c]);
3566
3567 MeshCellIteratorType cell(tria,
3568 tria_cell->level(),
3569 tria_cell->index(),
3570 &mesh);
3571
3572 unpack(cell, *received_data_iterator);
3573 ++received_data_iterator;
3574 }
3575 }
3576
3577 // make sure that all communication is finished
3578 // when we leave this function.
3579 if (requests.size() > 0)
3580 {
3581 const int ierr =
3582 MPI_Waitall(requests.size(), requests.data(), MPI_STATUSES_IGNORE);
3583 AssertThrowMPI(ierr);
3584 }
3585 if (reply_requests.size() > 0)
3586 {
3587 const int ierr = MPI_Waitall(reply_requests.size(),
3588 reply_requests.data(),
3589 MPI_STATUSES_IGNORE);
3590 AssertThrowMPI(ierr);
3591 }
3592
3593
3594# endif // DEAL_II_WITH_MPI
3595 }
3596
3597 } // namespace internal
3598
3599 template <typename DataType, typename MeshType>
3601 inline void exchange_cell_data_to_ghosts(
3602 const MeshType &mesh,
3603 const std::function<std::optional<DataType>(
3604 const typename MeshType::active_cell_iterator &)> &pack,
3605 const std::function<void(const typename MeshType::active_cell_iterator &,
3606 const DataType &)> &unpack,
3607 const std::function<bool(const typename MeshType::active_cell_iterator &)>
3608 &cell_filter)
3609 {
3610# ifndef DEAL_II_WITH_MPI
3611 (void)mesh;
3612 (void)pack;
3613 (void)unpack;
3614 (void)cell_filter;
3615 Assert(false, ExcNeedsMPI());
3616# else
3617 internal::exchange_cell_data<DataType,
3618 MeshType,
3619 typename MeshType::active_cell_iterator>(
3620 mesh,
3621 pack,
3622 unpack,
3623 cell_filter,
3624 [&](const auto &process) {
3625 for (const auto &cell : mesh.active_cell_iterators())
3626 if (cell->is_ghost())
3627 process(cell, cell->subdomain_id());
3628 },
3629 [](const auto &tria) { return tria.ghost_owners(); });
3630# endif
3631 }
3632
3633
3634
3635 template <typename DataType, typename MeshType>
3638 const MeshType &mesh,
3639 const std::function<std::optional<DataType>(
3640 const typename MeshType::level_cell_iterator &)> &pack,
3641 const std::function<void(const typename MeshType::level_cell_iterator &,
3642 const DataType &)> &unpack,
3643 const std::function<bool(const typename MeshType::level_cell_iterator &)>
3644 &cell_filter)
3645 {
3646# ifndef DEAL_II_WITH_MPI
3647 (void)mesh;
3648 (void)pack;
3649 (void)unpack;
3650 (void)cell_filter;
3651 Assert(false, ExcNeedsMPI());
3652# else
3653 internal::exchange_cell_data<DataType,
3654 MeshType,
3655 typename MeshType::level_cell_iterator>(
3656 mesh,
3657 pack,
3658 unpack,
3659 cell_filter,
3660 [&](const auto &process) {
3661 for (const auto &cell : mesh.cell_iterators())
3662 if (cell->is_ghost_on_level())
3663 process(cell, cell->level_subdomain_id());
3664 },
3665 [](const auto &tria) { return tria.level_ghost_owners(); });
3666# endif
3667 }
3668} // namespace GridTools
3669
3670#endif // DOXYGEN
3671
3673
3674#endif
std::array< std::uint64_t, 3 > binary_type
Definition cell_id.h:71
typename VectorType::value_type value_type
const unsigned int n_subdivisions
static Quadrature< dim > create_quadrature_rule(const unsigned int n_subdivisions)
void process_cell(const typename DoFHandler< dim >::active_cell_iterator &cell, const VectorType &ls_vector, const double iso_level, std::vector< Point< dim > > &vertices, std::vector< CellData< dim==1 ? 1 :dim - 1 > > &cells) const
void process_sub_cell(const std::vector< value_type > &, const std::vector< Point< 1 > > &, const std::vector< unsigned int > &, const double, std::vector< Point< 1 > > &, std::vector< CellData< 1 > > &, const bool) const
void process(const DoFHandler< dim > &background_dof_handler, const VectorType &ls_vector, const double iso_level, std::vector< Point< dim > > &vertices, std::vector< CellData< dim==1 ? 1 :dim - 1 > > &cells) const
Abstract base class for mapping classes.
Definition mapping.h:318
Definition point.h:111
cell_iterator create_cell_iterator(const CellId &cell_id) const
virtual MPI_Comm get_mpi_communicator() const
typename MeshType::active_cell_iterator type
Definition grid_tools.h:104
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_CXX20_REQUIRES(condition)
Definition config.h:249
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
unsigned int level
Definition grid_out.cc:4642
unsigned int vertex_indices[2]
#define DeclException0(Exception0)
static ::ExceptionBase & ExcNotImplemented()
static ::ExceptionBase & ExcNeedsMPI()
static ::ExceptionBase & ExcNonExistentSubdomain(int arg1)
#define Assert(cond, exc)
static ::ExceptionBase & ExcVertexNotUsed(unsigned int arg1)
#define AssertDimension(dim1, dim2)
#define AssertThrowMPI(error_code)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcTriangulationHasBeenRefined()
#define DeclException1(Exception1, type1, outsequence)
static ::ExceptionBase & ExcInvalidNumberOfPartitions(int arg1)
static ::ExceptionBase & ExcMessage(std::string arg1)
static ::ExceptionBase & ExcScalingFactorNotPositive(double arg1)
#define AssertThrow(cond, exc)
typename ActiveSelector::active_cell_iterator active_cell_iterator
void copy_boundary_to_manifold_id(Triangulation< dim, spacedim > &tria, const bool reset_boundary_ids=false)
void copy_material_to_manifold_id(Triangulation< dim, spacedim > &tria, const bool compute_face_ids=false)
void map_boundary_to_manifold_ids(const std::vector< types::boundary_id > &src_boundary_ids, const std::vector< types::manifold_id > &dst_manifold_ids, Triangulation< dim, spacedim > &tria, const std::vector< types::boundary_id > &reset_boundary_ids={})
void assign_co_dimensional_manifold_indicators(Triangulation< dim, spacedim > &tria, const std::function< types::manifold_id(const std::set< types::manifold_id > &)> &disambiguation_function=[](const std::set< types::manifold_id > &manifold_ids) { if(manifold_ids.size()==1) return *manifold_ids.begin();else return numbers::flat_manifold_id;}, bool overwrite_only_flat_manifold_ids=true)
std::vector< index_type > data
Definition mpi.cc:734
std::size_t size
Definition mpi.cc:733
const MPI_Comm comm
Definition mpi.cc:912
DistributedComputePointLocationsInternal< dim, spacedim > distributed_compute_point_locations(const GridTools::Cache< dim, spacedim > &cache, const std::vector< Point< spacedim > > &points, const std::vector< std::vector< BoundingBox< spacedim > > > &global_bboxes, const std::vector< bool > &marked_vertices, const double tolerance, const bool perform_handshake, const bool enforce_unique_mapping=false)
DistributedComputeIntersectionLocationsInternal< structdim, spacedim > distributed_compute_intersection_locations(const Cache< dim, spacedim > &cache, const std::vector< std::vector< Point< spacedim > > > &intersection_requests, const std::vector< std::vector< BoundingBox< spacedim > > > &global_bboxes, const std::vector< bool > &marked_vertices, const double tolerance)
std::vector< BoundingBox< MeshType::space_dimension > > compute_mesh_predicate_bounding_box(const MeshType &mesh, const std::function< bool(const typename MeshType::active_cell_iterator &)> &predicate, const unsigned int refinement_level=0, const bool allow_merge=false, const unsigned int max_boxes=numbers::invalid_unsigned_int)
void scale(const double scaling_factor, Triangulation< dim, spacedim > &triangulation)
RTree< std::pair< BoundingBox< spacedim >, unsigned int > > build_global_description_tree(const std::vector< BoundingBox< spacedim > > &local_description, const MPI_Comm mpi_communicator)
std::vector< typename MeshType::active_cell_iterator > get_active_child_cells(const typename MeshType::cell_iterator &cell)
void partition_triangulation_zorder(const unsigned int n_partitions, Triangulation< dim, spacedim > &triangulation, const bool group_siblings=true)
std::vector< typename Container::cell_iterator > get_cells_at_coarsest_common_level(const std::vector< typename Container::active_cell_iterator > &patch_cells)
void rotate(const double angle, Triangulation< dim, spacedim > &triangulation)
return_type compute_point_locations(const Cache< dim, spacedim > &cache, const std::vector< Point< spacedim > > &points, const typename Triangulation< dim, spacedim >::active_cell_iterator &cell_hint=typename Triangulation< dim, spacedim >::active_cell_iterator())
void collect_periodic_faces(const MeshType &mesh, const types::boundary_id b_id1, const types::boundary_id b_id2, const unsigned int direction, std::vector< PeriodicFacePair< typename MeshType::cell_iterator > > &matched_pairs, const Tensor< 1, MeshType::space_dimension > &offset=::Tensor< 1, MeshType::space_dimension >(), const FullMatrix< double > &matrix=FullMatrix< double >(), const double abs_tol=1e-10)
unsigned int find_closest_vertex(const std::map< unsigned int, Point< spacedim > > &vertices, const Point< spacedim > &p)
void transform(const Transformation &transformation, Triangulation< dim, spacedim > &triangulation)
std::pair< typename MeshType< dim, spacedim >::active_cell_iterator, Point< dim > > find_active_cell_around_point(const Mapping< dim, spacedim > &mapping, const MeshType< dim, spacedim > &mesh, const Point< spacedim > &p, const std::vector< bool > &marked_vertices={}, const double tolerance=1.e-10)
void get_active_neighbors(const typename MeshType::active_cell_iterator &cell, std::vector< typename MeshType::active_cell_iterator > &active_neighbors)
std::vector< bool > get_locally_owned_vertices(const Triangulation< dim, spacedim > &triangulation)
std::vector< types::global_vertex_index > parallel_to_serial_vertex_indices(const Triangulation< dim, spacedim > &serial_tria, const Triangulation< dim, spacedim > &parallel_tria)
void regularize_corner_cells(Triangulation< dim, spacedim > &tria, const double limit_angle_fraction=.75)
void shift(const Tensor< 1, spacedim > &shift_vector, Triangulation< dim, spacedim > &triangulation)
std::vector< typename MeshType::active_cell_iterator > find_cells_adjacent_to_vertex(const MeshType &container, const unsigned int vertex_index)
std::vector< typename MeshType::active_cell_iterator > compute_active_cell_halo_layer(const MeshType &mesh, const std::function< bool(const typename MeshType::active_cell_iterator &)> &predicate)
void exchange_cell_data_to_level_ghosts(const MeshType &mesh, const std::function< std::optional< DataType >(const typename MeshType::level_cell_iterator &)> &pack, const std::function< void(const typename MeshType::level_cell_iterator &, const DataType &)> &unpack, const std::function< bool(const typename MeshType::level_cell_iterator &)> &cell_filter=always_return< typename MeshType::level_cell_iterator, bool >{ true})
std::vector< typename MeshType::active_cell_iterator > compute_active_cell_layer_within_distance(const MeshType &mesh, const std::function< bool(const typename MeshType::active_cell_iterator &)> &predicate, const double layer_thickness)
std::map< unsigned int, types::global_vertex_index > compute_local_to_global_vertex_index_map(const Triangulation< dim, spacedim > &triangulation)
std::vector< typename MeshType::active_cell_iterator > compute_ghost_cell_halo_layer(const MeshType &mesh)
void exchange_cell_data_to_ghosts(const MeshType &mesh, const std::function< std::optional< DataType >(const typename MeshType::active_cell_iterator &)> &pack, const std::function< void(const typename MeshType::active_cell_iterator &, const DataType &)> &unpack, const std::function< bool(const typename MeshType::active_cell_iterator &)> &cell_filter=always_return< typename MeshType::active_cell_iterator, bool >{true})
void laplace_transform(const std::map< unsigned int, Point< dim > > &new_points, Triangulation< dim > &tria, const Function< dim, double > *coefficient=nullptr, const bool solve_for_absolute_positions=false)
void partition_multigrid_levels(Triangulation< dim, spacedim > &triangulation)
unsigned int find_closest_vertex_of_cell(const typename Triangulation< dim, spacedim >::active_cell_iterator &cell, const Point< spacedim > &position, const Mapping< dim, spacedim > &mapping=(ReferenceCells::get_hypercube< dim >() .template get_default_linear_mapping< spacedim >()))
std::map< unsigned int, std::set<::types::subdomain_id > > compute_vertices_with_ghost_neighbors(const Triangulation< dim, spacedim > &tria)
void collect_coinciding_vertices(const Triangulation< dim, spacedim > &tria, std::map< unsigned int, std::vector< unsigned int > > &coinciding_vertex_groups, std::map< unsigned int, unsigned int > &vertex_to_coinciding_vertex_group)
unsigned int count_cells_with_subdomain_association(const Triangulation< dim, spacedim > &triangulation, const types::subdomain_id subdomain)
return_type guess_point_owner(const std::vector< std::vector< BoundingBox< spacedim > > > &global_bboxes, const std::vector< Point< spacedim > > &points)
std::map< types::global_dof_index, std::vector< typename DoFHandler< dim, spacedim >::active_cell_iterator > > get_dof_to_support_patch_map(DoFHandler< dim, spacedim > &dof_handler)
std::vector< typename MeshType::cell_iterator > compute_cell_halo_layer_on_level(const MeshType &mesh, const std::function< bool(const typename MeshType::cell_iterator &)> &predicate, const unsigned int level)
void partition_triangulation(const unsigned int n_partitions, Triangulation< dim, spacedim > &triangulation, const SparsityTools::Partitioner partitioner=SparsityTools::Partitioner::metis)
std::vector< std::set< typename Triangulation< dim, spacedim >::active_cell_iterator > > vertex_to_cell_map(const Triangulation< dim, spacedim > &triangulation)
std::vector< typename MeshType::active_cell_iterator > compute_ghost_cell_layer_within_distance(const MeshType &mesh, const double layer_thickness)
return_type compute_point_locations_try_all(const Cache< dim, spacedim > &cache, const std::vector< Point< spacedim > > &points, const typename Triangulation< dim, spacedim >::active_cell_iterator &cell_hint=typename Triangulation< dim, spacedim >::active_cell_iterator())
std::vector< typename MeshType::active_cell_iterator > get_patch_around_cell(const typename MeshType::active_cell_iterator &cell)
std::vector< types::subdomain_id > get_subdomain_association(const Triangulation< dim, spacedim > &triangulation, const std::vector< CellId > &cell_ids)
void distort_random(const double factor, Triangulation< dim, spacedim > &triangulation, const bool keep_boundary=true, const unsigned int seed=boost::random::mt19937::default_seed)
std::vector< std::vector< Tensor< 1, spacedim > > > vertex_to_cell_centers_directions(const Triangulation< dim, spacedim > &mesh, const std::vector< std::set< typename Triangulation< dim, spacedim >::active_cell_iterator > > &vertex_to_cells)
std::vector< std::pair< typename MeshType< dim, spacedim >::active_cell_iterator, Point< dim > > > find_all_active_cells_around_point(const Mapping< dim, spacedim > &mapping, const MeshType< dim, spacedim > &mesh, const Point< spacedim > &p, const double tolerance, const std::pair< typename MeshType< dim, spacedim >::active_cell_iterator, Point< dim > > &first_cell, const std::vector< std::set< typename MeshType< dim, spacedim >::active_cell_iterator > > *vertex_to_cells=nullptr)
void build_triangulation_from_patch(const std::vector< typename Container::active_cell_iterator > &patch, Triangulation< Container::dimension, Container::space_dimension > &local_triangulation, std::map< typename Triangulation< Container::dimension, Container::space_dimension >::active_cell_iterator, typename Container::active_cell_iterator > &patch_to_global_tria_map)
std::optional< types::geometric_orientation > orthogonal_equality(const FaceIterator &face1, const FaceIterator &face2, const unsigned int direction, const Tensor< 1, FaceIterator::AccessorType::space_dimension > &offset=Tensor< 1, FaceIterator::AccessorType::space_dimension >(), const FullMatrix< double > &matrix=FullMatrix< double >(), const double abs_tol=1e-10)
std::vector< std::vector< BoundingBox< spacedim > > > exchange_local_bounding_boxes(const std::vector< BoundingBox< spacedim > > &local_bboxes, const MPI_Comm mpi_communicator)
double cell_measure(const std::vector< Point< dim > > &all_vertices, const ArrayView< const unsigned int > &vertex_indices)
return_type distributed_compute_point_locations(const GridTools::Cache< dim, spacedim > &cache, const std::vector< Point< spacedim > > &local_points, const std::vector< std::vector< BoundingBox< spacedim > > > &global_bboxes, const double tolerance=1e-10, const std::vector< bool > &marked_vertices={}, const bool enforce_unique_mapping=true)
@ matrix
Contents is actually a matrix.
*  *  if(update_pressure &update_flags) *  compute_pressure(constitutive_request
@ exchange_cell_data_request
grid_tools.h: exchange_cell_ghosts()
Definition mpi_tags.h:64
@ exchange_cell_data_reply
grid_tools.h: exchange_cell_ghosts()
Definition mpi_tags.h:67
std::size_t pack(const T &object, std::vector< char > &dest_buffer, const bool allow_compression=true)
Definition utilities.h:1352
T unpack(const std::vector< char > &buffer, const bool allow_compression=true)
Definition utilities.h:1509
Definition hp.h:115
unsigned int n_cells(const internal::TriangulationImplementation::NumberCache< 1 > &c)
Definition tria.cc:15802
constexpr types::manifold_id flat_manifold_id
Definition types.h:332
STL namespace.
Definition types.h:30
unsigned int global_dof_index
Definition types.h:92
unsigned int subdomain_id
Definition types.h:50
std::uint8_t geometric_orientation
Definition types.h:38
boost::geometry::index::rtree< LeafType, IndexType, IndexableGetter > RTree
Definition rtree.h:159
std::size_t memory_consumption() const
FullMatrix< double > matrix
types::geometric_orientation orientation
std::map< unsigned int, std::vector< unsigned int > > communicate_indices(const std::vector< std::tuple< unsigned int, unsigned int, unsigned int > > &point_recv_components, const MPI_Comm comm) const
GridTools::internal::DistributedComputePointLocationsInternal< dim, spacedim > convert_to_distributed_compute_point_locations_internal(const unsigned int n_points_1D, const Triangulation< dim, spacedim > &tria, const Mapping< dim, spacedim > &mapping, std::vector< Quadrature< spacedim > > *mapped_quadratures_recv_comp=nullptr, const bool consistent_numbering_of_sender_and_receiver=false) const
std::vector< std::tuple< std::pair< int, int >, unsigned int, unsigned int, IntersectionType > > send_components
Definition grid_tools.h:849
std::vector< std::tuple< unsigned int, unsigned int, IntersectionType > > recv_components
Definition grid_tools.h:860
std::array<::Point< spacedim >, structdim+1 > IntersectionType
Definition grid_tools.h:835
std::vector< std::tuple< unsigned int, unsigned int, unsigned int > > recv_components
Definition grid_tools.h:785
std::vector< std::tuple< std::pair< int, int >, unsigned int, unsigned int, Point< dim >, Point< spacedim >, unsigned int > > send_components
Definition grid_tools.h:760