Reference documentation for deal.II version 9.6.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 - 2023 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 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 }
50
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
141
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} // namespace ArborXWrappers
217
219
220namespace ArborX
221{
222 namespace
223 {
224 template <int dim, typename Number>
225 Point
226 to_arborx_point(::Point<dim, Number> p)
227 {
228 static_assert(dim >= 1 && dim <= 3);
229 if (dim == 1)
230 return {float(p[0]), 0.f, 0.f};
231 else if (dim == 2)
232 return {float(p[0]), float(p[1]), 0.f};
233 else
234 return {float(p[0]), float(p[1]), float(p[2])};
235 }
236 } // namespace
237
239
240 // ------------------- Point Primitives AccessTraits ------------------- //
241 template <int dim, typename Number>
242 std::size_t
243 AccessTraits<std::vector<::Point<dim, Number>>, PrimitivesTag>::size(
244 const std::vector<::Point<dim, Number>> &v)
245 {
246 return v.size();
247 }
248
249
250
251 template <int dim, typename Number>
252 Point
253 AccessTraits<std::vector<::Point<dim, Number>>, PrimitivesTag>::get(
254 const std::vector<::Point<dim, Number>> &v,
255 std::size_t i)
256 {
257 // ArborX assumes that the point coordinates use float and that the point
258 // is 3d
259 return to_arborx_point(v[i]);
260 }
261
262
263
264 // ----------------- BoundingBox Primitives AccessTraits ----------------- //
265 template <int dim, typename Number>
266 std::size_t
267 AccessTraits<std::vector<::BoundingBox<dim, Number>>, PrimitivesTag>::
268 size(const std::vector<::BoundingBox<dim, Number>> &v)
269 {
270 return v.size();
271 }
272
273
274
275 template <int dim, typename Number>
276 Box
277 AccessTraits<std::vector<::BoundingBox<dim, Number>>, PrimitivesTag>::
278 get(const std::vector<::BoundingBox<dim, Number>> &v, std::size_t i)
279 {
280 const auto boundary_points = v[i].get_boundary_points();
281 const ::Point<dim, Number> min_corner = boundary_points.first;
282 const ::Point<dim, Number> max_corner = boundary_points.second;
283 // ArborX assumes that the bounding box coordinates use float and that the
284 // bounding box is 3d
285 return {to_arborx_point(min_corner), to_arborx_point(max_corner)};
286 }
287
288
289
290 // ---------------------- Sphere Primitives AccessTraits ----------------- //
291 template <int dim, typename Number>
292 std::size_t
293 AccessTraits<std::vector<std::pair<::Point<dim, Number>, Number>>,
294 PrimitivesTag>::
295 size(const std::vector<std::pair<::Point<dim, Number>, Number>> &v)
296 {
297 return v.size();
298 }
299
300
301
302 template <int dim, typename Number>
303 Sphere
304 AccessTraits<std::vector<std::pair<::Point<dim, Number>, Number>>,
305 PrimitivesTag>::
306 get(const std::vector<std::pair<::Point<dim, Number>, Number>> &v,
307 std::size_t i)
308 {
309 // ArborX assumes that the center coordinates and the radius use float and
310 // the sphere is 3d
311 return {to_arborx_point(v[i].first), static_cast<float>(v[i].second)};
312 }
313} // namespace ArborX
314
315// ----------------------- Instantiations --------------------//
316# include "access_traits.inst"
317
318#endif
BoundingBoxIntersectPredicate(const std::vector<::BoundingBox< dim, Number > > &bounding_boxes)
BoundingBoxNearestPredicate(const std::vector<::BoundingBox< dim, Number > > &bounding_boxes, const unsigned int n_nearest_neighbors)
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)
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
SphereIntersectPredicate(const std::vector< std::pair<::Point< dim, Number >, Number > > &spheres)
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:503
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:504
Point< 2 > second
Definition grid_out.cc:4624
Point< 2 > first
Definition grid_out.cc:4623