From fa77eb44ff108d519edf89b3eca8713c2055f5a4 Mon Sep 17 00:00:00 2001 From: Andrey Prokopenko Date: Mon, 13 May 2024 15:03:55 -0400 Subject: [PATCH 1/3] Add KDOP<2,4> and KDOP<2,8> --- src/geometry/ArborX_KDOP.hpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/geometry/ArborX_KDOP.hpp b/src/geometry/ArborX_KDOP.hpp index bfb5d296d..e206cf4a2 100644 --- a/src/geometry/ArborX_KDOP.hpp +++ b/src/geometry/ArborX_KDOP.hpp @@ -29,6 +29,38 @@ namespace Details template struct KDOP_Directions; +template +struct KDOP_Directions<2, 4, Coordinate> +{ + static constexpr int n_directions = 2; + static KOKKOS_FUNCTION auto const &directions() + { + using Direction = Vector<2, Coordinate>; + static constexpr Kokkos::Array directions = { + Direction{1, 0}, + Direction{0, 1}, + }; + return directions; + } +}; + +template +struct KDOP_Directions<2, 8, Coordinate> +{ + static constexpr int n_directions = 4; + static KOKKOS_FUNCTION auto const &directions() + { + using Direction = Vector<2, Coordinate>; + static constexpr Kokkos::Array directions = { + Direction{1, 0}, + Direction{0, 1}, + Direction{1, 1}, + Direction{1, -1}, + }; + return directions; + } +}; + template struct KDOP_Directions<3, 6, Coordinate> { From 582f9d432a167a84ba9a7e61c335b4a49055b7f1 Mon Sep 17 00:00:00 2001 From: Andrey Prokopenko Date: Wed, 15 May 2024 16:08:27 -0400 Subject: [PATCH 2/3] Add tests for 2D KDOP --- test/tstKDOP.cpp | 82 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 8 deletions(-) diff --git a/test/tstKDOP.cpp b/test/tstKDOP.cpp index bdaa3d83b..31a04a371 100644 --- a/test/tstKDOP.cpp +++ b/test/tstKDOP.cpp @@ -9,8 +9,11 @@ * SPDX-License-Identifier: BSD-3-Clause * ****************************************************************************/ +#include #include +#include #include +#include #include "BoostTest_CUDA_clang_workarounds.hpp" #include @@ -18,17 +21,76 @@ #include #include -using ArborX::Box; -using ArborX::Point; using ArborX::Experimental::KDOP; -using KDOP_types = - std::tuple, KDOP<3, 14>, KDOP<3, 18>, KDOP<3, 26>>; - BOOST_AUTO_TEST_SUITE(DiscreteOrientedPolytopes) -BOOST_AUTO_TEST_CASE_TEMPLATE(intersects_KDOP, KDOP_t, KDOP_types) +using KDOP_2D_types = std::tuple, KDOP<2, 8>>; + +BOOST_AUTO_TEST_CASE_TEMPLATE(intersects_kdop_kdop_2D, KDOP_t, KDOP_2D_types) +{ + using Point = ArborX::ExperimentalHyperGeometry::Point<2>; + KDOP_t x; + BOOST_TEST(!intersects(x, x)); + expand(x, Point{1, 0}); + expand(x, Point{0, 1}); + BOOST_TEST(intersects(x, x)); + BOOST_TEST(!intersects(x, KDOP_t{})); +} + +BOOST_AUTO_TEST_CASE_TEMPLATE(intersects_point_kdop_2D, KDOP_t, KDOP_2D_types) +{ + using Point = ArborX::ExperimentalHyperGeometry::Point<2>; + { + KDOP_t x; + BOOST_TEST(!intersects(Point{1, 1}, x)); + } + { + KDOP_t x; // rombus + expand(x, Point{0.5f, 0}); + expand(x, Point{0.5f, 1}); + expand(x, Point{0, 0.5f}); + expand(x, Point{1, 0.5f}); + // unit square corners + BOOST_TEST(intersects(Point{0, 0}, x) == + (std::is_same_v>)); + BOOST_TEST(intersects(Point{1, 0}, x) == + (std::is_same_v>)); + BOOST_TEST(intersects(Point{0, 1}, x) == + (std::is_same_v>)); + BOOST_TEST(intersects(Point{1, 1}, x) == + (std::is_same_v>)); + // rombus corners + BOOST_TEST(intersects(Point{0.5f, 0}, x)); + BOOST_TEST(intersects(Point{0.5f, 1}, x)); + BOOST_TEST(intersects(Point{0, 0.5f}, x)); + BOOST_TEST(intersects(Point{1, 0.5f}, x)); + // unit square center + BOOST_TEST(intersects(Point{0.5f, 0.5f}, x)); + // mid rombus diagonals + BOOST_TEST(intersects(Point{0.75f, 0.25f}, x)); + BOOST_TEST(intersects(Point{0.25f, 0.25f}, x)); + BOOST_TEST(intersects(Point{0.25f, 0.75f}, x)); + BOOST_TEST(intersects(Point{0.75f, 0.75f}, x)); + // slightly outside of the diagonals + BOOST_TEST(intersects(Point{0.8f, 0.2f}, x) == + (std::is_same_v>)); + BOOST_TEST(intersects(Point{0.2f, 0.2f}, x) == + (std::is_same_v>)); + BOOST_TEST(intersects(Point{0.2f, 0.8f}, x) == + (std::is_same_v>)); + BOOST_TEST(intersects(Point{0.8f, 0.8f}, x) == + (std::is_same_v>)); + } +} + +using KDOP_3D_types = + std::tuple, KDOP<3, 14>, KDOP<3, 18>, KDOP<3, 26>>; + +BOOST_AUTO_TEST_CASE_TEMPLATE(intersects_kdop_kdop_3D, KDOP_t, KDOP_3D_types) { + using ArborX::Point; + KDOP_t x; BOOST_TEST(!intersects(x, x)); expand(x, Point{1, 0, 0}); @@ -38,8 +100,11 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(intersects_KDOP, KDOP_t, KDOP_types) BOOST_TEST(!intersects(x, KDOP_t{})); } -BOOST_AUTO_TEST_CASE_TEMPLATE(intersects_box, KDOP_t, KDOP_types) +BOOST_AUTO_TEST_CASE_TEMPLATE(intersects_kdop_box_3D, KDOP_t, KDOP_3D_types) { + using ArborX::Box; + using ArborX::Point; + KDOP_t x; BOOST_TEST(!intersects(x, Box{})); BOOST_TEST(!intersects(x, Box{{0, 0, 0}, {1, 1, 1}})); @@ -50,8 +115,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(intersects_box, KDOP_t, KDOP_types) BOOST_TEST(intersects(x, Box{{0, 0, 0}, {1, 1, 1}})); } -BOOST_AUTO_TEST_CASE_TEMPLATE(intersects_point, KDOP_t, KDOP_types) +BOOST_AUTO_TEST_CASE_TEMPLATE(intersects_point_kdop, KDOP_t, KDOP_3D_types) { + using ArborX::Point; { KDOP_t x; BOOST_TEST(!intersects(Point{1, 1, 1}, x)); From 5fb410ef33068ff0defef5fae2855f14c1b46089 Mon Sep 17 00:00:00 2001 From: Andrey Prokopenko Date: Thu, 16 May 2024 10:22:51 -0400 Subject: [PATCH 3/3] Fix and add test for intersects(kdop, box) for 2D --- src/geometry/ArborX_KDOP.hpp | 61 +++++++++++++++++++++++++----------- test/tstKDOP.cpp | 15 +++++++++ 2 files changed, 57 insertions(+), 19 deletions(-) diff --git a/src/geometry/ArborX_KDOP.hpp b/src/geometry/ArborX_KDOP.hpp index e206cf4a2..01e8189af 100644 --- a/src/geometry/ArborX_KDOP.hpp +++ b/src/geometry/ArborX_KDOP.hpp @@ -250,33 +250,56 @@ struct expand { KOKKOS_FUNCTION static void apply(KDOP &kdop, Box const &box) { + constexpr int DIM = GeometryTraits::dimension_v; + static_assert(DIM == 2 || DIM == 3); + // NOTE if any of the ranges is invalid, the code below would actually // expand the KDOP which is not what we want. // We may revisit this later and decide passing a valid box becomes a // precondition but this would be a breaking change (going from a wide to a // narrow contract). - for (int i = 0; i < 3; ++i) - if (box.minCorner()[i] > box.maxCorner()[i]) + for (int d = 0; d < DIM; ++d) + if (box.minCorner()[d] > box.maxCorner()[d]) return; - auto const xmin = box.minCorner()[0]; - auto const ymin = box.minCorner()[1]; - auto const zmin = box.minCorner()[2]; - auto const xmax = box.maxCorner()[0]; - auto const ymax = box.maxCorner()[1]; - auto const zmax = box.maxCorner()[2]; - for (auto const &point : { - Point{xmin, ymin, zmin}, - Point{xmin, ymax, zmin}, - Point{xmin, ymin, zmax}, - Point{xmin, ymax, zmax}, - Point{xmax, ymin, zmin}, - Point{xmax, ymax, zmin}, - Point{xmax, ymin, zmax}, - Point{xmax, ymax, zmax}, - }) + using Point = std::decay_t; + if constexpr (DIM == 3) { - Details::expand(kdop, point); + auto const xmin = box.minCorner()[0]; + auto const ymin = box.minCorner()[1]; + auto const zmin = box.minCorner()[2]; + auto const xmax = box.maxCorner()[0]; + auto const ymax = box.maxCorner()[1]; + auto const zmax = box.maxCorner()[2]; + for (auto const &point : { + Point{xmin, ymin, zmin}, + Point{xmin, ymax, zmin}, + Point{xmin, ymin, zmax}, + Point{xmin, ymax, zmax}, + Point{xmax, ymin, zmin}, + Point{xmax, ymax, zmin}, + Point{xmax, ymin, zmax}, + Point{xmax, ymax, zmax}, + }) + { + Details::expand(kdop, point); + } + } + else + { + auto const xmin = box.minCorner()[0]; + auto const ymin = box.minCorner()[1]; + auto const xmax = box.maxCorner()[0]; + auto const ymax = box.maxCorner()[1]; + for (auto const &point : { + Point{xmin, ymin}, + Point{xmin, ymax}, + Point{xmax, ymin}, + Point{xmax, ymax}, + }) + { + Details::expand(kdop, point); + } } } }; diff --git a/test/tstKDOP.cpp b/test/tstKDOP.cpp index 31a04a371..58d6da56f 100644 --- a/test/tstKDOP.cpp +++ b/test/tstKDOP.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -38,6 +39,20 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(intersects_kdop_kdop_2D, KDOP_t, KDOP_2D_types) BOOST_TEST(!intersects(x, KDOP_t{})); } +BOOST_AUTO_TEST_CASE_TEMPLATE(intersects_kdop_box_2D, KDOP_t, KDOP_2D_types) +{ + using Point = ArborX::ExperimentalHyperGeometry::Point<2>; + using Box = ArborX::ExperimentalHyperGeometry::Box<2>; + + KDOP_t x; + BOOST_TEST(!intersects(x, Box{})); + BOOST_TEST(!intersects(x, Box{{0, 0}, {1, 1}})); + expand(x, Point{1, 0}); + expand(x, Point{0, 1}); + BOOST_TEST(!intersects(x, Box{})); + BOOST_TEST(intersects(x, Box{{0, 0}, {1, 1}})); +} + BOOST_AUTO_TEST_CASE_TEMPLATE(intersects_point_kdop_2D, KDOP_t, KDOP_2D_types) { using Point = ArborX::ExperimentalHyperGeometry::Point<2>;