15#ifndef PECLET_CORE_DECOMP_MORTON_INDEXER_HPP
16#define PECLET_CORE_DECOMP_MORTON_INDEXER_HPP
18#ifdef PECLET_CORE_HAVE_MORTON
20#include "morton/morton.hpp"
32template <
int Dim,
unsigned Bits = (Dim == 2 ? 32u : (Dim == 3 ? 21u : 16u))>
35 using M = morton::Morton<Dim, Bits>;
36 using Code =
typename M::code_type;
37 using Coord =
typename M::coord_type;
47 static constexpr unsigned bits() {
return Bits; }
55 for (
int i = 0;
i < Dim; ++
i)
56 m.set(
static_cast<unsigned>(
i), localCoord(g,
i));
62 M m = M::from_code(
c);
64 for (
int i = 0;
i < Dim; ++
i)
65 g[
i] =
static_cast<Index>(m.get(
static_cast<unsigned>(
i))) + origin_[
i];
73 return M::from_code(
c).neighbor(
static_cast<unsigned>(axis), dir >= 0 ? 1 : -1).code();
78 return static_cast<Coord>(g[
i] - origin_[
i]);
Z-order (Morton) indexer over an axis-origin-relative cell block.
MORTON_HD Code codeOf(const IVec< Dim > &g) const
Global multi-index → Z-order code (origin-relative).
const IVec< Dim > & origin() const
void init(IVec< Dim > origin, IVec< Dim > size)
morton::Morton< Dim, Bits > M
typename M::coord_type Coord
const IVec< Dim > & size() const
typename M::code_type Code
MORTON_HD Code neighborCode(Code c, int axis, int dir) const
Neighbour code one cell along ±axis, computed directly in Morton space (the headline O(1) morton arit...
static constexpr unsigned bits()
MORTON_HD IVec< Dim > multiIndex(Code c) const
Z-order code → global multi-index (inverse of codeOf).
MortonIndexer(IVec< Dim > origin, IVec< Dim > size)
Kokkos::View< T *, MemSpace > View
1D device array.
std::int64_t Index
Signed index type for grids and particles (supersedes block_decomposer's long int IndxT).