Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
SerialPatchTree.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
18
20
21template<class vec>
22void get_serial_tree(
23 u64 root_key,
24 PatchTree &ptree,
25 std::vector<shamrock::scheduler::SerialPatchNode<vec>> &result_tree,
26 std::vector<u64> &result_tree_linked_patch_id,
27 u64 &counter,
28 u32 &max_level,
30
31 PatchTree::Node ptn = ptree.tree[root_key];
32
34 PtNode n = ptn.convert(box_transform);
35
36 max_level = sycl::max((u32) ptn.tree_node.level, max_level);
37
38 u64 id_nvec = counter;
39 result_tree.push_back(n);
40 result_tree_linked_patch_id.push_back(ptn.linked_patchid);
41 counter++;
42
43 // std::cout << "id : " << counter-1 << " leaf : " << ptn.is_leaf << std::endl;
44
45 if (!ptn.is_leaf()) {
46
47 u64 old_id0 = ptn.get_child_nid(0);
48 u64 old_id1 = ptn.get_child_nid(1);
49 u64 old_id2 = ptn.get_child_nid(2);
50 u64 old_id3 = ptn.get_child_nid(3);
51 u64 old_id4 = ptn.get_child_nid(4);
52 u64 old_id5 = ptn.get_child_nid(5);
53 u64 old_id6 = ptn.get_child_nid(6);
54 u64 old_id7 = ptn.get_child_nid(7);
55
56 result_tree.at(id_nvec).childs_id[0] = counter;
57 get_serial_tree<vec>(
58 old_id0,
59 ptree,
60 result_tree,
61 result_tree_linked_patch_id,
62 counter,
63 max_level,
64 box_transform);
65
66 result_tree.at(id_nvec).childs_id[1] = counter;
67 get_serial_tree<vec>(
68 old_id1,
69 ptree,
70 result_tree,
71 result_tree_linked_patch_id,
72 counter,
73 max_level,
74 box_transform);
75
76 result_tree.at(id_nvec).childs_id[2] = counter;
77 get_serial_tree<vec>(
78 old_id2,
79 ptree,
80 result_tree,
81 result_tree_linked_patch_id,
82 counter,
83 max_level,
84 box_transform);
85
86 result_tree.at(id_nvec).childs_id[3] = counter;
87 get_serial_tree<vec>(
88 old_id3,
89 ptree,
90 result_tree,
91 result_tree_linked_patch_id,
92 counter,
93 max_level,
94 box_transform);
95
96 result_tree.at(id_nvec).childs_id[4] = counter;
97 get_serial_tree<vec>(
98 old_id4,
99 ptree,
100 result_tree,
101 result_tree_linked_patch_id,
102 counter,
103 max_level,
104 box_transform);
105
106 result_tree.at(id_nvec).childs_id[5] = counter;
107 get_serial_tree<vec>(
108 old_id5,
109 ptree,
110 result_tree,
111 result_tree_linked_patch_id,
112 counter,
113 max_level,
114 box_transform);
115
116 result_tree.at(id_nvec).childs_id[6] = counter;
117 get_serial_tree<vec>(
118 old_id6,
119 ptree,
120 result_tree,
121 result_tree_linked_patch_id,
122 counter,
123 max_level,
124 box_transform);
125
126 result_tree.at(id_nvec).childs_id[7] = counter;
127 get_serial_tree<vec>(
128 old_id7,
129 ptree,
130 result_tree,
131 result_tree_linked_patch_id,
132 counter,
133 max_level,
134 box_transform);
135 }
136}
137
138template void get_serial_tree(
139 u64 root_key,
140 PatchTree &ptree,
141 std::vector<shamrock::scheduler::SerialPatchNode<f32_3>> &result_tree,
142 std::vector<u64> &result_tree_linked_patch_id,
143 u64 &counter,
144 u32 &max_level,
146template void get_serial_tree(
147 u64 root_key,
148 PatchTree &ptree,
149 std::vector<shamrock::scheduler::SerialPatchNode<f64_3>> &result_tree,
150 std::vector<u64> &result_tree_linked_patch_id,
151 u64 &counter,
152 u32 &max_level,
154
155template void get_serial_tree(
156 u64 root_key,
157 PatchTree &ptree,
158 std::vector<shamrock::scheduler::SerialPatchNode<i64_3>> &result_tree,
159 std::vector<u64> &result_tree_linked_patch_id,
160 u64 &counter,
161 u32 &max_level,
163
164template<>
166 PatchTree &ptree, const shamrock::patch::PatchCoordTransform<f32_3> box_transform) {
167
168 u64 cnt = 0;
169 level_count = 0;
170 for (u64 root_id : ptree.roots_id) {
171 root_count++;
172 roots_ids.push_back(cnt);
173 shamlog_debug_ln("Serial Patch Tree", "get serial tree fp32 root id :", root_id);
174 get_serial_tree<f32_3>(
175 root_id, ptree, serial_tree, linked_patch_ids, cnt, level_count, box_transform);
176 }
177
178 shamlog_debug_ln("Serial Patch Tree", "tree cell count = ", serial_tree.size());
179 shamlog_debug_ln("Serial Patch Tree", "level_count =", level_count);
180}
181
182template<>
184 PatchTree &ptree, const shamrock::patch::PatchCoordTransform<f64_3> box_transform) {
185
186 u64 cnt = 0;
187 level_count = 0;
188 for (u64 root_id : ptree.roots_id) {
189 root_count++;
190 roots_ids.push_back(cnt);
191 get_serial_tree<f64_3>(
192 root_id, ptree, serial_tree, linked_patch_ids, cnt, level_count, box_transform);
193 }
194 shamlog_debug_ln("Serial Patch Tree", "tree cell count = ", serial_tree.size());
195 shamlog_debug_ln("Serial Patch Tree", "level_count =", level_count);
196}
197
198template<>
200 PatchTree &ptree, const shamrock::patch::PatchCoordTransform<i64_3> box_transform) {
201
202 u64 cnt = 0;
203 level_count = 0;
204 for (u64 root_id : ptree.roots_id) {
205 root_count++;
206 roots_ids.push_back(cnt);
207 get_serial_tree<i64_3>(
208 root_id, ptree, serial_tree, linked_patch_ids, cnt, level_count, box_transform);
209 }
210 shamlog_debug_ln("Serial Patch Tree", "tree cell count = ", serial_tree.size());
211 shamlog_debug_ln("Serial Patch Tree", "level_count =", level_count);
212}
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
u32 level
Level of the tree node.
Node information in the patchtree + held patch info.
SerialPatchNode< vec > convert(const shamrock::patch::PatchCoordTransform< vec > box_transform)
Convert PatchTreeNode to SerialPatchNode using given coordinate transform.
Patch Tree : Tree structure organisation for an abstract list of patches Nb : this tree is compatible...
Definition PatchTree.hpp:29
std::unordered_map< u64, Node > tree
store the tree using a map
Definition PatchTree.hpp:43