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};
140
141template<class Tmorton, class Tvec, u32 dim>
143
145 static constexpr u32 tree_depth_max
147
148 LeafCellIterator::acc cell_iterator;
150
159 template<class Functor1, class Functor2>
160 inline void rtree_for(
161 Functor1 &&traverse_condition_with_aabb, Functor2 &&on_found_object) const {
162
163 tree_traverser.rtree_for(
164 std::forward<Functor1>(traverse_condition_with_aabb),
165 [&](u32 node_id) { // on leaf found
166 u32 leaf_id = node_id - tree_traverser.tree_traverser.offset_leaf;
167 cell_iterator.for_each_in_leaf_cell(leaf_id, on_found_object);
168 });
169 }
170};
171
172template<class Tmorton, class Tvec, u32 dim>
177
180
182 inline acc get_read_access(sham::EventList &deps) const {
183 return acc{
184 tree_traverser.get_read_access(deps),
185 aabb_min.get_read_access(deps),
186 aabb_max.get_read_access(deps)};
187 }
188
190 inline void complete_event_state(sycl::event e) const {
191 tree_traverser.complete_event_state(e);
192 aabb_min.complete_event_state(e);
193 aabb_max.complete_event_state(e);
194 }
195};
196
197template<class Tmorton, class Tvec, u32 dim>
200 std::vector<Tvec> aabb_min;
201 std::vector<Tvec> aabb_max;
202
205
207 inline acc get_read_access() const {
208 return acc{tree_traverser.get_read_access(), aabb_min.data(), aabb_max.data()};
209 }
210};
211
212template<class Tmorton, class Tvec, u32 dim>
216
219
221 inline acc get_read_access(sham::EventList &deps) const {
222 return acc{cell_iterator.get_read_access(deps), tree_traverser.get_read_access(deps)};
223 }
224
226 inline void complete_event_state(sycl::event e) const {
227 cell_iterator.complete_event_state(e);
228 tree_traverser.complete_event_state(e);
229 }
230};
231
232template<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:31
Morton curve implementation.
Axis-Aligned bounding box.
Definition AABB.hpp:99
Accessed version of CLBVHObjectIterator.
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.
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