]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add 1d support for ArborXWrappers
authorDaniel Arndt <arndtd@ornl.gov>
Tue, 11 Jul 2023 18:42:53 +0000 (14:42 -0400)
committerDaniel Arndt <arndtd@ornl.gov>
Tue, 11 Jul 2023 19:19:24 +0000 (15:19 -0400)
12 files changed:
source/arborx/access_traits.cc
source/arborx/access_traits.inst.in
tests/arborx/bounding_box_intersect.cc
tests/arborx/bounding_box_intersect.output
tests/arborx/distributed_tree_intersect.cc
tests/arborx/distributed_tree_intersect.with_arborx_with_mpi=on.mpirun=2.output
tests/arborx/point_intersect.cc
tests/arborx/point_intersect.output
tests/arborx/sphere_intersect.cc
tests/arborx/sphere_intersect.output
tests/arborx/sphere_nearest.cc
tests/arborx/sphere_nearest.output

index 1520624d49454e999c44728c278d695bf8ee8e62..3c37bc69823b9de1aff5a613917f39ee075f56fe 100644 (file)
@@ -26,16 +26,15 @@ namespace ArborXWrappers
   PointPredicate::PointPredicate(
     const std::vector<dealii::Point<dim, Number>> &dim_points)
   {
-    static_assert(dim != 1, "dim equal to one is not supported.");
-
     const unsigned int size = dim_points.size();
     points.reserve(size);
     for (unsigned int i = 0; i < size; ++i)
       {
         points.emplace_back(static_cast<float>(dim_points[i][0]),
-                            static_cast<float>(dim_points[i][1]),
-                            dim == 2 ? 0.f :
-                                       static_cast<float>(dim_points[i][2]));
+                            dim < 2 ? 0.f :
+                                      static_cast<float>(dim_points[i][1]),
+                            dim < 3 ? 0.f :
+                                      static_cast<float>(dim_points[i][2]));
       }
   }
 
@@ -153,20 +152,18 @@ namespace ArborXWrappers
     const std::vector<std::pair<dealii::Point<dim, Number>, Number>>
       &dim_spheres)
   {
-    static_assert(dim != 1, "dim equal to one is not supported.");
-
     const unsigned int size = dim_spheres.size();
     spheres.reserve(size);
     for (unsigned int i = 0; i < size; ++i)
       {
         // ArborX assumes that the center coordinates and the radius use float
         // and the sphere is 3d
-        spheres.emplace_back(std::make_pair(
+        spheres.emplace_back(
           dealii::Point<3, float>(
             static_cast<float>(dim_spheres[i].first[0]),
-            static_cast<float>(dim_spheres[i].first[1]),
-            dim == 2 ? 0.f : static_cast<float>(dim_spheres[i].first[2])),
-          static_cast<float>(dim_spheres[i].second)));
+            dim < 2 ? 0.f : static_cast<float>(dim_spheres[i].first[1]),
+            dim < 3 ? 0.f : static_cast<float>(dim_spheres[i].first[2])),
+          static_cast<float>(dim_spheres[i].second));
       }
   }
 
@@ -237,8 +234,8 @@ namespace ArborX
     // ArborX assumes that the point coordinates use float and that the point
     // is 3d
     return {static_cast<float>(v[i][0]),
-            static_cast<float>(v[i][1]),
-            dim == 2 ? 0 : static_cast<float>(v[i][2])};
+            dim < 2 ? 0 : static_cast<float>(v[i][1]),
+            dim < 3 ? 0 : static_cast<float>(v[i][2])};
   }
 
 
@@ -265,11 +262,11 @@ namespace ArborX
     // ArborX assumes that the bounding box coordinates use float and that the
     // bounding box is 3d
     return {{static_cast<float>(min_corner[0]),
-             static_cast<float>(min_corner[1]),
-             dim == 2 ? 0.f : static_cast<float>(min_corner[2])},
+             dim < 2 ? 0.f : static_cast<float>(min_corner[1]),
+             dim < 3 ? 0.f : static_cast<float>(min_corner[2])},
             {static_cast<float>(max_corner[0]),
-             static_cast<float>(max_corner[1]),
-             dim == 2 ? 0.f : static_cast<float>(max_corner[2])}};
+             dim < 2 ? 0.f : static_cast<float>(max_corner[1]),
+             dim < 3 ? 0.f : static_cast<float>(max_corner[2])}};
   }
 
 
@@ -296,8 +293,8 @@ namespace ArborX
     // ArborX assumes that the center coordinates and the radius use float and
     // the sphere is 3d
     return {{static_cast<float>(v[i].first[0]),
-             static_cast<float>(v[i].first[1]),
-             dim == 2 ? 0 : static_cast<float>(v[i].first[2])},
+             dim < 2 ? 0 : static_cast<float>(v[i].first[1]),
+             dim < 3 ? 0 : static_cast<float>(v[i].first[2])},
             static_cast<float>(v[i].second)};
   }
 } // namespace ArborX
index f82c48379265215e0698e85c8d50b6aee918d5d9..45ca6c5b5480feadbba27cd0e15c8056b81d41be 100644 (file)
@@ -16,7 +16,6 @@
 
 for (DIM : DIMENSIONS; SCALAR : REAL_SCALARS)
   {
-#if DIM > 1
     DEAL_II_NAMESPACE_OPEN
     namespace ArborXWrappers
     {
@@ -55,5 +54,4 @@ for (DIM : DIMENSIONS; SCALAR : REAL_SCALARS)
         std::vector<std::pair<dealii::Point<DIM, SCALAR>, SCALAR>>,
         PrimitivesTag>;
     \}
-#endif
   }
index 30aec63c204434509b759a3b1527205d90e8ae39..43f53c2a62748ef400bf31d6215389999ae9dfd4 100644 (file)
 
 #include "../tests.h"
 
+void
+test_1d()
+{
+  std::vector<BoundingBox<1>> bounding_boxes;
+  std::vector<Point<1>>       points;
+
+  unsigned int n_points_1d = 5;
+  for (unsigned int i = 0; i < n_points_1d; ++i)
+    points.emplace_back(i);
+
+  for (unsigned int i = 0; i < n_points_1d - 1; ++i)
+    bounding_boxes.emplace_back(std::make_pair(points[i], points[i + 1]));
+
+  Point<1> point_a(0.5);
+  Point<1> point_b(1.5);
+  Point<1> point_c(2.2);
+  Point<1> point_d(2.6);
+
+  std::vector<BoundingBox<1>> query_bounding_boxes;
+  query_bounding_boxes.emplace_back(std::make_pair(point_a, point_b));
+  query_bounding_boxes.emplace_back(std::make_pair(point_c, point_d));
+
+  ArborXWrappers::BVH                           bvh(bounding_boxes);
+  ArborXWrappers::BoundingBoxIntersectPredicate bb_intersect(
+    query_bounding_boxes);
+  auto             indices_offset = bvh.query(bb_intersect);
+  std::vector<int> indices        = indices_offset.first;
+  std::vector<int> offset         = indices_offset.second;
+
+  std::vector<int> indices_ref = {0, 1, 2};
+  std::vector<int> offset_ref  = {0, 2, 3};
+
+  AssertDimension(indices.size(), indices_ref.size());
+  AssertDimension(offset.size(), offset_ref.size());
+  for (unsigned int i = 0; i < offset.size() - 1; ++i)
+    {
+      for (unsigned int j = offset[i]; j < offset[i + 1]; ++j)
+        {
+          // The indices associated to each query are not ordered.
+          bool found = false;
+          for (unsigned int k = offset[i]; k < offset[i + 1]; ++k)
+            {
+              if (indices[j] == indices_ref[k])
+                {
+                  found = true;
+                  break;
+                }
+            }
+          AssertThrow(found, ExcInternalError());
+        }
+    }
+  for (unsigned int i = 0; i < offset.size(); ++i)
+    AssertThrow(offset[i] == offset_ref[i], ExcInternalError());
+
+  deallog << "OK" << std::endl;
+}
 
 void
 test_2d()
@@ -181,6 +237,7 @@ main(int argc, char **argv)
   initlog();
 
   // tests
+  test_1d();
   test_2d();
   test_3d();
 
index 8b3b075900ce960fcb04b78ce0e95f33d6db4ed2..fb71de2867cdd56077fa628bd1498d2d19382019 100644 (file)
@@ -1,3 +1,4 @@
 
 DEAL::OK
 DEAL::OK
+DEAL::OK
index b3ec93a610a643dbc18c5eaea6b572cbf45dcb48..76cb632e65d7e6d548754093c86a97c0dcc9125c 100644 (file)
 #include "../tests.h"
 
 
+void
+test_1d()
+{
+  std::vector<BoundingBox<1>> bounding_boxes;
+  std::vector<Point<1>>       points;
+
+  const unsigned int n_points_1d = 5;
+  const int          rank    = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD);
+  const int          n_procs = Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD);
+  const int          offset_bb    = 2 * rank * n_points_1d;
+  const int          offset_query = 2 * ((rank + 1) % n_procs) * n_points_1d;
+  for (unsigned int i = 0; i < n_points_1d; ++i)
+    points.emplace_back(i + offset_bb);
+
+  for (unsigned int i = 0; i < n_points_1d - 1; ++i)
+    bounding_boxes.emplace_back(std::make_pair(points[i], points[i + 1]));
+
+  Point<1> point_a(0.5 + offset_query);
+  Point<1> point_b(1.5 + offset_query);
+  Point<1> point_c(2.2 + offset_query);
+  Point<1> point_d(2.6 + offset_query);
+
+  std::vector<BoundingBox<1>> query_bounding_boxes;
+  query_bounding_boxes.emplace_back(std::make_pair(point_a, point_b));
+  query_bounding_boxes.emplace_back(std::make_pair(point_c, point_d));
+
+  ArborXWrappers::DistributedTree               distributed_tree(MPI_COMM_WORLD,
+                                                   bounding_boxes);
+  ArborXWrappers::BoundingBoxIntersectPredicate bb_intersect(
+    query_bounding_boxes);
+  auto indices_ranks_offset = distributed_tree.query(bb_intersect);
+  auto indices_ranks        = indices_ranks_offset.first;
+  auto offsets              = indices_ranks_offset.second;
+
+  std::vector<int> indices_ref = {1, 0, 2};
+  std::vector<int> offsets_ref = {0, 2, 3};
+
+  AssertThrow(indices_ranks.size() == indices_ref.size(), ExcInternalError());
+  AssertThrow(offsets.size() == offsets_ref.size(), ExcInternalError());
+  for (unsigned int i = 0; i < offsets.size() - 1; ++i)
+    {
+      for (int j = offsets[i]; j < offsets[i + 1]; ++j)
+        {
+          // The indices associated to each query are not ordered.
+          bool found = false;
+          for (int k = offsets[i]; k < offsets[i + 1]; ++k)
+            {
+              if ((indices_ranks[j].first == indices_ref[k]) &&
+                  (indices_ranks[j].second == (rank + 1) % n_procs))
+                {
+                  found = true;
+                  break;
+                }
+            }
+          AssertThrow(found, ExcInternalError());
+        }
+    }
+  for (unsigned int i = 0; i < offsets.size(); ++i)
+    AssertThrow(offsets[i] == offsets_ref[i], ExcInternalError());
+
+  deallog << "OK" << std::endl;
+}
+
+
 void
 test_2d()
 {
@@ -192,6 +256,7 @@ main(int argc, char **argv)
   initlog();
 
   // tests
+  test_1d();
   test_2d();
   test_3d();
 }
index 9282f706bc0325e1d56bd8dc7885d35251a1aa0e..fb71de2867cdd56077fa628bd1498d2d19382019 100644 (file)
@@ -1,3 +1,4 @@
 
-DEAL::OK                                                                                                                                                                                                                                     
+DEAL::OK
+DEAL::OK
 DEAL::OK
index e0ff970f26eccb39d5687d077e4d61782c3a51e2..401d1bac7ccc6e85eea04c9326fda0157c95a298 100644 (file)
 #include "../tests.h"
 
 
+void
+test_1d()
+{
+  std::vector<BoundingBox<1>> bounding_boxes;
+  std::vector<Point<1>>       points;
+
+  unsigned int n_points_1d = 5;
+  for (unsigned int i = 0; i < n_points_1d; ++i)
+    points.emplace_back(i);
+
+  for (unsigned int i = 0; i < n_points_1d - 1; ++i)
+    bounding_boxes.emplace_back(std::make_pair(points[i], points[i + 1]));
+
+  std::vector<Point<1>> query_points;
+  query_points.emplace_back(0.5);
+  query_points.emplace_back(1.5);
+  query_points.emplace_back(2.2);
+  query_points.emplace_back(2.6);
+
+
+  ArborXWrappers::BVH                     bvh(bounding_boxes);
+  ArborXWrappers::PointIntersectPredicate pt_intersect(query_points);
+  auto             indices_offset = bvh.query(pt_intersect);
+  std::vector<int> indices        = indices_offset.first;
+  std::vector<int> offset         = indices_offset.second;
+
+  std::vector<int> indices_ref = {0, 1, 2, 2};
+  std::vector<int> offset_ref  = {0, 1, 2, 3, 4};
+
+  AssertThrow(indices.size() == indices_ref.size(), ExcInternalError());
+  AssertThrow(offset.size() == offset_ref.size(), ExcInternalError());
+  for (unsigned int i = 0; i < offset.size() - 1; ++i)
+    {
+      for (unsigned int j = offset[i]; j < offset[i + 1]; ++j)
+        {
+          // The indices associated to each query are not ordered.
+          bool found = false;
+          for (unsigned int k = offset[i]; k < offset[i + 1]; ++k)
+            {
+              if (indices[j] == indices_ref[k])
+                {
+                  found = true;
+                  break;
+                }
+            }
+          AssertThrow(found, ExcInternalError());
+        }
+    }
+  for (unsigned int i = 0; i < offset.size(); ++i)
+    AssertThrow(offset[i] == offset_ref[i], ExcInternalError());
+
+  deallog << "OK" << std::endl;
+}
+
+
 void
 test_2d()
 {
@@ -176,6 +231,7 @@ main(int argc, char **argv)
   Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv);
 
   // tests
+  test_1d();
   test_2d();
   test_3d();
 }
index 8b3b075900ce960fcb04b78ce0e95f33d6db4ed2..fb71de2867cdd56077fa628bd1498d2d19382019 100644 (file)
@@ -1,3 +1,4 @@
 
 DEAL::OK
 DEAL::OK
+DEAL::OK
index a9a807d18db71903a9134a902fd761cc9d972f0c..b46ecee416bdd61645b205586a3c2893423dc998 100644 (file)
 #include "../tests.h"
 
 
+void
+test_1d()
+{
+  std::vector<Point<1>> points;
+
+  unsigned int n_points_1d = 5;
+  for (unsigned int i = 0; i < n_points_1d; ++i)
+    points.emplace_back(i);
+
+  std::vector<std::pair<Point<1>, double>> query_spheres;
+  query_spheres.emplace_back(Point<1>(0.5), 0.8);
+  query_spheres.emplace_back(Point<1>(1.5), 0.8);
+  query_spheres.emplace_back(Point<1>(2.2), 1.2);
+  query_spheres.emplace_back(Point<1>(2.6), 0.9);
+
+
+  ArborXWrappers::BVH                      bvh(points);
+  ArborXWrappers::SphereIntersectPredicate sph_intersect(query_spheres);
+  auto             indices_offsets = bvh.query(sph_intersect);
+  std::vector<int> indices         = indices_offsets.first;
+  std::vector<int> offsets         = indices_offsets.second;
+
+  std::vector<int> indices_ref = {0, 1, 1, 2, 1, 2, 3, 2, 3};
+  std::vector<int> offsets_ref = {0, 2, 4, 7, 9};
+
+  AssertThrow(indices.size() == indices_ref.size(), ExcInternalError());
+  AssertThrow(offsets.size() == offsets_ref.size(), ExcInternalError());
+  for (unsigned int i = 0; i < offsets.size() - 1; ++i)
+    {
+      for (int j = offsets[i]; j < offsets[i + 1]; ++j)
+        {
+          // The indices associated to each query are not ordered.
+          bool found = false;
+          for (int k = offsets[i]; k < offsets[i + 1]; ++k)
+            {
+              if (indices[j] == indices_ref[k])
+                {
+                  found = true;
+                  break;
+                }
+            }
+          AssertThrow(found, ExcInternalError());
+        }
+    }
+  for (unsigned int i = 0; i < offsets.size(); ++i)
+    AssertThrow(offsets[i] == offsets_ref[i], ExcInternalError());
+
+  deallog << "OK" << std::endl;
+}
+
 void
 test_2d()
 {
@@ -150,6 +200,7 @@ main(int argc, char **argv)
   Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv);
 
   // tests
+  test_1d();
   test_2d();
   test_3d();
 }
index 8b3b075900ce960fcb04b78ce0e95f33d6db4ed2..fb71de2867cdd56077fa628bd1498d2d19382019 100644 (file)
@@ -1,3 +1,4 @@
 
 DEAL::OK
 DEAL::OK
+DEAL::OK
index dae5af87c394018343da529ea20f4e3a04b32a77..8ff19ea7a77fb105c655defb196148a33783dfd6 100644 (file)
 
 
 
+void
+test_1d()
+{
+  std::vector<Point<1>> points;
+
+  unsigned int n_points_1d = 5;
+  for (unsigned int i = 0; i < n_points_1d; ++i)
+    points.emplace_back(i);
+
+  std::vector<std::pair<Point<1>, double>> query_spheres;
+  query_spheres.emplace_back(Point<1>(0.5), 0.1);
+  query_spheres.emplace_back(Point<1>(1.5), 0.1);
+  query_spheres.emplace_back(Point<1>(2.2), 0.1);
+  query_spheres.emplace_back(Point<1>(2.6), 0.1);
+
+
+  ArborXWrappers::BVH                    bvh(points);
+  ArborXWrappers::SphereNearestPredicate sph_nearest(query_spheres, 1);
+  auto             indices_offsets = bvh.query(sph_nearest);
+  std::vector<int> indices         = indices_offsets.first;
+  std::vector<int> offsets         = indices_offsets.second;
+
+  std::vector<int> indices_ref = {0, 1, 2, 3};
+  std::vector<int> offsets_ref = {0, 1, 2, 3, 4};
+
+  AssertThrow(indices.size() == indices_ref.size(), ExcInternalError());
+  AssertThrow(offsets.size() == offsets_ref.size(), ExcInternalError());
+  for (unsigned int i = 0; i < offsets.size() - 1; ++i)
+    {
+      for (int j = offsets[i]; j < offsets[i + 1]; ++j)
+        {
+          // The indices associated to each query are not ordered.
+          bool found = false;
+          for (int k = offsets[i]; k < offsets[i + 1]; ++k)
+            {
+              if (indices[j] == indices_ref[k])
+                {
+                  found = true;
+                  break;
+                }
+            }
+          AssertThrow(found, ExcInternalError());
+        }
+    }
+  for (unsigned int i = 0; i < offsets.size(); ++i)
+    AssertThrow(offsets[i] == offsets_ref[i], ExcInternalError());
+
+  deallog << "OK" << std::endl;
+}
+
+
 void
 test_2d()
 {
@@ -149,6 +200,7 @@ main(int argc, char **argv)
   Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv);
 
   // tests
+  test_1d();
   test_2d();
   test_3d();
 }
index 8b3b075900ce960fcb04b78ce0e95f33d6db4ed2..fb71de2867cdd56077fa628bd1498d2d19382019 100644 (file)
@@ -1,3 +1,4 @@
 
 DEAL::OK
 DEAL::OK
+DEAL::OK

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.