Reference documentation for deal.II version GIT relicensing-222-g16f23ad599 2024-03-28 18:20: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\}}\)
Loading...
Searching...
No Matches
mpi_remote_point_evaluation.cc
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2021 - 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#include <deal.II/base/config.h>
16
20
22
23#include <deal.II/fe/mapping.h>
24
28#include <deal.II/grid/tria.h>
29
31
32
33namespace Utilities
34{
35 namespace MPI
36 {
37 template <int dim, int spacedim>
39 const double tolerance,
40 const bool enforce_unique_mapping,
41 const unsigned int rtree_level,
42 const std::function<std::vector<bool>()> &marked_vertices)
43 : tolerance(tolerance)
44 , enforce_unique_mapping(enforce_unique_mapping)
45 , rtree_level(rtree_level)
46 , marked_vertices(marked_vertices)
47 {}
48
49
50
51 template <int dim, int spacedim>
57
58
59
60 template <int dim, int spacedim>
62 const double tolerance,
63 const bool enforce_unique_mapping,
64 const unsigned int rtree_level,
65 const std::function<std::vector<bool>()> &marked_vertices)
66 : additional_data(tolerance,
67 enforce_unique_mapping,
68 rtree_level,
69 marked_vertices)
70 , ready_flag(false)
71 {}
72
73
74
75 template <int dim, int spacedim>
77 {
78 if (tria_signal.connected())
79 tria_signal.disconnect();
80 }
81
82
83
84 template <int dim, int spacedim>
85 void
87 const std::vector<Point<spacedim>> &points,
89 const Mapping<dim, spacedim> &mapping)
90 {
91#ifndef DEAL_II_WITH_MPI
92 Assert(false, ExcNeedsMPI());
93 (void)points;
94 (void)tria;
95 (void)mapping;
96#else
97 if (tria_signal.connected())
98 tria_signal.disconnect();
99
100 tria_signal =
101 tria.signals.any_change.connect([&]() { this->ready_flag = false; });
102
103 std::vector<BoundingBox<spacedim>> local_boxes;
104 for (const auto &cell :
105 tria.active_cell_iterators() | IteratorFilters::LocallyOwnedCell())
106 local_boxes.push_back(mapping.get_bounding_box(cell));
107
108 // create r-tree of bounding boxes
109 const auto local_tree = pack_rtree(local_boxes);
110
111 // compress r-tree to a minimal set of bounding boxes
112 std::vector<std::vector<BoundingBox<spacedim>>> global_bboxes(1);
113 global_bboxes[0] =
114 extract_rtree_level(local_tree, additional_data.rtree_level);
115
116 const GridTools::Cache<dim, spacedim> cache(tria, mapping);
117
118 const auto data =
120 cache,
121 points,
122 global_bboxes,
123 additional_data.marked_vertices ? additional_data.marked_vertices() :
124 std::vector<bool>(),
125 additional_data.tolerance,
126 true,
127 additional_data.enforce_unique_mapping);
128
129 this->reinit(data, tria, mapping);
130#endif
131 }
132
133
134
135 template <int dim, int spacedim>
136 void
138 const GridTools::internal::
139 DistributedComputePointLocationsInternal<dim, spacedim> &data,
140 const Triangulation<dim, spacedim> &tria,
141 const Mapping<dim, spacedim> &mapping)
142 {
143 this->tria = &tria;
144 this->mapping = &mapping;
145
146 this->recv_ranks = data.recv_ranks;
147 this->recv_ptrs = data.recv_ptrs;
148
149 this->send_ranks = data.send_ranks;
150 this->send_ptrs = data.send_ptrs;
151
152 this->recv_permutation = {};
153 this->recv_permutation.resize(data.recv_components.size());
154 this->point_ptrs.assign(data.n_searched_points + 1, 0);
155 for (unsigned int i = 0; i < data.recv_components.size(); ++i)
156 {
157 AssertIndexRange(std::get<2>(data.recv_components[i]),
158 this->recv_permutation.size());
159 this->recv_permutation[std::get<2>(data.recv_components[i])] = i;
160
161 AssertIndexRange(std::get<1>(data.recv_components[i]) + 1,
162 this->point_ptrs.size());
163 this->point_ptrs[std::get<1>(data.recv_components[i]) + 1]++;
165
166 std::tuple<unsigned int, unsigned int> n_owning_processes_default{
168 std::tuple<unsigned int, unsigned int> n_owning_processes_local =
169 n_owning_processes_default;
170
171 for (unsigned int i = 0; i < data.n_searched_points; ++i)
172 {
173 std::get<0>(n_owning_processes_local) =
174 std::min(std::get<0>(n_owning_processes_local),
175 this->point_ptrs[i + 1]);
176 std::get<1>(n_owning_processes_local) =
177 std::max(std::get<1>(n_owning_processes_local),
178 this->point_ptrs[i + 1]);
179
180 this->point_ptrs[i + 1] += this->point_ptrs[i];
182
183 const auto n_owning_processes_global =
184 Utilities::MPI::all_reduce<std::tuple<unsigned int, unsigned int>>(
185 n_owning_processes_local,
186 tria.get_communicator(),
187 [&](const auto &a,
188 const auto &b) -> std::tuple<unsigned int, unsigned int> {
189 if (a == n_owning_processes_default)
190 return b;
191
192 if (b == n_owning_processes_default)
193 return a;
194
195 return std::tuple<unsigned int, unsigned int>{
196 std::min(std::get<0>(a), std::get<0>(b)),
197 std::max(std::get<1>(a), std::get<1>(b))};
198 });
199
200 if (n_owning_processes_global == n_owning_processes_default)
201 {
202 unique_mapping = true;
204 }
205 else
206 {
207 unique_mapping = (std::get<0>(n_owning_processes_global) == 1) &&
208 (std::get<1>(n_owning_processes_global) == 1);
209 all_points_found_flag = std::get<0>(n_owning_processes_global) > 0;
210 }
211
214
215 cell_data = std::make_unique<CellData>(tria);
216 send_permutation = {};
217
218 std::pair<int, int> dummy{-1, -1};
219 for (const auto &i : data.send_components)
220 {
221 if (dummy != std::get<0>(i))
222 {
223 dummy = std::get<0>(i);
224 cell_data->cells.emplace_back(dummy);
225 cell_data->reference_point_ptrs.emplace_back(
226 cell_data->reference_point_values.size());
227 }
228
229 cell_data->reference_point_values.emplace_back(std::get<3>(i));
230 send_permutation.emplace_back(std::get<5>(i));
231 }
232
233 cell_data->reference_point_ptrs.emplace_back(
234 cell_data->reference_point_values.size());
235
236 this->ready_flag = true;
237 }
238
239
240
241 template <int dim, int spacedim>
246
247
248
249 template <int dim, int spacedim>
252 {
253 return {0, static_cast<unsigned int>(cells.size())};
254 }
255
256
257
258 template <int dim, int spacedim>
261 const unsigned int cell) const
262 {
263 AssertIndexRange(cell, cells.size());
264 return {&triangulation, cells[cell].first, cells[cell].second};
265 }
266
267
268
269 template <int dim, int spacedim>
272 const unsigned int cell) const
273 {
274 AssertIndexRange(cell, cells.size());
275 return {reference_point_values.data() + reference_point_ptrs[cell],
276 reference_point_ptrs[cell + 1] - reference_point_ptrs[cell]};
277 }
278
279
280
281 template <int dim, int spacedim>
287
288
289
290 template <int dim, int spacedim>
291 const std::vector<unsigned int> &
296
297
298
299 template <int dim, int spacedim>
300 bool
305
306
307
308 template <int dim, int spacedim>
309 bool
314
315
316
317 template <int dim, int spacedim>
318 bool
320 const unsigned int i) const
321 {
322 AssertIndexRange(i, point_ptrs.size() - 1);
323
325 return true;
326 else
327 return (point_ptrs[i + 1] - point_ptrs[i]) > 0;
328 }
329
330
331
332 template <int dim, int spacedim>
336 return *tria;
337 }
338
339
340
341 template <int dim, int spacedim>
348
349
350 template <int dim, int spacedim>
351 bool
354 return ready_flag;
355 }
356
357 } // end of namespace MPI
358} // end of namespace Utilities
360#include "mpi_remote_point_evaluation.inst"
361
Abstract base class for mapping classes.
Definition mapping.h:316
Definition point.h:111
Signals signals
Definition tria.h:2529
std_cxx20::ranges::iota_view< unsigned int, unsigned int > cell_indices() const
ArrayView< const Point< dim > > get_unit_points(const unsigned int cell) const
Triangulation< dim, spacedim >::active_cell_iterator get_active_cell_iterator(const unsigned int cell) const
CellData(const Triangulation< dim, spacedim > &triangulation)
RemotePointEvaluation(const AdditionalData &additional_data=AdditionalData())
const Triangulation< dim, spacedim > & get_triangulation() const
SmartPointer< const Mapping< dim, spacedim > > mapping
const std::vector< unsigned int > & get_point_ptrs() const
const Mapping< dim, spacedim > & get_mapping() const
SmartPointer< const Triangulation< dim, spacedim > > tria
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
static ::ExceptionBase & ExcNeedsMPI()
#define Assert(cond, exc)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
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)
static const unsigned int invalid_unsigned_int
Definition types.h:220
boost::integer_range< IncrementableType > iota_view
Definition iota_view.h:45
STL namespace.
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation
std::vector< BoundingBox< boost::geometry::dimension< typename Rtree::indexable_type >::value > > extract_rtree_level(const Rtree &tree, const unsigned int level)
RTree< typename LeafTypeIterator::value_type, IndexType, IndexableGetter > pack_rtree(const LeafTypeIterator &begin, const LeafTypeIterator &end)
AdditionalData(const double tolerance=1e-6, const bool enforce_unique_mapping=false, const unsigned int rtree_level=0, const std::function< std::vector< bool >()> &marked_vertices={})