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
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 sham::DeviceBuffer<u32_2>(0, shamsys::instance::get_compute_scheduler_ptr()),
66 sham::DeviceBuffer<u32_2>(0, shamsys::instance::get_compute_scheduler_ptr())});
67 }));
68
69 m.def(
70 "clbvh_dual_tree_traversal",
72 shambase::VecComponent<Tvec> theta_crit,
73 bool ordered_result) {
75 shamsys::instance::get_compute_scheduler_ptr(), bvh, theta_crit, ordered_result);
76 });
77
78 m.def(
79 "benchmark_clbvh_dual_tree_traversal",
81 shambase::VecComponent<Tvec> theta_crit,
82 bool ordered_result) {
84 t.start();
86 shamsys::instance::get_compute_scheduler_ptr(), bvh, theta_crit, ordered_result);
87 t.end();
88 return t.elasped_sec();
89 });
90
91 m.def("get_default_impl_list_clbvh_dual_tree_traversal", []() {
93 });
94
95 m.def(
96 "set_impl_clbvh_dual_tree_traversal",
97 [](const std::string &impl, const std::string &param = "") {
99 });
100
101 m.def("get_current_impl_clbvh_dual_tree_traversal_impl", []() {
103 });
104}
105
106Register_pymod(shamtreelibinit) {
107
108 py::module shamtree_module = m.def_submodule("tree", "backend library");
109
110 register_CLBVH<u64, f64_3, 3>(shamtree_module, "CLBVH_u64_f64_3");
111 register_dtt_alg<u64, f64_3, 3>(shamtree_module);
112}
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 time.hpp:96
void end()
Stops the timer and stores the elapsed time in nanoseconds.
Definition time.hpp:111
f64 elasped_sec() const
Converts the stored nanosecond time to a floating point representation in seconds.
Definition time.hpp:123
void start()
Starts the timer.
Definition time.hpp:106
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 Register_pymod(placeholdername)
Register a python module init function using static initialisation.
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.