deal.II version GIT relicensing-2289-g1e5549a87a 2024-12-21 21:30:00+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.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2021 - 2024 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#ifndef dealii_arborx_access_traits_h
16#define dealii_arborx_access_traits_h
17
18#include <deal.II/base/config.h>
19
20#ifdef DEAL_II_WITH_ARBORX
22
23# include <ArborX.hpp>
24
25# include <utility>
26
27
29
31{
37 {
38 protected:
42 template <int dim, typename Number>
43 PointPredicate(const std::vector<::Point<dim, Number>> &points);
44
48 std::size_t
49 size() const;
50
54 const ::Point<3, float> &
55 get(unsigned int i) const;
56
57 private:
58 std::vector<::Point<3, float>> points;
59 };
60
61
62
70 {
71 public:
76 template <int dim, typename Number>
78 const std::vector<::Point<dim, Number>> &points);
79
80 // We need these since we inherit privately to avoid polymorphic use.
83 };
84
85
86
94 {
95 public:
101 template <int dim, typename Number>
103 const unsigned int n_nearest_neighbors);
104
108 unsigned int
110
111 // We need these since we inherit privately to avoid polymorphic use.
114
115 private:
117 };
118
119
120
126 {
127 protected:
132 template <int dim, typename Number>
134 const std::vector<::BoundingBox<dim, Number>> &bounding_boxes);
135
139 std::size_t
140 size() const;
141
145 const ::BoundingBox<3, float> &
146 get(unsigned int i) const;
147
148 private:
149 std::vector<::BoundingBox<3, float>> bounding_boxes;
150 };
151
152
153
161 {
162 public:
167 template <int dim, typename Number>
169 const std::vector<::BoundingBox<dim, Number>> &bounding_boxes);
170
171 // We need these since we inherit privately to avoid polymorphic use.
174 };
175
176
184 {
185 public:
191 template <int dim, typename Number>
193 const std::vector<::BoundingBox<dim, Number>> &bounding_boxes,
194 const unsigned int n_nearest_neighbors);
195
199 unsigned int
201
202 // We need these since we inherit privately to avoid polymorphic use.
205
206 private:
208 };
209
210
211
217 {
218 protected:
223 template <int dim, typename Number>
225 const std::vector<std::pair<::Point<dim, Number>, Number>>
226 &spheres);
227
231 std::size_t
232 size() const;
233
237 const std::pair<::Point<3, float>, float> &
238 get(unsigned int) const;
239
240 private:
241 std::vector<std::pair<::Point<3, float>, float>> spheres;
242 };
243
244
245
253 {
254 public:
259 template <int dim, typename Number>
261 const std::vector<std::pair<::Point<dim, Number>, Number>>
262 &spheres);
263
264 // We need these since we inherit privately to avoid polymorphic use.
267 };
268
269
270
278 {
279 public:
285 template <int dim, typename Number>
287 const std::vector<std::pair<::Point<dim, Number>, Number>> &spheres,
288 const unsigned int n_nearest_neighbors);
289
293 unsigned int
295
296 // We need these since we inherit privately to avoid polymorphic use.
299
300 private:
302 };
303} // namespace ArborXWrappers
304
306
310namespace ArborX
311{
316 template <int dim, typename Number>
317 struct AccessTraits<std::vector<::Point<dim, Number>>, PrimitivesTag>
318 {
319 using memory_space = Kokkos::HostSpace;
320
324 static std::size_t
325 size(const std::vector<::Point<dim, Number>> &v);
326
330 static Point
331 get(const std::vector<::Point<dim, Number>> &v, std::size_t i);
332 };
333
334
335
340 template <int dim, typename Number>
341 struct AccessTraits<std::vector<::BoundingBox<dim, Number>>,
342 PrimitivesTag>
343 {
344 using memory_space = Kokkos::HostSpace;
345
349 static std::size_t
350 size(const std::vector<::BoundingBox<dim, Number>> &v);
351
355 static Box
356 get(const std::vector<::BoundingBox<dim, Number>> &v, std::size_t i);
357 };
358
359
360
365 template <int dim, typename Number>
366 struct AccessTraits<
367 std::vector<std::pair<::Point<dim, Number>, Number>>,
368 PrimitivesTag>
369 {
370 using memory_space = Kokkos::HostSpace;
371
375 static std::size_t
376 size(const std::vector<std::pair<::Point<dim, Number>, Number>> &v);
377
382 static Sphere
383 get(const std::vector<std::pair<::Point<dim, Number>, Number>> &v,
384 std::size_t i);
385 };
386
387
388
392 template <>
394 PredicatesTag>
395 {
396 using memory_space = Kokkos::HostSpace;
397
401 static std::size_t
402 size(const ::ArborXWrappers::PointIntersectPredicate &pt_intersect);
403
408 static auto
409 get(const ::ArborXWrappers::PointIntersectPredicate &pt_intersect,
410 std::size_t i);
411 };
412
413
414
418 template <>
420 PredicatesTag>
421 {
422 using memory_space = Kokkos::HostSpace;
423
427 static std::size_t
428 size(const ::ArborXWrappers::PointNearestPredicate &pt_nearest);
429
435 static auto
436 get(const ::ArborXWrappers::PointNearestPredicate &pt_nearest,
437 std::size_t i);
438 };
439
440
441
446 template <>
448 PredicatesTag>
449 {
450 using memory_space = Kokkos::HostSpace;
451
455 static std::size_t
456 size(const ::ArborXWrappers::BoundingBoxIntersectPredicate
457 &bb_intersect);
458
463 static auto
464 get(
465 const ::ArborXWrappers::BoundingBoxIntersectPredicate &bb_intersect,
466 std::size_t i);
467 };
468
469
470
475 template <>
477 PredicatesTag>
478 {
479 using memory_space = Kokkos::HostSpace;
480
484 static std::size_t
485 size(const ::ArborXWrappers::BoundingBoxNearestPredicate &bb_nearest);
486
494 static auto
495 get(const ::ArborXWrappers::BoundingBoxNearestPredicate &bb_nearest,
496 std::size_t i);
497 };
498
499
500
504 template <>
506 PredicatesTag>
507 {
508 using memory_space = Kokkos::HostSpace;
509
513 static std::size_t
514 size(const ::ArborXWrappers::SphereIntersectPredicate &sph_intersect);
515
520 static auto
521 get(const ::ArborXWrappers::SphereIntersectPredicate &sph_intersect,
522 std::size_t i);
523 };
524
525
526
530 template <>
532 PredicatesTag>
533 {
534 using memory_space = Kokkos::HostSpace;
535
539 static std::size_t
540 size(const ::ArborXWrappers::SphereNearestPredicate &sph_nearest);
541
547 static auto
548 get(const ::ArborXWrappers::SphereNearestPredicate &sph_nearest,
549 std::size_t i);
550 };
551
552 // ------------------------------- Inline ----------------------------------//
553
554 // The implementation of AccessTraits<..., PredicatesTag> needs to be in the
555 // header file otherwise the return type of auto get() cannot be determined.
556 // We use auto because ArborX does not expose the type of intersects
557
558 inline std::size_t
559 AccessTraits<::ArborXWrappers::PointIntersectPredicate, PredicatesTag>::
560 size(const ::ArborXWrappers::PointIntersectPredicate &pt_intersect)
561 {
562 return pt_intersect.size();
563 }
564
565
566
567 inline auto
568 AccessTraits<::ArborXWrappers::PointIntersectPredicate, PredicatesTag>::
569 get(const ::ArborXWrappers::PointIntersectPredicate &pt_intersect,
570 std::size_t i)
571 {
572 const auto dealii_point = pt_intersect.get(i);
573 return intersects(Point{dealii_point[0], dealii_point[1], dealii_point[2]});
574 }
575
576
577
578 inline std::size_t
579 AccessTraits<::ArborXWrappers::PointNearestPredicate, PredicatesTag>::
580 size(const ::ArborXWrappers::PointNearestPredicate &pt_nearest)
581 {
582 return pt_nearest.size();
583 }
584
585
586
587 inline auto
588 AccessTraits<::ArborXWrappers::PointNearestPredicate, PredicatesTag>::
589 get(const ::ArborXWrappers::PointNearestPredicate &pt_nearest,
590 std::size_t i)
591 {
592 const auto dealii_point = pt_nearest.get(i);
593 return nearest(Point{dealii_point[0], dealii_point[1], dealii_point[2]},
594 pt_nearest.get_n_nearest_neighbors());
595 }
596
597
598
599 inline std::size_t
601 PredicatesTag>::
602 size(
603 const ::ArborXWrappers::BoundingBoxIntersectPredicate &bb_intersect)
604 {
605 return bb_intersect.size();
606 }
607
608
609
610 inline auto
612 PredicatesTag>::
613 get(
614 const ::ArborXWrappers::BoundingBoxIntersectPredicate &bb_intersect,
615 std::size_t i)
616 {
617 const auto boundary_points = bb_intersect.get(i).get_boundary_points();
618 const ::Point<3, float> min_corner = boundary_points.first;
619 const ::Point<3, float> max_corner = boundary_points.second;
620
621 return intersects(Box{{min_corner[0], min_corner[1], min_corner[2]},
622 {max_corner[0], max_corner[1], max_corner[2]}});
623 }
624
625
626
627 inline std::size_t
629 PredicatesTag>::
630 size(const ::ArborXWrappers::BoundingBoxNearestPredicate &bb_nearest)
631 {
632 return bb_nearest.size();
633 }
634
635
636
637 inline auto
639 PredicatesTag>::
640 get(const ::ArborXWrappers::BoundingBoxNearestPredicate &bb_nearest,
641 std::size_t i)
642 {
643 const auto boundary_points = bb_nearest.get(i).get_boundary_points();
644 const ::Point<3, float> min_corner = boundary_points.first;
645 const ::Point<3, float> max_corner = boundary_points.second;
646
647 return nearest(Box{{min_corner[0], min_corner[1], min_corner[2]},
648 {max_corner[0], max_corner[1], max_corner[2]}},
649 bb_nearest.get_n_nearest_neighbors());
650 }
651
652
653
654 inline std::size_t
656 PredicatesTag>::
657 size(const ::ArborXWrappers::SphereIntersectPredicate &sph_intersect)
658 {
659 return sph_intersect.size();
660 }
661
662
663
664 inline auto
666 PredicatesTag>::
667 get(const ::ArborXWrappers::SphereIntersectPredicate &sph_intersect,
668 std::size_t i)
669 {
670 const auto sphere = sph_intersect.get(i);
671 return intersects(
672 Sphere{{sphere.first[0], sphere.first[1], sphere.first[2]},
673 sphere.second});
674 }
675
676
677
678 inline std::size_t
679 AccessTraits<::ArborXWrappers::SphereNearestPredicate, PredicatesTag>::
680 size(const ::ArborXWrappers::SphereNearestPredicate &sph_nearest)
681 {
682 return sph_nearest.size();
683 }
684
685
686
687 inline auto
688 AccessTraits<::ArborXWrappers::SphereNearestPredicate, PredicatesTag>::
689 get(const ::ArborXWrappers::SphereNearestPredicate &sph_nearest,
690 std::size_t i)
691 {
692 const auto sphere = sph_nearest.get(i);
693 return nearest(Sphere{{sphere.first[0], sphere.first[1], sphere.first[2]},
694 sphere.second},
695 sph_nearest.get_n_nearest_neighbors());
696 }
697} // namespace ArborX
698
699#endif
700
701#endif
const ::BoundingBox< 3, float > & get(unsigned int i) const
const ::BoundingBox< 3, float > & get(unsigned int i) const
std::vector<::BoundingBox< 3, float > > bounding_boxes
const ::BoundingBox< 3, float > & get(unsigned int i) const
unsigned int get_n_nearest_neighbors() const
std::vector<::Point< 3, float > > points
const ::Point< 3, float > & get(unsigned int i) const
const std::pair<::Point< 3, float >, float > & get(unsigned int) const
const std::pair<::Point< 3, float >, float > & get(unsigned int) const
std::vector< std::pair<::Point< 3, float >, float > > spheres
std::pair< Point< spacedim, Number >, Point< spacedim, Number > > & get_boundary_points()
Definition point.h:111
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:498
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:499
std::size_t size
Definition mpi.cc:734
STL namespace.