Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
pySfc.cpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
18#include "shammath/sfc/bmi.hpp"
21#include <variant>
22
23enum ReprType { _u32, _u64 };
24
25using namespace shamrock::sfc;
26
27namespace shampylib {
28
29 void init_shamrock_math_sfc(py::module &m) {
30
31 py::module sfc_module = m.def_submodule("sfc", "Space Filling curve Library");
32
33 sfc_module.def(
34 "icoord_to_morton_3d_u64",
35 [](u32 x, u32 y, u32 z) -> u64 {
37 },
38 R"pbdoc(
39 Convert a 3d integer coord to morton code
40 )pbdoc");
41
42 sfc_module.def(
43 "morton_to_icoord_3d_u64",
44 [](u64 m) -> std::array<u32, 3> {
46 return {u32{ret.x()}, u32{ret.y()}, u32{ret.z()}};
47 },
48 R"pbdoc(
49 Convert a morton code to 3d integer coord
50 )pbdoc");
51
52 sfc_module.def(
53 "icoord_to_morton_3d_u32",
54 [](u16 x, u16 y, u16 z) -> u32 {
56 },
57 R"pbdoc(
58 Convert a 3d integer coord to morton code
59 )pbdoc");
60
61 sfc_module.def(
62 "morton_to_icoord_3d_u32",
63 [](u32 m) -> std::array<u16, 3> {
65 return {u16{ret.x()}, u16{ret.y()}, u16{ret.z()}};
66 },
67 R"pbdoc(
68 Convert a morton code to 3d integer coord
69 )pbdoc");
70
71 sfc_module.def(
72 "to_morton_grid_3d_u32_f32_3",
73 [](std::array<f32, 3> pos,
74 std::array<f32, 3> bmin,
75 std::array<f32, 3> bmax) -> std::array<u16, 3> {
76 f32_3 pos_{pos[0], pos[1], pos[2]};
77 f32_3 bmin_{bmin[0], bmin[1], bmin[2]};
78 f32_3 bmax_{bmax[0], bmax[1], bmax[2]};
79 auto tmp = MortonConverter<u32, f32_3, 3>::get_transform(bmin_, bmax_);
81 return {u16{ret.x()}, u16{ret.y()}, u16{ret.z()}};
82 });
83
84 sfc_module.def(
85 "to_morton_grid_3d_u32_f64_3",
86 [](std::array<f64, 3> pos,
87 std::array<f64, 3> bmin,
88 std::array<f64, 3> bmax) -> std::array<u16, 3> {
89 f64_3 pos_{pos[0], pos[1], pos[2]};
90 f64_3 bmin_{bmin[0], bmin[1], bmin[2]};
91 f64_3 bmax_{bmax[0], bmax[1], bmax[2]};
92 auto tmp = MortonConverter<u32, f64_3, 3>::get_transform(bmin_, bmax_);
94 return {u16{ret.x()}, u16{ret.y()}, u16{ret.z()}};
95 });
96
97 sfc_module.def(
98 "to_morton_grid_3d_u64_f32_3",
99 [](std::array<f32, 3> pos,
100 std::array<f32, 3> bmin,
101 std::array<f32, 3> bmax) -> std::array<u32, 3> {
102 f32_3 pos_{pos[0], pos[1], pos[2]};
103 f32_3 bmin_{bmin[0], bmin[1], bmin[2]};
104 f32_3 bmax_{bmax[0], bmax[1], bmax[2]};
105 auto tmp = MortonConverter<u64, f32_3, 3>::get_transform(bmin_, bmax_);
107 return {u32{ret.x()}, u32{ret.y()}, u32{ret.z()}};
108 });
109
110 sfc_module.def(
111 "to_morton_grid_3d_u64_f64_3",
112 [](std::array<f64, 3> pos,
113 std::array<f64, 3> bmin,
114 std::array<f64, 3> bmax) -> std::array<u32, 3> {
115 f64_3 pos_{pos[0], pos[1], pos[2]};
116 f64_3 bmin_{bmin[0], bmin[1], bmin[2]};
117 f64_3 bmax_{bmax[0], bmax[1], bmax[2]};
118 auto tmp = MortonConverter<u64, f64_3, 3>::get_transform(bmin_, bmax_);
120 return {u32{ret.x()}, u32{ret.y()}, u32{ret.z()}};
121 });
122
123 sfc_module.def(
124 "coord_to_hilbert_3d_u64",
125 [](f64 x, f64 y, f64 z) {
127 },
128 R"pbdoc(
129 Convert a 3d coordinate in the unit cube to hilbert codes
130 )pbdoc");
131 }
132
133} // namespace shampylib
double f64
Alias for double.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
std::uint16_t u16
16 bit unsigned integer
Bit manipulation instruction implementation for SYCL.
hilbert curve implementation from killing J., 2004
Morton curve implementation.
Pybind11 include and definitions.