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
15
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 {.impl_name = "reference", .params = ""};
43 } else if (impl == DTTImpl::PARALLEL_SELECT) {
44 return {.impl_name = "parallel_select", .params = ""};
45 } else if (impl == DTTImpl::SCAN_MULTIPASS) {
46 return {.impl_name = "scan_multipass", .params = ""};
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 {.impl_name = "reference", .params = ""},
55 {.impl_name = "parallel_select", .params = ""},
56 {.impl_name = "scan_multipass", .params = ""}};
57 return impl_list;
58 }
59
61 const std::string &impl, const std::string &param) {
62 shamlog_info_ln("tree", "setting dtt implementation to impl :", impl);
63 dtt_impl = dtt_impl_from_params(impl);
64 }
65
67 return dtt_impl_to_params(dtt_impl);
68 }
69
70 template<class Tmorton, class Tvec, u32 dim>
72 sham::DeviceScheduler_ptr dev_sched,
74 shambase::VecComponent<Tvec> theta_crit,
75 bool ordered_result,
76 bool allow_leaf_lowering) {
77
78 if (bvh.is_empty()) {
80 "BVH is empty, cannot perform DTT");
81 }
82
86
87 bool ord = ordered_result;
88 bool llow = allow_leaf_lowering;
89
90 switch (dtt_impl) {
91 case DTTImpl::REFERENCE : return ImplRef::dtt(dev_sched, bvh, theta_crit, ord, llow);
92 case DTTImpl::PARALLEL_SELECT: return ImplPar::dtt(dev_sched, bvh, theta_crit, ord, llow);
93 case DTTImpl::SCAN_MULTIPASS : return ImplSca::dtt(dev_sched, bvh, theta_crit, ord, llow);
95 }
96 }
97
98 template DTTResult clbvh_dual_tree_traversal<u64, f64_3, 3>(
99 sham::DeviceScheduler_ptr dev_sched,
100 const CompressedLeafBVH<u64, f64_3, 3> &bvh,
101 shambase::VecComponent<f64_3> theta_crit,
102 bool ordered_result,
103 bool allow_leaf_lowering);
104
105 template DTTResult clbvh_dual_tree_traversal<u32, f64_3, 3>(
106 sham::DeviceScheduler_ptr dev_sched,
107 const CompressedLeafBVH<u32, f64_3, 3> &bvh,
108 shambase::VecComponent<f64_3> theta_crit,
109 bool ordered_result,
110 bool allow_leaf_lowering);
111
112} // 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.
ExcptTypes make_except_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Create an exception with a message and a location.
void throw_unimplemented(SourceLocation loc=SourceLocation{})
Throw a std::runtime_error saying that the function is unimplemented.
namespace to control implementation behavior
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.