Reference documentation for deal.II version 9.4.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\}}\)
access_traits.cc
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2021 - 2022 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
17 
18 #ifdef DEAL_II_WITH_ARBORX
19 
21 
22 namespace ArborXWrappers
23 {
24  // ------------------- PointPredicate ------------------- //
25  template <int dim, typename Number>
27  const std::vector<::Point<dim, Number>> &dim_points)
28  {
29  static_assert(dim != 1, "dim equal to one is not supported.");
30 
31  const unsigned int size = dim_points.size();
32  points.reserve(size);
33  for (unsigned int i = 0; i < size; ++i)
34  {
35  points.emplace_back(static_cast<float>(dim_points[i][0]),
36  static_cast<float>(dim_points[i][1]),
37  dim == 2 ? 0.f :
38  static_cast<float>(dim_points[i][2]));
39  }
40  }
41 
42 
43 
44  std::size_t
46  {
47  return points.size();
48  }
49 
50 
51 
52  const ::Point<3, float> &
53  PointPredicate::get(unsigned int i) const
54  {
55  return points[i];
56  }
57 
58 
59 
60  template <int dim, typename Number>
62  const std::vector<::Point<dim, Number>> &points)
63  : PointPredicate(points)
64  {}
65 
66 
67 
68  template <int dim, typename Number>
70  const std::vector<::Point<dim, Number>> &points,
71  const unsigned int n_nearest_neighbors)
72  : PointPredicate(points)
73  , n_nearest_neighbors(n_nearest_neighbors)
74  {}
75 
76 
77 
78  unsigned int
80  {
81  return n_nearest_neighbors;
82  }
83 
84  // ------------------- BoundingBoxPredicate ------------------- //
85  template <int dim, typename Number>
87  const std::vector<::BoundingBox<dim, Number>> &bb)
88  {
89  const unsigned int size = bb.size();
90  bounding_boxes.reserve(size);
91  ::Point<3, float> min_corner_arborx(0., 0., 0.);
92  ::Point<3, float> max_corner_arborx(0., 0., 0.);
93  for (unsigned int i = 0; i < size; ++i)
94  {
95  auto boundary_points = bb[i].get_boundary_points();
96  ::Point<dim, Number> min_corner = boundary_points.first;
97  ::Point<dim, Number> max_corner = boundary_points.second;
98  for (unsigned int d = 0; d < dim; ++d)
99  {
100  min_corner_arborx[d] = static_cast<float>(min_corner[d]);
101  max_corner_arborx[d] = static_cast<float>(max_corner[d]);
102  }
103  bounding_boxes.emplace_back(
104  std::make_pair(min_corner_arborx, max_corner_arborx));
105  }
106  }
107 
108 
109 
110  std::size_t
112  {
113  return bounding_boxes.size();
114  }
115 
116 
117 
118  const ::BoundingBox<3, float> &
119  BoundingBoxPredicate::get(unsigned int i) const
120  {
121  return bounding_boxes[i];
122  }
123 
124 
125 
126  template <int dim, typename Number>
128  const std::vector<::BoundingBox<dim, Number>> &bounding_boxes)
129  : BoundingBoxPredicate(bounding_boxes)
130  {}
131 
132 
133 
134  template <int dim, typename Number>
136  const std::vector<::BoundingBox<dim, Number>> &bounding_boxes,
137  const unsigned int n_nearest_neighbors)
138  : BoundingBoxPredicate(bounding_boxes)
139  , n_nearest_neighbors(n_nearest_neighbors)
140  {}
141 
142 
143 
144  unsigned int
146  {
148  }
149 
150  // ------------------- SpherePredicate ------------------- //
151  template <int dim, typename Number>
153  const std::vector<std::pair<::Point<dim, Number>, Number>>
154  &dim_spheres)
155  {
156  static_assert(dim != 1, "dim equal to one is not supported.");
157 
158  const unsigned int size = dim_spheres.size();
159  spheres.reserve(size);
160  for (unsigned int i = 0; i < size; ++i)
161  {
162  // ArborX assumes that the center coordinates and the radius use float
163  // and the sphere is 3D
164  spheres.emplace_back(std::make_pair(
165  ::Point<3, float>(
166  static_cast<float>(dim_spheres[i].first[0]),
167  static_cast<float>(dim_spheres[i].first[1]),
168  dim == 2 ? 0.f : static_cast<float>(dim_spheres[i].first[2])),
169  static_cast<float>(dim_spheres[i].second)));
170  }
171  }
172 
173 
174 
175  std::size_t
177  {
178  return spheres.size();
179  }
180 
181 
182 
183  const std::pair<::Point<3, float>, float> &
184  SpherePredicate::get(unsigned int i) const
185  {
186  return spheres[i];
187  }
188 
189 
190 
191  template <int dim, typename Number>
193  const std::vector<std::pair<::Point<dim, Number>, Number>> &spheres)
194  : SpherePredicate(spheres)
195  {}
196 
197 
198 
199  template <int dim, typename Number>
201  const std::vector<std::pair<::Point<dim, Number>, Number>> &spheres,
202  const unsigned int n_nearest_neighbors)
203  : SpherePredicate(spheres)
204  , n_nearest_neighbors(n_nearest_neighbors)
205  {}
206 
207 
208 
209  unsigned int
211  {
212  return n_nearest_neighbors;
213  }
214 } // namespace ArborXWrappers
215 
217 
218 namespace ArborX
219 {
220  // ------------------- Point Primitives AccessTraits ------------------- //
221  template <int dim, typename Number>
222  std::size_t
223  AccessTraits<std::vector<::Point<dim, Number>>, PrimitivesTag>::size(
224  const std::vector<::Point<dim, Number>> &v)
225  {
226  return v.size();
227  }
228 
229 
230 
231  template <int dim, typename Number>
232  Point
233  AccessTraits<std::vector<::Point<dim, Number>>, PrimitivesTag>::get(
234  const std::vector<::Point<dim, Number>> &v,
235  std::size_t i)
236  {
237  // ArborX assumes that the point coordinates use float and that the point
238  // is 3D
239  return {static_cast<float>(v[i][0]),
240  static_cast<float>(v[i][1]),
241  dim == 2 ? 0 : static_cast<float>(v[i][2])};
242  }
243 
244 
245 
246  // ----------------- BoundingBox Primitives AccessTraits ----------------- //
247  template <int dim, typename Number>
248  std::size_t
249  AccessTraits<std::vector<::BoundingBox<dim, Number>>, PrimitivesTag>::
250  size(const std::vector<::BoundingBox<dim, Number>> &v)
251  {
252  return v.size();
253  }
254 
255 
256 
257  template <int dim, typename Number>
258  Box
259  AccessTraits<std::vector<::BoundingBox<dim, Number>>, PrimitivesTag>::
260  get(const std::vector<::BoundingBox<dim, Number>> &v, std::size_t i)
261  {
262  const auto boundary_points = v[i].get_boundary_points();
263  const ::Point<dim, Number> min_corner = boundary_points.first;
264  const ::Point<dim, Number> max_corner = boundary_points.second;
265  // ArborX assumes that the bounding box coordinates use float and that the
266  // bounding box is 3D
267  return {{static_cast<float>(min_corner[0]),
268  static_cast<float>(min_corner[1]),
269  dim == 2 ? 0.f : static_cast<float>(min_corner[2])},
270  {static_cast<float>(max_corner[0]),
271  static_cast<float>(max_corner[1]),
272  dim == 2 ? 0.f : static_cast<float>(max_corner[2])}};
273  }
274 
275 
276 
277  // ---------------------- Sphere Primitives AccessTraits ----------------- //
278  template <int dim, typename Number>
279  std::size_t
280  AccessTraits<std::vector<std::pair<::Point<dim, Number>, Number>>,
281  PrimitivesTag>::
282  size(const std::vector<std::pair<::Point<dim, Number>, Number>> &v)
283  {
284  return v.size();
285  }
286 
287 
288 
289  template <int dim, typename Number>
290  Sphere
291  AccessTraits<std::vector<std::pair<::Point<dim, Number>, Number>>,
292  PrimitivesTag>::
293  get(const std::vector<std::pair<::Point<dim, Number>, Number>> &v,
294  std::size_t i)
295  {
296  // ArborX assumes that the center coordinates and the radius use float and
297  // the sphere is 3D
298  return {{static_cast<float>(v[i].first[0]),
299  static_cast<float>(v[i].first[1]),
300  dim == 2 ? 0 : static_cast<float>(v[i].first[2])},
301  static_cast<float>(v[i].second)};
302  }
303 } // namespace ArborX
304 
305 // ----------------------- Instantiations --------------------//
306 # include "access_traits.inst"
307 
308 #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)
std::vector<::BoundingBox< 3, float > > bounding_boxes
const ::BoundingBox< 3, float > & get(unsigned int i) const
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
Definition: access_traits.h:59
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)
unsigned int get_n_nearest_neighbors() 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)
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:442
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:443
Point< 2 > second
Definition: grid_out.cc:4604
Point< 2 > first
Definition: grid_out.cc:4603
SignedDistance::Sphere< dim > Sphere
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)