deal.II version GIT relicensing-6842-g793a97d2aa 2026-10-02 14:00: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
bvh.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) 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
13#ifndef dealii_arborx_bvh_h
14#define dealii_arborx_bvh_h
15
16#include <deal.II/base/config.h>
17
18#ifdef DEAL_II_WITH_ARBORX
20
21# include <ArborX_Config.hpp>
22# include <ArborX_LinearBVH.hpp>
23# include <Kokkos_Core.hpp>
24
25#endif
26
28
29#ifdef DEAL_II_WITH_ARBORX
33namespace ArborXWrappers
34{
52# if ARBORX_VERSION_MAJOR < 2
53 class BVH
54 {
55 public:
59 template <int dim, typename Number>
60 BVH(const std::vector<BoundingBox<dim, Number>> &bounding_boxes);
61
65 template <int dim, typename Number>
66 BVH(const std::vector<Point<dim, Number>> &points);
67
137 template <typename QueryType>
138 std::pair<std::vector<int>, std::vector<int>>
139 query(const QueryType &queries);
140
141 private:
145 ArborX::BVH<Kokkos::HostSpace> bvh;
146 };
147
148
149
150 template <int dim, typename Number>
151 BVH::BVH(const std::vector<BoundingBox<dim, Number>> &bounding_boxes)
152 : bvh(Kokkos::DefaultHostExecutionSpace{}, bounding_boxes)
153 {}
154
155
156
157 template <int dim, typename Number>
158 BVH::BVH(const std::vector<Point<dim, Number>> &points)
159 : bvh(Kokkos::DefaultHostExecutionSpace{}, points)
160 {}
161
162
163
164 template <typename QueryType>
165 std::pair<std::vector<int>, std::vector<int>>
166 BVH::query(const QueryType &queries)
167 {
168 Kokkos::View<int *, Kokkos::HostSpace> indices("indices", 0);
169
170 Kokkos::View<int *, Kokkos::HostSpace> offset("offset", 0);
171 ArborX::query(
172 bvh, Kokkos::DefaultHostExecutionSpace{}, queries, indices, offset);
173 std::vector<int> indices_vector;
174 indices_vector.insert(indices_vector.begin(),
175 indices.data(),
176 indices.data() + indices.extent(0));
177 std::vector<int> offset_vector;
178 offset_vector.insert(offset_vector.begin(),
179 offset.data(),
180 offset.data() + offset.extent(0));
181
182 return {indices_vector, offset_vector};
183 }
184# else
185 template <typename Value>
186 class BVH
187 {
188 public:
192 BVH(const std::vector<Value> &values);
193
263 template <typename QueryType>
264 std::pair<std::vector<int>, std::vector<int>>
265 query(const QueryType &queries);
266
267 private:
271 ArborX::BVH<Kokkos::HostSpace,
272 ArborX::PairValueIndex<Value, unsigned int>,
273 internal::IndexableGetter>
274 bvh;
275 };
276
277
278
279 template <typename Value>
280 BVH<Value>::BVH(const std::vector<Value> &values)
281 : bvh(Kokkos::DefaultHostExecutionSpace{},
282 ArborX::Experimental::attach_indices(values),
283 internal::IndexableGetter{})
284 {}
285
286
287
288 template <typename Value>
289 template <typename QueryType>
290 std::pair<std::vector<int>, std::vector<int>>
291 BVH<Value>::query(const QueryType &queries)
292 {
293 Kokkos::View<int *, Kokkos::HostSpace> indices("indices", 0);
294
295 Kokkos::View<int *, Kokkos::HostSpace> offset("offset", 0);
296 bvh.query(Kokkos::DefaultHostExecutionSpace{},
297 queries,
298 internal::ExtractIndex{},
299 indices,
300 offset);
301 std::vector<int> indices_vector;
302 indices_vector.insert(indices_vector.begin(),
303 indices.data(),
304 indices.data() + indices.extent(0));
305 std::vector<int> offset_vector;
306 offset_vector.insert(offset_vector.begin(),
307 offset.data(),
308 offset.data() + offset.extent(0));
309
310 return {indices_vector, offset_vector};
311 }
312# endif
313} // namespace ArborXWrappers
314
315#endif
316
318#endif
ArborX::BVH< Kokkos::HostSpace > bvh
Definition bvh.h:145
std::pair< std::vector< int >, std::vector< int > > query(const QueryType &queries)
Definition bvh.h:166
BVH(const std::vector< BoundingBox< dim, Number > > &bounding_boxes)
Definition bvh.h:151
Definition point.h:111
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39