Skip to content

Commit

Permalink
Use HyperTriangle
Browse files Browse the repository at this point in the history
  • Loading branch information
masterleinad committed Aug 4, 2023
1 parent ea2b750 commit 1008189
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions benchmarks/tokamak/tokamak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@
****************************************************************************/

#include <ArborX.hpp>
#include <ArborX_HyperTriangle.hpp>

#include <Kokkos_Core.hpp>

#include <fstream>

template <int dim>
struct Triangle
{
ArborX::ExperimentalHyperGeometry::Point<dim> a, b, c;
};

struct Mapping
{
ArborX::ExperimentalHyperGeometry::Point<2> alpha;
Expand All @@ -37,7 +32,7 @@ struct Mapping

// x = a + alpha * (b - a) + beta * (c - a)
// = (1-beta-alpha) * a + alpha * b + beta * c
void compute(Triangle<2> const &triangle)
void compute(ArborX::ExperimentalHyperGeometry::Triangle<2> const &triangle)
{
auto const &a = triangle.a;
auto const &b = triangle.b;
Expand All @@ -55,7 +50,7 @@ struct Mapping
p0 = a;
}

Triangle<2> get_triangle() const
ArborX::ExperimentalHyperGeometry::Triangle<2> get_triangle() const
{
float const inv_det = 1. / (alpha[0] * beta[1] - alpha[1] * beta[0]);
ArborX::ExperimentalHyperGeometry::Point<2> a = p0;
Expand All @@ -74,7 +69,8 @@ struct Triangles
KOKKOS_FUNCTION int size() const { return triangles_.size(); }

// Return the triangle with index i.
KOKKOS_FUNCTION Triangle<2> const &get_triangle(int i) const
KOKKOS_FUNCTION ArborX::ExperimentalHyperGeometry::Triangle<2> const &
get_triangle(int i) const
{
return triangles_(i);
}
Expand All @@ -84,7 +80,9 @@ struct Triangles
return mappings_(i);
}

Kokkos::View<Triangle<2> *, typename DeviceType::memory_space> triangles_;
Kokkos::View<ArborX::ExperimentalHyperGeometry::Triangle<2> *,
typename DeviceType::memory_space>
triangles_;
Kokkos::View<Mapping *, typename DeviceType::memory_space> mappings_;
};

Expand Down Expand Up @@ -150,15 +148,15 @@ template <typename DeviceType>
Triangles<DeviceType>
parse_stl(typename DeviceType::execution_space const &execution_space)
{
std::vector<Triangle<2>> triangles_host;
std::vector<ArborX::ExperimentalHyperGeometry::Triangle<2>> triangles_host;
std::vector<Mapping> mappings_host;
std::ifstream stl_file("RZGrid.stl");
if (!stl_file.good())
throw std::runtime_error("Cannot open file");
std::string line;
std::istringstream in;
Mapping mapping;
Triangle<2> triangle;
ArborX::ExperimentalHyperGeometry::Triangle<2> triangle;
std::string dummy;
while (std::getline(stl_file >> std::ws, line))
{
Expand Down Expand Up @@ -195,12 +193,15 @@ parse_stl(typename DeviceType::execution_space const &execution_space)

std::cout << "Read " << triangles_host.size() << " Triangles\n";

Kokkos::View<Triangle<2> *, typename DeviceType::memory_space> triangles(
Kokkos::view_alloc(Kokkos::WithoutInitializing, "triangles"),
triangles_host.size());
Kokkos::deep_copy(execution_space, triangles,
Kokkos::View<Triangle<2> *, Kokkos::HostSpace>(
triangles_host.data(), triangles_host.size()));
Kokkos::View<ArborX::ExperimentalHyperGeometry::Triangle<2> *,
typename DeviceType::memory_space>
triangles(Kokkos::view_alloc(Kokkos::WithoutInitializing, "triangles"),
triangles_host.size());
Kokkos::deep_copy(
execution_space, triangles,
Kokkos::View<ArborX::ExperimentalHyperGeometry::Triangle<2> *,
Kokkos::HostSpace>(triangles_host.data(),
triangles_host.size()));

Kokkos::View<Mapping *, typename DeviceType::memory_space> mappings(
Kokkos::view_alloc(Kokkos::WithoutInitializing, "mappings"),
Expand Down Expand Up @@ -296,7 +297,8 @@ int main()

std::cout << "Creating BVH tree.\n";
ArborX::BasicBoundingVolumeHierarchy<
MemorySpace, ArborX::ExperimentalHyperGeometry::Box<2>> const
MemorySpace, ArborX::Details::PairIndexVolume<
ArborX::ExperimentalHyperGeometry::Box<2>>> const
tree(execution_space, triangles);
std::cout << "BVH tree set up.\n";

Expand All @@ -309,11 +311,9 @@ int main()
ArborX::Point &coeffs;
};

ArborX::Details::TreeTraversal<
ArborX::BasicBoundingVolumeHierarchy<
MemorySpace, ArborX::ExperimentalHyperGeometry::Box<2>>,
Dummy, TriangleIntersectionCallback<DeviceType>,
ArborX::Details::SpatialPredicateTag>
ArborX::Details::TreeTraversal<decltype(tree), Dummy,
TriangleIntersectionCallback<DeviceType>,
ArborX::Details::SpatialPredicateTag>
tree_traversal(tree,
TriangleIntersectionCallback<DeviceType>{triangles});

Expand Down

0 comments on commit 1008189

Please sign in to comment.