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
bvh.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_bvh_h
16#define dealii_arborx_bvh_h
17
18#include <deal.II/base/config.h>
19
20#ifdef DEAL_II_WITH_ARBORX
22
23# include <ArborX_Config.hpp>
24# include <ArborX_LinearBVH.hpp>
25# include <Kokkos_Core.hpp>
26
28
32namespace ArborXWrappers
33{
51# if ARBORX_VERSION_MAJOR < 2
52 class BVH
53 {
54 public:
58 template <int dim, typename Number>
59 BVH(const std::vector<BoundingBox<dim, Number>> &bounding_boxes);
60
64 template <int dim, typename Number>
65 BVH(const std::vector<Point<dim, Number>> &points);
66
136 template <typename QueryType>
137 std::pair<std::vector<int>, std::vector<int>>
138 query(const QueryType &queries);
139
140 private:
144 ArborX::BVH<Kokkos::HostSpace> bvh;
145 };
146
147
148
149 template <int dim, typename Number>
150 BVH::BVH(const std::vector<BoundingBox<dim, Number>> &bounding_boxes)
151 : bvh(Kokkos::DefaultHostExecutionSpace{}, bounding_boxes)
152 {}
153
154
155
156 template <int dim, typename Number>
157 BVH::BVH(const std::vector<Point<dim, Number>> &points)
158 : bvh(Kokkos::DefaultHostExecutionSpace{}, points)
159 {}
160
161
162
163 template <typename QueryType>
164 std::pair<std::vector<int>, std::vector<int>>
165 BVH::query(const QueryType &queries)
166 {
167 Kokkos::View<int *, Kokkos::HostSpace> indices("indices", 0);
168
169 Kokkos::View<int *, Kokkos::HostSpace> offset("offset", 0);
170 ArborX::query(
171 bvh, Kokkos::DefaultHostExecutionSpace{}, queries, indices, offset);
172 std::vector<int> indices_vector;
173 indices_vector.insert(indices_vector.begin(),
174 indices.data(),
175 indices.data() + indices.extent(0));
176 std::vector<int> offset_vector;
177 offset_vector.insert(offset_vector.begin(),
178 offset.data(),
179 offset.data() + offset.extent(0));
180
181 return {indices_vector, offset_vector};
182 }
183# else
184 template <typename Value>
185 class BVH
186 {
187 public:
191 BVH(const std::vector<Value> &values);
192
262 template <typename QueryType>
263 std::pair<std::vector<int>, std::vector<int>>
264 query(const QueryType &queries);
265
266 private:
270 ArborX::BVH<Kokkos::HostSpace,
271 ArborX::PairValueIndex<Value, unsigned int>,
272 internal::IndexableGetter>
273 bvh;
274 };
275
276
277
278 template <typename Value>
279 BVH<Value>::BVH(const std::vector<Value> &values)
280 : bvh(Kokkos::DefaultHostExecutionSpace{},
281 ArborX::Experimental::attach_indices(values),
282 internal::IndexableGetter{})
283 {}
284
285
286
287 template <typename Value>
288 template <typename QueryType>
289 std::pair<std::vector<int>, std::vector<int>>
290 BVH<Value>::query(const QueryType &queries)
291 {
292 Kokkos::View<int *, Kokkos::HostSpace> indices("indices", 0);
293
294 Kokkos::View<int *, Kokkos::HostSpace> offset("offset", 0);
295 bvh.query(Kokkos::DefaultHostExecutionSpace{},
296 queries,
297 internal::ExtractIndex{},
298 indices,
299 offset);
300 std::vector<int> indices_vector;
301 indices_vector.insert(indices_vector.begin(),
302 indices.data(),
303 indices.data() + indices.extent(0));
304 std::vector<int> offset_vector;
305 offset_vector.insert(offset_vector.begin(),
306 offset.data(),
307 offset.data() + offset.extent(0));
308
309 return {indices_vector, offset_vector};
310 }
311# endif
312} // namespace ArborXWrappers
313
315
316#else
317
318// Make sure the scripts that create the C++20 module input files have
319// something to latch on if the preprocessor #ifdef above would
320// otherwise lead to an empty content of the file.
323
324#endif
325#endif
ArborX::BVH< Kokkos::HostSpace > bvh
Definition bvh.h:144
std::pair< std::vector< int >, std::vector< int > > query(const QueryType &queries)
Definition bvh.h:165
BVH(const std::vector< BoundingBox< dim, Number > > &bounding_boxes)
Definition bvh.h:150
Definition point.h:113
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:40
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:41