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
23
24namespace shamtree {
25
27 namespace impl {
28
30 struct Reference {
31 static constexpr std::string_view variant_type_name = "reference";
32 };
33
36 static constexpr std::string_view variant_type_name = "parallel_select";
37 };
38
41 static constexpr std::string_view variant_type_name = "scan_multipass";
42 };
43
45 constexpr std::string_view dtt_impl_name = "clbvh_dual_tree_traversal";
46
49 [](const sham::DeviceScheduler_ptr &, auto &self) {
50 self.set(ScanMultipass{});
51 }};
52
53 // Must come after the global it registers: same TU, so it is initialized after it
55
56 } // namespace impl
57
58 template<class Tmorton, class Tvec, u32 dim>
60 sham::DeviceScheduler_ptr dev_sched,
62 shambase::VecComponent<Tvec> theta_crit,
63 bool ordered_result,
64 bool allow_leaf_lowering) {
65
66 if (bvh.is_empty()) {
68 "BVH is empty, cannot perform DTT");
69 }
70
74
75 if (!impl::dtt_impl.is_set()) {
77 }
78
79 bool ord = ordered_result;
80 bool llow = allow_leaf_lowering;
81
82 return std::visit(
84 [&](impl::Reference) {
85 return ImplRef::dtt(dev_sched, bvh, theta_crit, ord, llow);
86 },
88 return ImplPar::dtt(dev_sched, bvh, theta_crit, ord, llow);
89 },
91 return ImplSca::dtt(dev_sched, bvh, theta_crit, ord, llow);
92 },
93 },
94 impl::dtt_impl.get());
95 }
96
97 template DTTResult clbvh_dual_tree_traversal<u64, f64_3, 3>(
98 sham::DeviceScheduler_ptr dev_sched,
99 const CompressedLeafBVH<u64, f64_3, 3> &bvh,
100 shambase::VecComponent<f64_3> theta_crit,
101 bool ordered_result,
102 bool allow_leaf_lowering);
103
104 template DTTResult clbvh_dual_tree_traversal<u32, f64_3, 3>(
105 sham::DeviceScheduler_ptr dev_sched,
106 const CompressedLeafBVH<u32, f64_3, 3> &bvh,
107 shambase::VecComponent<f64_3> theta_crit,
108 bool ordered_result,
109 bool allow_leaf_lowering);
110
111} // 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.
Generic std::variant-based implementation selector.
Drop-in replacement for the hand-rolled "global variable + enum + name mapping.
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.
Name-keyed registry of the implementation selectors (IImplVariant) of every algorithm.
#define SHAMALGS_REGISTER_IMPL(name, impl)
Register the implementation selector impl under name at static initialization.
void autoselect_impl(std::string_view alg, const sham::DeviceScheduler_ptr &sched)
Select the default implementation of alg for the device behind sched.
ExcptTypes make_except_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Create an exception with a message and a location.
namespace to control implementation behavior
shamalgs::ImplVariantGlobal< Reference, ParallelSelect, ScanMultipass > dtt_impl
Currently selected dual tree traversal implementation.
constexpr std::string_view dtt_impl_name
Registry name, shared by its registration and the dispatch site(s).
Build an overload set out of several callables, for use with std::visit.
Result structure for dual tree traversal operations.
Parallel-select implementation of the dual tree traversal.
Naive reference CPU implementation of the dual tree traversal.
Scan-multipass implementation of the dual tree traversal.