deal.II version 9.7.0
\(\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: LGPL-2.1-or-later
4// Copyright (C) 2021 - 2025 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
16
17#ifdef DEAL_II_WITH_ARBORX
18
20
21namespace ArborXWrappers
22{
23# if ARBORX_VERSION_MAJOR < 2
24
25 namespace
26 {
27 template <int dim, typename Number>
28 ::Point<3, float>
29 to_3d_float_point(::Point<dim, Number> p)
30 {
31 static_assert(dim >= 1 && dim <= 3);
32 if (dim == 1)
33 return Point<3, float>(p[0], 0.f, 0.f);
34 else if (dim == 2)
35 return Point<3, float>(p[0], p[1], 0.f);
36 else
37 return Point<3, float>(p[0], p[1], p[2]);
38 }
39 } // namespace
40
41 // ------------------- PointPredicate ------------------- //
42 template <int dim, typename Number>
44 const std::vector<::Point<dim, Number>> &dim_points)
45 {
46 const unsigned int size = dim_points.size();
47 points.reserve(size);
48 for (unsigned int i = 0; i < size; ++i)
49 points.emplace_back(to_3d_float_point(dim_points[i]));
50 }
51
52
53
54 std::size_t
56 {
57 return points.size();
58 }
59
60
61
62 const ::Point<3, float> &
63 PointPredicate::get(unsigned int i) const
64 {
65 return points[i];
66 }
67
68
69
70 template <int dim, typename Number>
75
76
77
78 template <int dim, typename Number>
85
86
87
88 unsigned int
93
94 // ------------------- BoundingBoxPredicate ------------------- //
95 template <int dim, typename Number>
97 const std::vector<::BoundingBox<dim, Number>> &bb)
98 {
99 const unsigned int size = bb.size();
100 bounding_boxes.reserve(size);
101 ::Point<3, float> min_corner_arborx(0., 0., 0.);
102 ::Point<3, float> max_corner_arborx(0., 0., 0.);
103 for (unsigned int i = 0; i < size; ++i)
104 {
105 auto boundary_points = bb[i].get_boundary_points();
106 ::Point<dim, Number> min_corner = boundary_points.first;
107 ::Point<dim, Number> max_corner = boundary_points.second;
108 for (unsigned int d = 0; d < dim; ++d)
109 {
110 min_corner_arborx[d] = static_cast<float>(min_corner[d]);
111 max_corner_arborx[d] = static_cast<float>(max_corner[d]);
112 }
113 bounding_boxes.emplace_back(
114 std::make_pair(min_corner_arborx, max_corner_arborx));
115 }
116 }
117
118
119
120 std::size_t
122 {
123 return bounding_boxes.size();
124 }
125
126
127
128 const ::BoundingBox<3, float> &
129 BoundingBoxPredicate::get(unsigned int i) const
130 {
131 return bounding_boxes[i];
132 }
133
134
135
136 template <int dim, typename Number>
142
143
144 template <int dim, typename Number>
146 const std::vector<::BoundingBox<dim, Number>> &bounding_boxes,
147 const unsigned int n_nearest_neighbors)
149 , n_nearest_neighbors(n_nearest_neighbors)
150 {}
151
152
153
154 unsigned int
159
160 // ------------------- SpherePredicate ------------------- //
161 template <int dim, typename Number>
163 const std::vector<std::pair<::Point<dim, Number>, Number>>
164 &dim_spheres)
165 {
166 const unsigned int size = dim_spheres.size();
167 spheres.reserve(size);
168 for (unsigned int i = 0; i < size; ++i)
169 {
170 // ArborX assumes that the center coordinates and the radius use float
171 // and the sphere is 3d
172 spheres.emplace_back(to_3d_float_point(dim_spheres[i].first),
173 static_cast<float>(dim_spheres[i].second));
174 }
175 }
176
177
178
179 std::size_t
181 {
182 return spheres.size();
183 }
184
185
186
187 const std::pair<::Point<3, float>, float> &
188 SpherePredicate::get(unsigned int i) const
189 {
190 return spheres[i];
191 }
192
193
194
195 template <int dim, typename Number>
200
201
202
203 template <int dim, typename Number>
210
211
212
213 unsigned int
218# else
219 template <int dim, typename Number>
221 const std::vector<::Point<dim, Number>> &points)
222 : points(points)
223 {}
224
225
226
227 template <int dim, typename Number>
228 std::size_t
230 {
231 return points.size();
232 }
234
235
236 template <int dim, typename Number>
237 const ::Point<dim, Number> &
240 return points[i];
241 }
242
243
244 template <int dim, typename Number>
246 const std::vector<::Point<dim, Number>> &points,
247 const unsigned int n_nearest_neighbors)
248 : points(points)
249 , n_nearest_neighbors(n_nearest_neighbors)
250 {}
251
252
253
254 template <int dim, typename Number>
255 unsigned int
257 {
258 return n_nearest_neighbors;
259 }
260
261
262
263 template <int dim, typename Number>
264 std::size_t
266 {
267 return points.size();
268 }
269
270
271
272 template <int dim, typename Number>
273 const ::Point<dim, Number> &
274 PointNearestPredicate<dim, Number>::get(unsigned int i) const
275 {
276 return points[i];
277 }
278
279
280 // ------------------- BoundingBoxPredicate ------------------- //
281 template <int dim, typename Number>
283 const std::vector<::BoundingBox<dim, Number>> &bb)
284 : bounding_boxes(bb)
285 {}
286
287
288
289 template <int dim, typename Number>
290 std::size_t
292 {
293 return bounding_boxes.size();
294 }
295
296
297
298 template <int dim, typename Number>
299 const ::BoundingBox<dim, Number> &
301 {
302 return bounding_boxes[i];
303 }
304
305
306
307 template <int dim, typename Number>
309 const std::vector<::BoundingBox<dim, Number>> &bounding_boxes,
310 const unsigned int n_nearest_neighbors)
311 : bounding_boxes(bounding_boxes)
312 , n_nearest_neighbors(n_nearest_neighbors)
313 {}
314
315
316
317 template <int dim, typename Number>
318 unsigned int
320 {
321 return n_nearest_neighbors;
322 }
323
324
325
326 template <int dim, typename Number>
327 std::size_t
329 {
330 return bounding_boxes.size();
331 }
332
333
334
335 template <int dim, typename Number>
336 const ::BoundingBox<dim, Number> &
338 {
339 return bounding_boxes[i];
340 }
341
342 // ------------------- SpherePredicate ------------------- //
343 template <int dim, typename Number>
345 const std::vector<std::pair<::Point<dim, Number>, Number>> &spheres)
346 : spheres(spheres)
347 {}
348
349
350
351 template <int dim, typename Number>
352 std::size_t
354 {
355 return spheres.size();
356 }
357
358
359
360 template <int dim, typename Number>
361 const std::pair<::Point<dim, Number>, Number> &
363 {
364 return spheres[i];
365 }
366
367
368
369 template <int dim, typename Number>
371 const std::vector<std::pair<::Point<dim, Number>, Number>> &spheres,
372 const unsigned int n_nearest_neighbors)
373 : spheres(spheres)
374 , n_nearest_neighbors(n_nearest_neighbors)
375 {}
376
377
378
379 template <int dim, typename Number>
380 unsigned int
382 {
383 return n_nearest_neighbors;
384 }
385
386
387
388 template <int dim, typename Number>
389 std::size_t
391 {
392 return spheres.size();
393 }
394
395
396
397 template <int dim, typename Number>
398 const std::pair<::Point<dim, Number>, Number> &
399 SphereNearestPredicate<dim, Number>::get(unsigned int i) const
400 {
401 return spheres[i];
402 }
403# endif
404} // namespace ArborXWrappers
405
406
408
409namespace ArborX
410{
411# if ARBORX_VERSION_MAJOR < 2
412 namespace
413 {
414 template <int dim, typename Number>
415 Point
416 to_arborx_point(::Point<dim, Number> p)
417 {
418 static_assert(dim >= 1 && dim <= 3);
419 if (dim == 1)
420 return {float(p[0]), 0.f, 0.f};
421 else if (dim == 2)
422 return {float(p[0]), float(p[1]), 0.f};
423 else
424 return {float(p[0]), float(p[1]), float(p[2])};
425 }
426 } // namespace
427
428
429
430 // ------------------- Point Primitives AccessTraits ------------------- //
431 template <int dim, typename Number>
432 std::size_t
433 AccessTraits<std::vector<::Point<dim, Number>>, PrimitivesTag>::size(
434 const std::vector<::Point<dim, Number>> &v)
435 {
436 return v.size();
437 }
438
439
440
441 template <int dim, typename Number>
442 Point
443 AccessTraits<std::vector<::Point<dim, Number>>, PrimitivesTag>::get(
444 const std::vector<::Point<dim, Number>> &v,
445 std::size_t i)
446 {
447 // ArborX assumes that the point coordinates use float and that the point
448 // is 3d
449 return to_arborx_point(v[i]);
450 }
451
452
453
454 // ----------------- BoundingBox Primitives AccessTraits ----------------- //
455 template <int dim, typename Number>
456 std::size_t
457 AccessTraits<std::vector<::BoundingBox<dim, Number>>, PrimitivesTag>::
458 size(const std::vector<::BoundingBox<dim, Number>> &v)
459 {
460 return v.size();
461 }
462
463
464
465 template <int dim, typename Number>
466 Box
467 AccessTraits<std::vector<::BoundingBox<dim, Number>>, PrimitivesTag>::
468 get(const std::vector<::BoundingBox<dim, Number>> &v, std::size_t i)
469 {
470 const auto boundary_points = v[i].get_boundary_points();
471 const ::Point<dim, Number> min_corner = boundary_points.first;
472 const ::Point<dim, Number> max_corner = boundary_points.second;
473 // ArborX assumes that the bounding box coordinates use float and that the
474 // bounding box is 3d
475 return {to_arborx_point(min_corner), to_arborx_point(max_corner)};
476 }
477
478
479
480 // ---------------------- Sphere Primitives AccessTraits ----------------- //
481 template <int dim, typename Number>
482 std::size_t
483 AccessTraits<std::vector<std::pair<::Point<dim, Number>, Number>>,
484 PrimitivesTag>::
485 size(const std::vector<std::pair<::Point<dim, Number>, Number>> &v)
486 {
487 return v.size();
488 }
489
490
491
492 template <int dim, typename Number>
493 Sphere
494 AccessTraits<std::vector<std::pair<::Point<dim, Number>, Number>>,
495 PrimitivesTag>::
496 get(const std::vector<std::pair<::Point<dim, Number>, Number>> &v,
497 std::size_t i)
498 {
499 // ArborX assumes that the center coordinates and the radius use float and
500 // the sphere is 3d
501 return {to_arborx_point(v[i].first), static_cast<float>(v[i].second)};
502 }
503
504# else
505 template <typename T>
506 std::size_t
507 AccessTraits<
508 std::vector<T>,
509 std::enable_if_t<
510 std::is_same_v<T, ::Point<T::dimension, float>> ||
511 std::is_same_v<T, ::Point<T::dimension, double>> ||
512 std::is_same_v<T, ::BoundingBox<T::dimension, float>> ||
513 std::is_same_v<T, ::BoundingBox<T::dimension, double>> ||
514 std::is_same_v<T, std::pair<::Point<T::dimension, float>, float>> ||
515 std::is_same_v<T,
516 std::pair<::Point<T::dimension, double>, double>>>>::
517 size(const std::vector<T> &v)
518 {
519 return v.size();
520 }
521
522
523
524 template <typename T>
525 T
526 AccessTraits<
527 std::vector<T>,
528 std::enable_if_t<
529 std::is_same_v<T, ::Point<T::dimension, float>> ||
530 std::is_same_v<T, ::Point<T::dimension, double>> ||
531 std::is_same_v<T, ::BoundingBox<T::dimension, float>> ||
532 std::is_same_v<T, ::BoundingBox<T::dimension, double>> ||
533 std::is_same_v<T, std::pair<::Point<T::dimension, float>, float>> ||
534 std::is_same_v<T,
535 std::pair<::Point<T::dimension, double>, double>>>>::
536 get(const std::vector<T> &v, std::size_t i)
537 {
538 return v[i];
539 }
540# endif
541} // namespace ArborX
542
543// ----------------------- Instantiations --------------------//
544# include "arborx/access_traits.inst"
545
546#endif
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)
const ::BoundingBox< 3, float > & get(unsigned int i) const
std::vector<::BoundingBox< 3, float > > bounding_boxes
PointIntersectPredicate(const std::vector<::Point< dim, Number > > &points)
const ::Point< 3, float > & get(unsigned int i) const
const ::Point< 3, float > & get(unsigned int i) const
unsigned int get_n_nearest_neighbors() 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:113
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:40
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:41
static Point get(const std::vector<::Point< dim, Number > > &v, std::size_t i)
static std::size_t size(const std::vector<::Point< dim, Number > > &v)