Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
PatchTree.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
20#include <nlohmann/json.hpp>
21#include <unordered_set>
22
23namespace shamrock::scheduler {
24
29 class PatchTree {
30 public:
31 using Patch = patch::Patch;
33
37 std::unordered_set<u64> roots_id;
38
43 std::unordered_map<u64, Node> tree;
44
49 std::unordered_set<u64> leaf_key;
50
55 std::unordered_set<u64> parent_of_only_leaf_key;
56
62 void split_node(u64 id);
63
69 void merge_node_dm1(u64 idparent);
70
77 [[deprecated]] void build_from_patchtable(std::vector<Patch> &plist, u64 max_val_1axis);
78
86 std::vector<Patch> &plist, const std::unordered_map<u64, u64> &id_patch_to_global_idx);
87
95 std::vector<Patch> &plist, const std::unordered_map<u64, u64> &id_patch_to_global_idx);
96
103 std::unordered_set<u64> get_split_request(u64 crit_load_split);
104
111 std::unordered_set<u64> get_merge_request(u64 crit_load_merge);
112
113 void insert_root_node(u32 patch_id, patch::PatchCoord<3> coords);
114
115 nlohmann::json serialize_patch_metadata() const;
116
117 void load_json(const nlohmann::json &j);
118
119 private:
120 u64 next_id = 0;
121
122 u64 insert_node(Node n);
123 void remove_node(u64 id);
124
125 void update_ptnode(
126 Node &n,
127 std::vector<Patch> &plist,
128 const std::unordered_map<u64, u64> &id_patch_to_global_idx);
129 };
130
131 void to_json(nlohmann::json &j, const PatchTree &p);
132
133 void from_json(const nlohmann::json &j, PatchTree &p);
134
135} // namespace shamrock::scheduler
Header file for the patch struct and related function.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
Node information in the patchtree + held patch info.
Patch Tree : Tree structure organisation for an abstract list of patches Nb : this tree is compatible...
Definition PatchTree.hpp:29
void load_json(const nlohmann::json &j)
Load the metadata of the patch tree from a JSON object.
std::unordered_set< u64 > roots_id
set of root nodes ids
Definition PatchTree.hpp:37
std::unordered_set< u64 > leaf_key
key of leaf nodes in tree
Definition PatchTree.hpp:49
std::unordered_set< u64 > get_merge_request(u64 crit_load_merge)
Get list of nodes id to merge.
void build_from_patchtable(std::vector< Patch > &plist, u64 max_val_1axis)
make tree from a patch table
nlohmann::json serialize_patch_metadata() const
Serialize the metadata of the patch tree.
std::unordered_set< u64 > get_split_request(u64 crit_load_split)
Get list of nodes id to split.
void update_values_node(std::vector< Patch > &plist, const std::unordered_map< u64, u64 > &id_patch_to_global_idx)
update value in nodes (tree reduction)
std::unordered_set< u64 > parent_of_only_leaf_key
key of nodes that have only leafs as child
Definition PatchTree.hpp:55
void partial_values_reduction(std::vector< Patch > &plist, const std::unordered_map< u64, u64 > &id_patch_to_global_idx)
update values in leafs and parent_of_only_leaf_key only
void merge_node_dm1(u64 idparent)
merge childs of idparent (id parent should have only leafs as childs)
Definition PatchTree.cpp:66
std::unordered_map< u64, Node > tree
store the tree using a map
Definition PatchTree.hpp:43
void split_node(u64 id)
split a leaf node
Definition PatchTree.cpp:36
Patch object that contain generic patch information.
Definition Patch.hpp:33