10#include <Kokkos_Macros.hpp>
14template <std::
size_t Dimensions>
26template <
class Index, std::
size_t Radius>
29 static_assert(Radius <= 2);
30 static constexpr std::size_t size = Radius == 0 ? 1
31 : Radius == 1 ? 1 + 2 * Index::size()
32 : 1 + 2 * Index::size() * (Index::size() + 1);
33 KOKKOS_FUNCTION
static constexpr std::array<int, Index::size()> offset(std::size_t point)
35 std::array<int, Index::size()> result {};
39 if (point < 2 * Index::size()) {
40 result[point / 2] = point % 2 == 0 ? -1 : 1;
43 point -= 2 * Index::size();
44 if constexpr (Radius == 2) {
45 if (point < 2 * Index::size()) {
46 result[point / 2] = point % 2 == 0 ? -2 : 2;
49 point -= 2 * Index::size();
50 for (std::size_t first = 0; first < Index::size(); ++first)
51 for (std::size_t second = first + 1; second < Index::size(); ++second) {
53 result[first] = point % 2 == 0 ? -1 : 1;
54 result[second] = point / 2 == 0 ? -1 : 1;
71template <
class Index,
class Source,
class Target, std::
size_t Radius>
74 return {flat / (detail::StencilShape<Index, Radius>::size * Source::mem_size()),
75 detail::StencilShape<Index, Radius>::offset(
76 (flat / Source::mem_size()) % detail::StencilShape<Index, Radius>::size),
77 flat % Source::mem_size()};
80template <
class Index,
class Source,
class Target, std::
size_t Radius>
83 for (std::size_t point = 0; point < detail::StencilShape<Index, Radius>::size; ++point)
84 if (detail::StencilShape<Index, Radius>::offset(point) == index.spatial_offset)
85 return (index.output_component * detail::StencilShape<Index, Radius>::size + point)
88 return Target::mem_size() * detail::StencilShape<Index, Radius>::size * Source::mem_size();
93template <
class Index, std::
size_t Count>
94KOKKOS_FUNCTION
constexpr std::size_t stencil_component_index(
95 std::array<std::size_t, Count>
const& ids)
97 if constexpr (Index::rank() == 0)
99 else if constexpr (Index::rank() == 1)
102 return Index::mem_id(ids);
KOKKOS_FUNCTION constexpr StencilIndex< Index::size()> stencil_reindex(std::size_t flat)
Decode the standard ordering: output component, spatial point, input component.
std::size_t input_component
KOKKOS_FUNCTION constexpr std::size_t stencil_flatten(StencilIndex< Index::size()> index)
std::size_t output_component
std::array< int, Dimensions > spatial_offset