namespace gpr::sfc

Overview

namespace sfc {
 
// global variables
 
uint8_t MORTON_TO_HILBERT_LUT[96] = {     48, 33, 27, 34, 47, 78, 28, 77,       66, 29, 51, 52, 65, 30, 72, 63,       76, 95, 75, 24, 53, 54, 82, 81,       18,  3, 17, 80, 61,  4, 62, 15,        0, 59, 71, 60, 49, 50, 86, 85,       84, 83,  5, 90, 79, 56,  6, 89,       32, 23,  1, 94, 11, 12,  2, 93,       42, 41, 13, 14, 35, 88, 36, 31,       92, 37, 87, 38, 91, 74,  8, 73,       46, 45,  9, 10,  7, 20, 64, 19,       70, 25, 39, 16, 69, 26, 44, 43,       22, 55, 21, 68, 57, 40, 58, 67,   };
 
// global functions
 
uint32_t morton_3d(uint32_t x, uint32_t y, uint32_t z);
uint32_t morton_to_hilbert_3d(uint32_t morton, uint32_t bits);
uint32_t hilbert_3d(double x, double y, double z, double min_coord, double scale, uint32_t bits = 10);
std::vector<size_t> hilbert_permutation(const double* coords, size_t n_atoms, uint32_t bits = 10);
 
} // namespace sfc

Detailed Documentation

Global Variables

uint8_t MORTON_TO_HILBERT_LUT[96] = {     48, 33, 27, 34, 47, 78, 28, 77,       66, 29, 51, 52, 65, 30, 72, 63,       76, 95, 75, 24, 53, 54, 82, 81,       18,  3, 17, 80, 61,  4, 62, 15,        0, 59, 71, 60, 49, 50, 86, 85,       84, 83,  5, 90, 79, 56,  6, 89,       32, 23,  1, 94, 11, 12,  2, 93,       42, 41, 13, 14, 35, 88, 36, 31,       92, 37, 87, 38, 91, 74,  8, 73,       46, 45,  9, 10,  7, 20, 64, 19,       70, 25, 39, 16, 69, 26, 44, 43,       22, 55, 21, 68, 57, 40, 58, 67,   }

96-byte LUT for Morton->Hilbert conversion.

12 transform states x 8 octants = 96 entries. Upper bits encode next transform state, lower 3 bits encode Hilbert sub-index.

Global Functions

uint32_t morton_3d(uint32_t x, uint32_t y, uint32_t z)

Compute 3D Morton (Z-order) index from integer coordinates.

Morton index interleaves bits: xyz -> …z2y2x2z1y1x1z0y0x0 Uses pdep intrinsic on BMI2-capable CPUs, otherwise bit manipulation.

Parameters:

x

X coordinate (0 to 2^bits - 1)

y

Y coordinate (0 to 2^bits - 1)

z

Z coordinate (0 to 2^bits - 1)

Returns:

Morton index

uint32_t morton_to_hilbert_3d(uint32_t morton, uint32_t bits)

Convert Morton index to Hilbert index using 96-byte LUT.

Parameters:

morton

Morton (Z-order) index

bits

Number of bits per dimension (max 10 for 32-bit output)

Returns:

Hilbert index

uint32_t hilbert_3d(double x, double y, double z, double min_coord, double scale, uint32_t bits = 10)

Compute 3D Hilbert index from floating-point coordinates.

Parameters:

x

X coordinate

y

Y coordinate

z

Z coordinate

min_coord

Minimum coordinate value (for normalization)

scale

Coordinate range (max - min, for normalization)

bits

Precision bits per dimension (default 10, giving 1024 levels)

Returns:

Hilbert index

std::vector<size_t> hilbert_permutation(const double* coords, size_t n_atoms, uint32_t bits = 10)

Compute Hilbert-ordered permutation for a set of 3D points.

Returns a permutation array such that iterating over atoms in permutation order visits them in Hilbert curve order (spatially coherent).

Parameters:

coords

Pointer to xyz coordinates, packed as [x0,y0,z0,x1,y1,z1,…]

n_atoms

Number of atoms

bits

Hilbert precision (default 10)

Returns:

Permutation array where perm[i] is the original index of the i-th atom in Hilbert order