deal.II version GIT relicensing-6917-gb466a1809f 2026-10-16 06: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
access_traits.cc
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) 2021 - 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
14
15#include <ArborX.hpp>
16
18
19namespace ArborXWrappers
20{
21#if ARBORX_VERSION_MAJOR < 2
22
23 namespace
24 {
25 template <int dim, typename Number>
27 to_3d_float_point(::Point<dim, Number> p)
28 {
29 static_assert(dim >= 1 && dim <= 3);
30 if (dim == 1)
31 return Point<3, float>(p[0], 0.f, 0.f);
32 else if (dim == 2)
33 return Point<3, float>(p[0], p[1], 0.f);
34 else
35 return Point<3, float>(p[0], p[1], p[2]);
36 }
37 } // namespace
38
39 // ------------------- PointPredicate ------------------- //
40 template <int dim, typename Number>
42 const std::vector<::Point<dim, Number>> &dim_points)
43 {
44 const unsigned int size = dim_points.size();
45 points.reserve(size);
46 for (unsigned int i = 0; i < size; ++i)
47 points.emplace_back(to_3d_float_point(dim_points[i]));
48 }
49
51
52 std::size_t
54 {
55 return points.size();
56 }
57
58
59
60 const ::Point<3, float> &
61 PointPredicate::get(unsigned int i) const
62 {
63 return points[i];
64 }
65
66
67
68 template <int dim, typename Number>
73
74
75
76 template <int dim, typename Number>
78 const std::vector<::Point<dim, Number>> &points,
79 const unsigned int n_nearest_neighbors)
80 : PointPredicate(points)
81 , n_nearest_neighbors(n_nearest_neighbors)
82 {}
83
84
85
86 unsigned int
91
92 // ------------------- BoundingBoxPredicate ------------------- //
93 template <int dim, typename Number>
95 const std::vector<::BoundingBox<dim, Number>> &bb)
96 {
97 const unsigned int size = bb.size();
98 bounding_boxes.reserve(size);
99 ::Point<3, float> min_corner_arborx(0., 0., 0.);
100 ::Point<3, float> max_corner_arborx(0., 0., 0.);
101 for (unsigned int i = 0; i < size; ++i)
102 {
103 auto boundary_points = bb[i].get_boundary_points();
104 ::Point<dim, Number> min_corner = boundary_points.first;
105 ::Point<dim, Number> max_corner = boundary_points.second;
106 for (unsigned int d = 0; d < dim; ++d)
107 {
108 min_corner_arborx[d] = static_cast<float>(min_corner[d]);
109 max_corner_arborx[d] = static_cast<float>(max_corner[d]);
110 }
111 bounding_boxes.emplace_back(
112 std::make_pair(min_corner_arborx, max_corner_arborx));
113 }
114 }
115
116
117
118 std::size_t
120 {
121 return bounding_boxes.size();
122 }
123
124
125
126 const ::BoundingBox<3, float> &
127 BoundingBoxPredicate::get(unsigned int i) const
128 {
129 return bounding_boxes[i];
130 }
131
132
133
134 template <int dim, typename Number>
136 const std::vector<::BoundingBox<dim, Number>> &bounding_boxes)
137 : BoundingBoxPredicate(bounding_boxes)
138 {}
139
140
142 template <int dim, typename Number>
144 const std::vector<::BoundingBox<dim, Number>> &bounding_boxes,
145 const unsigned int n_nearest_neighbors)
146 : BoundingBoxPredicate(bounding_boxes)
147 , n_nearest_neighbors(n_nearest_neighbors)
148 {}
149
150
151
152 unsigned int
157
158 // ------------------- SpherePredicate ------------------- //
159 template <int dim, typename Number>
161 const std::vector<std::pair<::Point<dim, Number>, Number>>
162 &dim_spheres)
163 {
164 const unsigned int size = dim_spheres.size();
165 spheres.reserve(size);
166 for (unsigned int i = 0; i < size; ++i)
167 {
168 // ArborX assumes that the center coordinates and the radius use float
169 // and the sphere is 3d
170 spheres.emplace_back(to_3d_float_point(dim_spheres[i].first),
171 static_cast<float>(dim_spheres[i].second));
172 }
173 }
174
175
176
177 std::size_t
179 {
180 return spheres.size();
181 }
182
183
184
185 const std::pair<::Point<3, float>, float> &
186 SpherePredicate::get(unsigned int i) const
187 {
188 return spheres[i];
189 }
190
191
192
193 template <int dim, typename Number>
195 const std::vector<std::pair<::Point<dim, Number>, Number>> &spheres)
196 : SpherePredicate(spheres)
197 {}
198
199
200
201 template <int dim, typename Number>
203 const std::vector<std::pair<::Point<dim, Number>, Number>> &spheres,
204 const unsigned int n_nearest_neighbors)
205 : SpherePredicate(spheres)
206 , n_nearest_neighbors(n_nearest_neighbors)
207 {}
208
209
210
211 unsigned int
216#else
217 template <int dim, typename Number>
219 const std::vector<::Point<dim, Number>> &points)
220 : points(points)
221 {}
222
223
224
225 template <int dim, typename Number>
226 std::size_t
228 {
229 return points.size();
230 }
231
232
234 template <int dim, typename Number>
235 const ::Point<dim, Number> &
237 {
238 return points[i];
240
241
242 template <int dim, typename Number>
244 const std::vector<::Point<dim, Number>> &points,
245 const unsigned int n_nearest_neighbors)
246 : points(points)
247 , n_nearest_neighbors(n_nearest_neighbors)
248 {}
249
250
251
252 template <int dim, typename Number>
253 unsigned int
255 {
256 return n_nearest_neighbors;
257 }
258
259
260
261 template <int dim, typename Number>
262 std::size_t
264 {
265 return points.size();
266 }
267
268
269
270 template <int dim, typename Number>
271 const ::Point<dim, Number> &
272 PointNearestPredicate<dim, Number>::get(unsigned int i) const
273 {
274 return points[i];
275 }
276
277
278 // ------------------- BoundingBoxPredicate ------------------- //
279 template <int dim, typename Number>
281 const std::vector<::BoundingBox<dim, Number>> &bb)
282 : bounding_boxes(bb)
283 {}
284
285
286
287 template <int dim, typename Number>
288 std::size_t
290 {
291 return bounding_boxes.size();
292 }
293
294
295
296 template <int dim, typename Number>
297 const ::BoundingBox<dim, Number> &
299 {
300 return bounding_boxes[i];
301 }
302
303
304
305 template <int dim, typename Number>
307 const std::vector<::BoundingBox<dim, Number>> &bounding_boxes,
308 const unsigned int n_nearest_neighbors)
309 : bounding_boxes(bounding_boxes)
310 , n_nearest_neighbors(n_nearest_neighbors)
311 {}
312
313
314
315 template <int dim, typename Number>
316 unsigned int
318 {
319 return n_nearest_neighbors;
320 }
321
322
323
324 template <int dim, typename Number>
325 std::size_t
327 {
328 return bounding_boxes.size();
329 }
330
331
332
333 template <int dim, typename Number>
334 const ::BoundingBox<dim, Number> &
336 {
337 return bounding_boxes[i];
338 }
339
340 // ------------------- SpherePredicate ------------------- //
341 template <int dim, typename Number>
343 const std::vector<std::pair<::Point<dim, Number>, Number>> &spheres)
344 : spheres(spheres)
345 {}
346
347
348
349 template <int dim, typename Number>
350 std::size_t
352 {
353 return spheres.size();
354 }
355
356
357
358 template <int dim, typename Number>
359 const std::pair<::Point<dim, Number>, Number> &
361 {
362 return spheres[i];
363 }
364
365
366
367 template <int dim, typename Number>
369 const std::vector<std::pair<::Point<dim, Number>, Number>> &spheres,
370 const unsigned int n_nearest_neighbors)
371 : spheres(spheres)
372 , n_nearest_neighbors(n_nearest_neighbors)
373 {}
374
375
376
377 template <int dim, typename Number>
378 unsigned int
380 {
381 return n_nearest_neighbors;
382 }
383
384
385
386 template <int dim, typename Number>
387 std::size_t
389 {
390 return spheres.size();
391 }
392
393
394
395 template <int dim, typename Number>
396 const std::pair<::Point<dim, Number>, Number> &
397 SphereNearestPredicate<dim, Number>::get(unsigned int i) const
398 {
399 return spheres[i];
400 }
401#endif
402} // namespace ArborXWrappers
403
404
406
407namespace ArborX
408{
409#if ARBORX_VERSION_MAJOR < 2
410 namespace
411 {
412 template <int dim, typename Number>
413 Point
414 to_arborx_point(::Point<dim, Number> p)
415 {
416 static_assert(dim >= 1 && dim <= 3);
417 if (dim == 1)
418 return {float(p[0]), 0.f, 0.f};
419 else if (dim == 2)
420 return {float(p[0]), float(p[1]), 0.f};
421 else
422 return {float(p[0]), float(p[1]), float(p[2])};
423 }
424 } // namespace
425
426
427
428 // ------------------- Point Primitives AccessTraits ------------------- //
429 template <int dim, typename Number>
430 std::size_t
431 AccessTraits<std::vector<::Point<dim, Number>>, PrimitivesTag>::size(
432 const std::vector<::Point<dim, Number>> &v)
433 {
434 return v.size();
435 }
436
437
438
439 template <int dim, typename Number>
440 Point
441 AccessTraits<std::vector<::Point<dim, Number>>, PrimitivesTag>::get(
442 const std::vector<::Point<dim, Number>> &v,
443 std::size_t i)
444 {
445 // ArborX assumes that the point coordinates use float and that the point
446 // is 3d
447 return to_arborx_point(v[i]);
448 }
449
450
451
452 // ----------------- BoundingBox Primitives AccessTraits ----------------- //
453 template <int dim, typename Number>
454 std::size_t
455 AccessTraits<std::vector<::BoundingBox<dim, Number>>, PrimitivesTag>::
456 size(const std::vector<::BoundingBox<dim, Number>> &v)
457 {
458 return v.size();
459 }
460
461
462
463 template <int dim, typename Number>
464 Box
465 AccessTraits<std::vector<::BoundingBox<dim, Number>>, PrimitivesTag>::
466 get(const std::vector<::BoundingBox<dim, Number>> &v, std::size_t i)
467 {
468 const auto boundary_points = v[i].get_boundary_points();
469 const ::Point<dim, Number> min_corner = boundary_points.first;
470 const ::Point<dim, Number> max_corner = boundary_points.second;
471 // ArborX assumes that the bounding box coordinates use float and that the
472 // bounding box is 3d
473 return {to_arborx_point(min_corner), to_arborx_point(max_corner)};
474 }
475
476
477
478 // ---------------------- Sphere Primitives AccessTraits ----------------- //
479 template <int dim, typename Number>
480 std::size_t
481 AccessTraits<std::vector<std::pair<::Point<dim, Number>, Number>>,
482 PrimitivesTag>::
483 size(const std::vector<std::pair<::Point<dim, Number>, Number>> &v)
484 {
485 return v.size();
486 }
487
488
489
490 template <int dim, typename Number>
491 Sphere
492 AccessTraits<std::vector<std::pair<::Point<dim, Number>, Number>>,
493 PrimitivesTag>::
494 get(const std::vector<std::pair<::Point<dim, Number>, Number>> &v,
495 std::size_t i)
496 {
497 // ArborX assumes that the center coordinates and the radius use float and
498 // the sphere is 3d
499 return {to_arborx_point(v[i].first), static_cast<float>(v[i].second)};
500 }
501
502#else
503 template <typename T>
504 std::size_t
505 AccessTraits<
506 std::vector<T>,
507 std::enable_if_t<
508 std::is_same_v<T, ::Point<T::dimension, float>> ||
509 std::is_same_v<T, ::Point<T::dimension, double>> ||
510 std::is_same_v<T, ::BoundingBox<T::dimension, float>> ||
511 std::is_same_v<T, ::BoundingBox<T::dimension, double>> ||
512 std::is_same_v<T, std::pair<::Point<T::dimension, float>, float>> ||
513 std::is_same_v<T,
514 std::pair<::Point<T::dimension, double>, double>>>>::
515 size(const std::vector<T> &v)
516 {
517 return v.size();
518 }
519
520
521
522 template <typename T>
523 T
524 AccessTraits<
525 std::vector<T>,
526 std::enable_if_t<
527 std::is_same_v<T, ::Point<T::dimension, float>> ||
528 std::is_same_v<T, ::Point<T::dimension, double>> ||
529 std::is_same_v<T, ::BoundingBox<T::dimension, float>> ||
530 std::is_same_v<T, ::BoundingBox<T::dimension, double>> ||
531 std::is_same_v<T, std::pair<::Point<T::dimension, float>, float>> ||
532 std::is_same_v<T,
533 std::pair<::Point<T::dimension, double>, double>>>>::
534 get(const std::vector<T> &v, std::size_t i)
535 {
536 return v[i];
537 }
538#endif
539} // namespace ArborX
540
541// ----------------------- Instantiations --------------------//
542#include "arborx/access_traits.inst"
BoundingBoxIntersectPredicate(const std::vector<::BoundingBox< dim, Number > > &bounding_boxes)
const ::BoundingBox< 3, float > & get(unsigned int i) const
BoundingBoxNearestPredicate(const std::vector<::BoundingBox< dim, Number > > &bounding_boxes, const unsigned int n_nearest_neighbors)
const ::BoundingBox< 3, float > & get(unsigned int i) const
BoundingBoxPredicate(const std::vector<::BoundingBox< dim, Number > > &bounding_boxes)
std::vector<::BoundingBox< 3, float > > bounding_boxes
const ::BoundingBox< 3, float > & get(unsigned int i) const
PointIntersectPredicate(const std::vector<::Point< dim, Number > > &points)
const ::Point< 3, float > & get(unsigned int i) const
unsigned int get_n_nearest_neighbors() const
const ::Point< 3, float > & get(unsigned int i) const
PointNearestPredicate(const std::vector<::Point< dim, Number > > &points, const unsigned int n_nearest_neighbors)
std::vector<::Point< 3, float > > points
PointPredicate(const std::vector<::Point< dim, Number > > &points)
const ::Point< 3, float > & get(unsigned int i) const
const std::pair<::Point< 3, float >, float > & get(unsigned int) const
SphereIntersectPredicate(const std::vector< std::pair<::Point< dim, Number >, Number > > &spheres)
const std::pair<::Point< 3, float >, float > & get(unsigned int) const
SphereNearestPredicate(const std::vector< std::pair<::Point< dim, Number >, Number > > &spheres, const unsigned int n_nearest_neighbors)
const std::pair<::Point< 3, float >, float > & get(unsigned int) const
std::vector< std::pair<::Point< 3, float >, float > > spheres
SpherePredicate(const std::vector< std::pair<::Point< dim, Number >, Number > > &spheres)
Definition point.h:111
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
Point< 2 > second
Definition grid_out.cc:4640
Point< 2 > first
Definition grid_out.cc:4639
std::size_t size
Definition mpi.cc:733
*  *  *  RotationFunction< dim, Number >::RotationFunction Number(dim)