Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
CLBVHDualTreeTraversal.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
20
21namespace shamtree {
22
23 enum class DTTImpl : u32 { REFERENCE, PARALLEL_SELECT, SCAN_MULTIPASS };
24 DTTImpl dtt_impl = DTTImpl::SCAN_MULTIPASS;
25
26 inline DTTImpl dtt_impl_from_params(const std::string &impl) {
27 if (impl == "reference") {
28 return DTTImpl::REFERENCE;
29 } else if (impl == "parallel_select") {
30 return DTTImpl::PARALLEL_SELECT;
31 } else if (impl == "scan_multipass") {
32 return DTTImpl::SCAN_MULTIPASS;
33 }
35 "invalid implementation : {}, possible implementations : {}",
36 impl,
38 }
39
40 inline shamalgs::impl_param dtt_impl_to_params(const DTTImpl &impl) {
41 if (impl == DTTImpl::REFERENCE) {
42 return {"reference", ""};
43 } else if (impl == DTTImpl::PARALLEL_SELECT) {
44 return {"parallel_select", ""};
45 } else if (impl == DTTImpl::SCAN_MULTIPASS) {
46 return {"scan_multipass", ""};
47 }
49 shambase::format("unknown dtt implementation : {}", u32(impl)));
50 }
51
52 std::vector<shamalgs::impl_param> impl::get_default_impl_list_clbvh_dual_tree_traversal() {
53 std::vector<shamalgs::impl_param> impl_list{
54 {"reference", ""}, {"parallel_select", ""}, {"scan_multipass", ""}};
55 return impl_list;
56 }
57
59 const std::string &impl, const std::string &param) {
60 shamlog_info_ln("tree", "setting dtt implementation to impl :", impl);
61 dtt_impl = dtt_impl_from_params(impl);
62 }
63
65 return dtt_impl_to_params(dtt_impl);
66 }
67
68 template<class Tmorton, class Tvec, u32 dim>
70 sham::DeviceScheduler_ptr dev_sched,
72 shambase::VecComponent<Tvec> theta_crit,
73 bool ordered_result,
74 bool allow_leaf_lowering) {
75
76 if (bvh.is_empty()) {
78 "BVH is empty, cannot perform DTT");
79 }
80
84
85 bool ord = ordered_result;
86 bool llow = allow_leaf_lowering;
87
88 switch (dtt_impl) {
89 case DTTImpl::REFERENCE : return ImplRef::dtt(dev_sched, bvh, theta_crit, ord, llow);
90 case DTTImpl::PARALLEL_SELECT: return ImplPar::dtt(dev_sched, bvh, theta_crit, ord, llow);
91 case DTTImpl::SCAN_MULTIPASS : return ImplSca::dtt(dev_sched, bvh, theta_crit, ord, llow);
93 }
94 }
95
96 template DTTResult clbvh_dual_tree_traversal<u64, f64_3, 3>(
97 sham::DeviceScheduler_ptr dev_sched,
98 const CompressedLeafBVH<u64, f64_3, 3> &bvh,
99 shambase::VecComponent<f64_3> theta_crit,
100 bool ordered_result,
101 bool allow_leaf_lowering);
102
103 template DTTResult clbvh_dual_tree_traversal<u32, f64_3, 3>(
104 sham::DeviceScheduler_ptr dev_sched,
105 const CompressedLeafBVH<u32, f64_3, 3> &bvh,
106 shambase::VecComponent<f64_3> theta_crit,
107 bool ordered_result,
108 bool allow_leaf_lowering);
109
110} // namespace shamtree
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.
std::uint32_t u32
32 bit unsigned integer
A Compressed Leaf Bounding Volume Hierarchy (CLBVH) for neighborhood queries.
bool is_empty() const
is the BVH empty ?
This header file contains utility functions related to exception handling in the code.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
void throw_unimplemented(SourceLocation loc=SourceLocation{})
Throw a std::runtime_error saying that the function is unimplemented.
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.
Result structure for dual tree traversal operations.