EBGeometry 1.0
Loading...
Searching...
No Matches
EBGeometry_SFC.hpp
Go to the documentation of this file.
1/* EBGeometry
2 * Copyright © 2024 Robert Marskar
3 * Please refer to Copyright.txt and LICENSE in the EBGeometry root directory.
4 */
5
12#ifndef EBGeometry_SFC
13#define EBGeometry_SFC
14
15// Std includes
16#include <cstdint>
17
18// Our includes
20
21namespace SFC {
22
26 using Code = uint64_t;
27
31 using Index = std::array<unsigned int, 3>;
32
36 static constexpr unsigned int ValidBits = 21;
37
41 static constexpr Code ValidSpan = (static_cast<uint64_t>(1) << ValidBits) - 1;
42
43#if __cplusplus >= 202002L
47 template <typename S>
48 concept Encodable = requires(const Index& point, const SFC::Code code) {
49 { S::encode(point) } -> std::same_as<SFC::Code>;
50 { S::decode(code) } -> std::same_as<Index>;
51 };
52#endif
53
57 struct Morton
58 {
63 inline static uint64_t
64 encode(const Index& a_point) noexcept;
65
70 inline static Index
71 decode(const uint64_t& a_code) noexcept;
72
73 protected:
77 static constexpr uint_fast64_t Mask_64[6]{
78 0x1fffff, 0x1f00000000ffff, 0x1f0000ff0000ff, 0x100f00f00f00f00f, 0x10c30c30c30c30c3, 0x1249249249249249};
79 };
80
85 struct Nested
86 {
91 inline static uint64_t
92 encode(const Index& a_point) noexcept;
93
98 inline static Index
99 decode(const uint64_t& a_code) noexcept;
100 };
101} // namespace SFC
102
104
105#if __cplusplus >= 202002L
106static_assert(EBGeometry::SFC::Encodable<EBGeometry::SFC::Morton>);
107static_assert(EBGeometry::SFC::Encodable<EBGeometry::SFC::Nested>);
108#endif
109
110#include "EBGeometry_SFCImplem.hpp"
111
112#endif
std::array< unsigned int, 3 > Index
Alias for 3D cell index.
Definition EBGeometry_SFC.hpp:31
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:218
Implementation of the Morton SFC.
Definition EBGeometry_SFC.hpp:58
static Index decode(const uint64_t &a_code) noexcept
Decode the 64-bit Morton code into an Index.
static constexpr uint_fast64_t Mask_64[6]
Mask for magic-bits encoding of 3D Morton code.
Definition EBGeometry_SFC.hpp:77
static uint64_t encode(const Index &a_point) noexcept
Encode an input point into a Morton index with a 64-bit representation.
Implementation of a nested index SFC.
Definition EBGeometry_SFC.hpp:86
static Index decode(const uint64_t &a_code) noexcept
Decode the 64-bit SFC code into an Index.
static uint64_t encode(const Index &a_point) noexcept
Encode the input point into the SFC code.