Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
pyShamtree.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
15
16#include "shambase/time.hpp"
21#include "shamcomm/logs.hpp"
25#include <pybind11/complex.h>
26
27template<class Tmorton, class Tvec, u32 dim>
28inline void register_CLBVH(py::module &m, const char *class_name) {
29
31
32 shamcomm::logs::debug_ln("[Py]", "registering shamrock.tree." + std::string(class_name));
33 py::class_<CLBVH>(m, class_name)
34 .def(py::init([]() {
35 return std::make_unique<CLBVH>(
36 CLBVH::make_empty(shamsys::instance::get_compute_scheduler_ptr()));
37 }))
38 .def(
39 "rebuild_from_positions",
40 [](CLBVH &self,
41 sham::DeviceBuffer<Tvec> &positions,
42 const shammath::AABB<Tvec> &bounding_box,
43 u32 compression_level) {
44 self.rebuild_from_positions(positions, bounding_box, compression_level);
45 })
46 .def(
47 "get_leaf_cell_count",
48 [](CLBVH &self) {
49 return self.get_leaf_cell_count();
50 })
51 .def(
52 "get_internal_cell_count",
53 [](CLBVH &self) {
54 return self.get_internal_cell_count();
55 })
56 .def("get_total_cell_count", [](CLBVH &self) {
57 return self.get_total_cell_count();
58 });
59}
60
61template<class Tmorton, class Tvec, u32 dim>
62inline void register_dtt_alg(py::module &m) {
63 py::class_<shamtree::DTTResult>(m, "DTTResult").def(py::init([]() {
64 return std::make_unique<shamtree::DTTResult>(shamtree::DTTResult{
65 .node_interactions_m2l
66 = sham::DeviceBuffer<u32_2>(0, shamsys::instance::get_compute_scheduler_ptr()),
67 .node_interactions_p2p
68 = sham::DeviceBuffer<u32_2>(0, shamsys::instance::get_compute_scheduler_ptr())});
69 }));
70
71 m.def(
72 "clbvh_dual_tree_traversal",
74 shambase::VecComponent<Tvec> theta_crit,
75 bool ordered_result) {
77 shamsys::instance::get_compute_scheduler_ptr(), bvh, theta_crit, ordered_result);
78 });
79
80 m.def(
81 "benchmark_clbvh_dual_tree_traversal",
83 shambase::VecComponent<Tvec> theta_crit,
84 bool ordered_result) {
86 t.start();
88 shamsys::instance::get_compute_scheduler_ptr(), bvh, theta_crit, ordered_result);
89 t.stop();
90 return t.elapsed_sec();
91 });
92
93 m.def("get_default_impl_list_clbvh_dual_tree_traversal", []() {
95 });
96
97 m.def(
98 "set_impl_clbvh_dual_tree_traversal",
99 [](const std::string &impl, const std::string &param = "") {
101 });
102
103 m.def("get_current_impl_clbvh_dual_tree_traversal_impl", []() {
105 });
106}
107
109
110 py::module shamtree_module = root_module.def_submodule("tree", "backend library");
111
112 register_CLBVH<u64, f64_3, 3>(shamtree_module, "CLBVH_u64_f64_3");
113 register_dtt_alg<u64, f64_3, 3>(shamtree_module);
114}
Dual tree traversal algorithm for Compressed Leaf Bounding Volume Hierarchies.
DTTResult clbvh_dual_tree_traversal(sham::DeviceScheduler_ptr dev_sched, const CompressedLeafBVH< Tmorton, Tvec, dim > &bvh, shambase::VecComponent< Tvec > theta_crit, bool ordered_result=false, bool allow_leaf_lowering=false)
Perform dual tree traversal on a compressed leaf bounding volume hierarchy.
Header file describing a Node Instance.
std::uint32_t u32
32 bit unsigned integer
A buffer allocated in USM (Unified Shared Memory).
Class Timer measures the time elapsed since the timer was started.
Definition Timer.hpp:36
f64 elapsed_sec() const
Converts the stored nanosecond time to a floating point representation in seconds.
Definition Timer.hpp:88
void start()
Starts the timer.
Definition Timer.hpp:51
void stop()
Stops the timer and stores the elapsed time in nanoseconds.
Definition Timer.hpp:65
A Compressed Leaf Bounding Volume Hierarchy (CLBVH) for neighborhood queries.
void set_impl_clbvh_dual_tree_traversal(const std::string &impl, const std::string &param="")
Set the implementation for dual tree traversal.
shamalgs::impl_param get_current_impl_clbvh_dual_tree_traversal_impl()
Get the current implementation for dual tree traversal.
std::vector< shamalgs::impl_param > get_default_impl_list_clbvh_dual_tree_traversal()
Get list of available dual tree traversal implementations.
Pybind11 include and definitions.
#define ON_PYTHON_INIT
Register a Python module init function using static initialization.
void debug_ln(std::string module_name, Types... var2)
Prints a log message with multiple arguments followed by a newline.
Definition logs.hpp:133
Axis-Aligned bounding box.
Definition AABB.hpp:99
Result structure for dual tree traversal operations.