-
Notifications
You must be signed in to change notification settings - Fork 2
/
dgt_tree.hpp
74 lines (64 loc) · 1.95 KB
/
dgt_tree.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#pragma once
#include "mpicpp.hpp"
#include "p3a_grid3.hpp"
#include "dgt_block.hpp"
#include "dgt_defines.hpp"
#include "dgt_point.hpp"
namespace dgt {
class Node {
private:
friend class Tree;
private:
Point m_pt = {0, {0,0,0}};
Node* m_parent = nullptr;
std::unique_ptr<Node> m_child[2][2][2] = {{{nullptr}}};
public:
Block block;
public:
Node() = default;
Node(Node const& other) = delete;
Node operator=(Node const& other) = delete;
Node(Node&& other) = default;
Node& operator=(Node&& other) = default;
[[nodiscard]] Point pt() const;
[[nodiscard]] Node* parent();
[[nodiscard]] Node const* parent() const;
[[nodiscard]] Node* child(p3a::vector3<int> const& local);
[[nodiscard]] Node const* child(p3a::vector3<int> const& local) const;
[[nodiscard]] bool is_leaf() const;
void add_child(p3a::vector3<int> const& local);
void rm_child(p3a::vector3<int> const& local);
private:
Node(Node* parent, p3a::vector3<int> const& local);
void create(int dim, Point const& base);
void insert(int dim, Point const& pt);
};
class Tree {
private:
int m_dim = 0;
Point m_base_pt = {0, {0,0,0}};
std::unique_ptr<Node> m_root;
public:
Tree();
Tree(Tree const& other) = delete;
Tree operator=(Tree const& other) = delete;
Tree(Tree&& other) = default;
Tree& operator=(Tree&& other) = default;
[[nodiscard]] int dim() const;
[[nodiscard]] Point base() const;
[[nodiscard]] Node* root();
[[nodiscard]] Node const* root() const;
[[nodiscard]] Node* find(Point const& pt);
void set_dim(int dim);
void set_base(Point const& pt);
void insert(Point const& pt);
void init(p3a::grid3 const& base);
};
std::vector<Node*> collect_leaves(Tree& tree);
void partition_leaves(
mpicpp::comm* comm,
std::vector<Node*> const& leaves);
std::vector<Node*> collect_owned_leaves(
mpicpp::comm* comm,
std::vector<Node*> const& leaves);
}