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
19#include "shammath/AABB.hpp"
26
27namespace shamtree {
28
30 template<class Tmorton, class Tvec, u32 dim>
31 struct CLBVHTraverserAccessed;
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>
52 struct CLBVHObjectIteratorAccessed;
53
64 template<class Tmorton, class Tvec, u32 dim>
65 struct CLBVHObjectIterator;
66
68 template<class Tmorton, class Tvec, u32 dim>
69 struct CLBVHObjectIteratorHost;
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
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>
196
197template<class Tmorton, class Tvec, u32 dim>
211
212template<class Tmorton, class Tvec, u32 dim>
231
232template<class Tmorton, class Tvec, u32 dim>
std::uint32_t u32
32 bit unsigned integer
A buffer allocated in USM (Unified Shared Memory)
void complete_event_state(sycl::event e) const
Complete the event state of the buffer.
const T * get_read_access(sham::EventList &depends_list, SourceLocation src_loc=SourceLocation{}) const
Get a read-only pointer to the buffer's data.
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
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.
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
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
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.
KarrasTreeTraverserAccessed get_read_access() const
get read only accessor
Utility struct to traverse a Karras Radix Tree.
KarrasTreeTraverserAccessed 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
void for_each_in_leaf_cell(const u32 &cell_id, Functor_iter &&func_it) const
Iterate over all particles in a given cell.
host version of the cell iterator
acc get_read_access() const
get read only accessor
void complete_event_state(sycl::event e) const
Completes the event state for the associated buffers.
acc get_read_access(sham::EventList &deps) const
Get a read-only access to the buffers.