44#include " Omega_h_vector.hpp"
55#include " Omega_h_bbox.hpp"
66#include " Omega_h_mesh.hpp"
7- #include < numeric>
7+ #include < Kokkos_Array.hpp>
8+ #include < array>
89namespace pcms
910{
1011
1112template <unsigned dim>
1213struct UniformGrid
1314{
1415 // Make private?
15- std::array <Real, dim> edge_length;
16- std::array <Real, dim> bot_left;
17- std::array <LO , dim> divisions;
16+ Kokkos::Array <Real, dim> edge_length;
17+ Kokkos::Array <Real, dim> bot_left;
18+ Kokkos::Array <LO , dim> divisions;
1819
1920public:
2021 [[nodiscard]] LO GetNumCells () const
2122 {
22- return std::accumulate (divisions.begin (), divisions.end (), 1 ,
23- std::multiplies<LO >{});
23+ LO total = 1 ;
24+ for (std::size_t i = 0 ; i < dim; ++i)
25+ total *= divisions[i];
26+ return total;
2427 }
2528 // / return the grid cell ID that the input point is inside or closest to if
2629 // / the point lies outside
@@ -30,13 +33,13 @@ struct UniformGrid
3033 [[nodiscard]] KOKKOS_INLINE_FUNCTION LO
3134 ClosestCellID (const Omega_h::Vector<dim>& point) const
3235 {
33- std::array <Real, dim> distance_within_grid;
36+ Kokkos::Array <Real, dim> distance_within_grid;
3437
3538 for (size_t i = 0 ; i < dim; ++i) {
3639 distance_within_grid[i] = point[i] - bot_left[i];
3740 }
3841
39- std::array <LO , dim> indexes;
42+ Kokkos::Array <LO , dim> indexes;
4043
4144 for (auto & index : indexes) {
4245 index = -1 ;
@@ -86,14 +89,14 @@ struct UniformGrid
8689 return true ;
8790 }
8891
89- [[nodiscard]] KOKKOS_INLINE_FUNCTION std::array <LO , dim> GetDimensionedIndex (
90- LO idx) const
92+ [[nodiscard]] KOKKOS_INLINE_FUNCTION Kokkos::Array <LO , dim>
93+ GetDimensionedIndex ( LO idx) const
9194 {
9295 LO stride = 1 ;
93- for (std::size_t i = 0 ; i < divisions. size () - 1 ; ++i) {
96+ for (std::size_t i = 0 ; i < dim - 1 ; ++i) {
9497 stride *= divisions[i];
9598 }
96- std::array <LO , dim> result;
99+ Kokkos::Array <LO , dim> result;
97100
98101 for (size_t i = 0 ; i < dim; ++i) {
99102 result[i] = idx / stride;
@@ -105,7 +108,7 @@ struct UniformGrid
105108 }
106109
107110 [[nodiscard]] KOKKOS_INLINE_FUNCTION LO
108- GetCellIndex (std::array <LO , dim> dimensionedIndex) const
111+ GetCellIndex (Kokkos::Array <LO , dim> dimensionedIndex) const
109112 {
110113 // note that the indexes refer to row/columns which have the opposite order
111114 // of the coordinates i.e. x,y
@@ -124,9 +127,9 @@ struct UniformGrid
124127
125128private:
126129 template <typename T, std::size_t N>
127- KOKKOS_INLINE_FUNCTION static void reverse (std::array <T, N>& arr)
130+ KOKKOS_INLINE_FUNCTION static void reverse (Kokkos::Array <T, N>& arr)
128131 {
129- for (size_t i = 0 , j = arr. size () - 1 ; i < j; ++i, --j) {
132+ for (size_t i = 0 , j = N - 1 ; i < j; ++i, --j) {
130133 auto temp = arr[i];
131134 arr[i] = arr[j];
132135 arr[j] = temp;
@@ -158,16 +161,18 @@ UniformGrid<dim> CreateUniformGridFromMesh(Omega_h::Mesh& mesh,
158161 auto bbox = Omega_h::get_bounding_box<dim>(&mesh);
159162
160163 // Calculate edge lengths and bottom-left corner
161- std::array<Real, dim> edge_length;
162- std::array<Real, dim> bot_left;
164+ Kokkos::Array<Real, dim> edge_length;
165+ Kokkos::Array<Real, dim> bot_left;
166+ Kokkos::Array<LO , dim> divs;
163167
164168 for (unsigned i = 0 ; i < dim; ++i) {
165169 bot_left[i] = bbox.min [i];
166170 edge_length[i] = bbox.max [i] - bbox.min [i];
171+ divs[i] = divisions[i];
167172 }
168173
169174 return UniformGrid<dim>{
170- .edge_length = edge_length, .bot_left = bot_left, .divisions = divisions };
175+ .edge_length = edge_length, .bot_left = bot_left, .divisions = divs };
171176}
172177
173178/* *
@@ -187,7 +192,8 @@ UniformGrid<dim> CreateUniformGridFromMesh(Omega_h::Mesh& mesh,
187192 LO cells_per_dim)
188193{
189194 std::array<LO , dim> divisions;
190- divisions.fill (cells_per_dim);
195+ for (unsigned i = 0 ; i < dim; ++i)
196+ divisions[i] = cells_per_dim;
191197 return CreateUniformGridFromMesh<dim>(mesh, divisions);
192198}
193199
0 commit comments