Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
CLBVHObjectIterator.hpp
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
10#pragma once
11
17
19#include "shammath/AABB.hpp"
26
27namespace shamtree {
28
30 template<class Tmorton, class Tvec, u32 dim>
32
43 template<class Tmorton, class Tvec, u32 dim>
44 struct CLBVHTraverser;
45
47 template<class Tmorton, class Tvec, u32 dim>
48 struct CLBVHTraverserHost;
49
51 template<class Tmorton, class Tvec, u32 dim>
53
64 template<class Tmorton, class Tvec, u32 dim>
66
68 template<class Tmorton, class Tvec, u32 dim>
70
71} // namespace shamtree
72
73template<class Tmorton, class Tvec, u32 dim>
75
77 static constexpr u32 tree_depth_max
79
81 const Tvec *aabb_min;
82 const Tvec *aabb_max;
83
99 template<class Functor1, class Functor2, class Functor3>
101 Functor1 &&traverse_condition,
102 Functor2 &&on_found_leaf,
103 Functor3 &&on_excluded_node) const {
104
105 tree_traverser.template stack_based_traversal<tree_depth_max>(
106 std::forward<Functor1>(traverse_condition),
107 std::forward<Functor2>(on_found_leaf),
108 std::forward<Functor3>(on_excluded_node));
109 }
110
112 template<class Functor1, class Functor2, class Functor3>
114 u32 root_node,
115 Functor1 &&traverse_condition,
116 Functor2 &&on_found_leaf,
117 Functor3 &&on_excluded_node) const {
118
119 tree_traverser.template stack_based_traversal<tree_depth_max>(
120 root_node,
121 std::forward<Functor1>(traverse_condition),
122 std::forward<Functor2>(on_found_leaf),
123 std::forward<Functor3>(on_excluded_node));
124 }
125
126 template<class Functor1, class Functor2>
127 inline void rtree_for(Functor1 &&traverse_condition_with_aabb, Functor2 &&on_found_leaf) const {
128
130 [&](u32 node_id) { // interaction crit
131 return traverse_condition_with_aabb(
132 node_id, shammath::AABB<Tvec>{aabb_min[node_id], aabb_max[node_id]});
133 },
134 [&](u32 node_id) { // on leaf found
135 on_found_leaf(node_id);
136 },
137 [&](u32) {});
138 }
139
144 template<class StackAccessor, class Functor1, class Functor2>
145 inline void rtree_for(
146 StackAccessor &&stack,
147 u32 stack_size,
148 Functor1 &&traverse_condition_with_aabb,
149 Functor2 &&on_found_leaf) const {
150
151 tree_traverser.stack_based_traversal(
152 std::forward<StackAccessor>(stack),
153 stack_size,
154 [&](u32 node_id) { // interaction crit
155 return traverse_condition_with_aabb(
156 node_id, shammath::AABB<Tvec>{aabb_min[node_id], aabb_max[node_id]});
157 },
158 [&](u32 node_id) { // on leaf found
159 on_found_leaf(node_id);
160 },
161 [&](u32) {});
162 }
163};
164
165template<class Tmorton, class Tvec, u32 dim>
167
169 static constexpr u32 tree_depth_max
171
172 LeafCellIterator::acc cell_iterator;
174
183 template<class Functor1, class Functor2>
184 inline void rtree_for(
185 Functor1 &&traverse_condition_with_aabb, Functor2 &&on_found_object) const {
186
187 tree_traverser.rtree_for(
188 std::forward<Functor1>(traverse_condition_with_aabb),
189 [&](u32 node_id) { // on leaf found
190 u32 leaf_id = node_id - tree_traverser.tree_traverser.offset_leaf;
191 cell_iterator.for_each_in_leaf_cell(leaf_id, on_found_object);
192 });
193 }
194
199 template<class StackAccessor, class Functor1, class Functor2>
200 inline void rtree_for(
201 StackAccessor &&stack,
202 u32 stack_size,
203 Functor1 &&traverse_condition_with_aabb,
204 Functor2 &&on_found_object) const {
205
206 tree_traverser.rtree_for(
207 std::forward<StackAccessor>(stack),
208 stack_size,
209 std::forward<Functor1>(traverse_condition_with_aabb),
210 [&](u32 node_id) { // on leaf found
211 u32 leaf_id = node_id - tree_traverser.tree_traverser.offset_leaf;
212 cell_iterator.for_each_in_leaf_cell(leaf_id, on_found_object);
213 });
214 }
215};
216
217template<class Tmorton, class Tvec, u32 dim>
222
225
227 inline acc get_read_access(sham::EventList &deps) const {
228 return acc{
229 tree_traverser.get_read_access(deps),
230 aabb_min.get_read_access(deps),
231 aabb_max.get_read_access(deps)};
232 }
233
235 inline void complete_event_state(sycl::event e) const {
236 tree_traverser.complete_event_state(e);
237 aabb_min.complete_event_state(e);
238 aabb_max.complete_event_state(e);
239 }
240};
241
242template<class Tmorton, class Tvec, u32 dim>
245 std::vector<Tvec> aabb_min;
246 std::vector<Tvec> aabb_max;
247
250
252 inline acc get_read_access() const {
253 return acc{tree_traverser.get_read_access(), aabb_min.data(), aabb_max.data()};
254 }
255};
256
257template<class Tmorton, class Tvec, u32 dim>
261
264
266 inline acc get_read_access(sham::EventList &deps) const {
267 return acc{cell_iterator.get_read_access(deps), tree_traverser.get_read_access(deps)};
268 }
269
271 inline void complete_event_state(sycl::event e) const {
272 cell_iterator.complete_event_state(e);
273 tree_traverser.complete_event_state(e);
274 }
275};
276
277template<class Tmorton, class Tvec, u32 dim>
std::uint32_t u32
32 bit unsigned integer
A buffer allocated in USM (Unified Shared Memory).
Class to manage a list of SYCL events.
Definition EventList.hpp:32
Morton curve implementation.
Axis-Aligned bounding box.
Definition AABB.hpp:99
Accessed version of CLBVHObjectIterator.
void rtree_for(StackAccessor &&stack, u32 stack_size, Functor1 &&traverse_condition_with_aabb, Functor2 &&on_found_object) const
static constexpr u32 tree_depth_max
maximum depth of the tree according to the morton codes
CLBVHTraverserAccessed< Tmorton, Tvec, dim > tree_traverser
Tree traverser.
LeafCellIterator::acc cell_iterator
Cell iterator.
void rtree_for(Functor1 &&traverse_condition_with_aabb, Functor2 &&on_found_object) const
Traverses the tree and executes a function for each found object.
host version of the object iterator
LeafCellIteratorHost cell_iterator
Cell iterator.
CLBVHTraverserHost< Tmorton, Tvec, dim > tree_traverser
Tree traverser.
acc get_read_access() const
get read only accessor
CLBVHObjectIteratorAccessed< Tmorton, Tvec, dim > acc
shorthand for CLBVHObjectIteratorAccessed
This class is designed to traverse a BVH tree represented as a Compressed Leaf BVH (CLBVH) and a Karr...
acc get_read_access(sham::EventList &deps) const
get read only accessor
void complete_event_state(sycl::event e) const
complete the buffer states with the resulting event
CLBVHTraverser< Tmorton, Tvec, dim > tree_traverser
Tree traverser.
CLBVHObjectIteratorAccessed< Tmorton, Tvec, dim > acc
shorthand for CLBVHObjectIteratorAccessed
LeafCellIterator cell_iterator
Cell iterator.
Accessed version of CLBVHTraverser.
static constexpr u32 tree_depth_max
maximum depth of the tree according to the morton codes
void traverse_tree_base(Functor1 &&traverse_condition, Functor2 &&on_found_leaf, Functor3 &&on_excluded_node) const
Traverses the tree by calling tree_traverser's stack_based_traversal.
const Tvec * aabb_min
Minimum of the AABB.
void traverse_tree_base(u32 root_node, Functor1 &&traverse_condition, Functor2 &&on_found_leaf, Functor3 &&on_excluded_node) const
version with root node
KarrasTreeTraverserAccessed tree_traverser
Tree traverser.
const Tvec * aabb_max
Maximum of the AABB.
void rtree_for(StackAccessor &&stack, u32 stack_size, Functor1 &&traverse_condition_with_aabb, Functor2 &&on_found_leaf) const
host version of the traverser
std::vector< Tvec > aabb_min
Minimum of the AABB.
KarrasTreeTraverserHost tree_traverser
Tree traverser.
std::vector< Tvec > aabb_max
Maximum of the AABB.
acc get_read_access() const
get read only accessor
CLBVHTraverserAccessed< Tmorton, Tvec, dim > acc
shorthand for CLBVHObjectIteratorAccessed
This class is designed to traverse a BVH tree represented as a Compressed Leaf BVH (CLBVH) and a Karr...
CLBVHTraverserAccessed< Tmorton, Tvec, dim > acc
shorthand for CLBVHObjectIteratorAccessed
acc get_read_access(sham::EventList &deps) const
get read only accessor
const sham::DeviceBuffer< Tvec > & aabb_max
Maximum of the AABB.
void complete_event_state(sycl::event e) const
complete the buffer states with the resulting event
KarrasTreeTraverser tree_traverser
Tree traverser.
const sham::DeviceBuffer< Tvec > & aabb_min
Minimum of the AABB.
Utility struct to traverse a Karras Radix Tree.
host version of the cell iterator