chombo-discharge
CD_KDNodeImplem.H
Go to the documentation of this file.
1 /* chombo-discharge
2  * Copyright © 2022 SINTEF Energy Research.
3  * Please refer to Copyright.txt and LICENSE in the chombo-discharge root directory.
4  */
5 
12 #ifndef CD_KDNodeImplem_H
13 #define CD_KDNodeImplem_H
14 
15 // Std includes
16 #include <utility>
17 #include <type_traits>
18 
19 // Our includes
20 #include <CD_KDNode.H>
21 #include <CD_NamespaceHeader.H>
22 
23 template <class P>
24 inline KDNode<P>::KDNode() : m_left(nullptr), m_right(nullptr), m_weight(0.0)
25 {}
26 
27 template <class P>
28 inline KDNode<P>::KDNode(ParticleList& a_particles)
29  : m_left(nullptr), m_right(nullptr), m_weight(0.0), m_particles(std::move(a_particles))
30 {}
31 
32 template <class P>
34 {}
35 
36 template <class P>
37 inline const typename KDNode<P>::ParticleList&
38 KDNode<P>::getParticles() const noexcept
39 {
40  return m_particles;
41 }
42 
43 template <class P>
44 inline typename KDNode<P>::ParticleList&
46 {
47  return m_particles;
48 }
49 
50 template <class P>
51 inline const Real&
52 KDNode<P>::weight() const noexcept
53 {
54  return m_weight;
55 }
56 
57 template <class P>
58 inline Real&
60 {
61  return m_weight;
62 }
63 
64 template <class P>
65 inline bool
66 KDNode<P>::isLeafNode() const noexcept
67 {
68  return (m_left == nullptr) && (m_right == nullptr);
69 }
70 
71 template <class P>
72 inline bool
73 KDNode<P>::isInteriorNode() const noexcept
74 {
75  return !(this->isLeafNode());
76 }
77 
78 template <class P>
79 inline typename KDNode<P>::ParticleList
81 {
82  ParticleList primitives;
83 
84  this->gatherParticles(primitives);
85 
86  return primitives;
87 }
88 
89 template <class P>
90 inline void
91 KDNode<P>::gatherParticles(ParticleList& a_particles) const noexcept
92 {
93  if (this->isLeafNode()) {
94  a_particles.reserve(a_particles.size() + m_particles.size());
95  a_particles.insert(a_particles.end(), m_particles.begin(), m_particles.end());
96  }
97  else {
98  m_left->gatherParticles(a_particles);
99  m_right->gatherParticles(a_particles);
100  }
101 }
102 
103 template <class P>
104 inline typename KDNode<P>::ParticleList
106 {
107  ParticleList primitives;
108 
109  this->moveParticles(primitives);
110 
111  return primitives;
112 }
113 
114 template <class P>
115 inline void
117 {
118  if (this->isLeafNode()) {
119  a_particles.reserve(a_particles.size() + m_particles.size());
120 
121  std::move(m_particles.begin(), m_particles.end(), std::back_inserter(a_particles));
122  }
123  else {
124  m_left->moveParticles(a_particles);
125  m_right->moveParticles(a_particles);
126  }
127 }
128 
129 template <class P>
130 inline std::shared_ptr<KDNode<P>>&
132 {
133  return m_left;
134 }
135 
136 template <class P>
137 inline std::shared_ptr<KDNode<P>>&
139 {
140  return m_right;
141 }
142 
143 #include <CD_NamespaceFooter.H>
144 
145 #endif
Namespace containing various particle management utilities.
ParticleList moveParticles() noexcept
Move the particles list further down in the subtree into this vector.
Definition: CD_KDNodeImplem.H:105
const Real & weight() const noexcept
Get the node weight.
Definition: CD_KDNodeImplem.H:52
const ParticleList & getParticles() const noexcept
Get particles in this node.
Definition: CD_KDNodeImplem.H:38
KDNode()
Default constructor.
Definition: CD_KDNodeImplem.H:24
std::shared_ptr< KDNode< P > > & getRight() noexcept
Get the right node.
Definition: CD_KDNodeImplem.H:138
ParticleList gatherParticles() const noexcept
Gather particles further down in the subtree and return all particles (in the leaf nodes)
Definition: CD_KDNodeImplem.H:80
virtual ~KDNode()
Destructor. Does nothing.
Definition: CD_KDNodeImplem.H:33
std::shared_ptr< KDNode< P > > & getLeft() noexcept
Get the left node.
Definition: CD_KDNodeImplem.H:131
std::vector< P > ParticleList
List of particles. This is aliased because the KD-tree construction may require both random access an...
Definition: CD_KDNode.H:39
bool isLeafNode() const noexcept
Is leaf node or not.
Definition: CD_KDNodeImplem.H:66
bool isInteriorNode() const noexcept
Is leaf node or not.
Definition: CD_KDNodeImplem.H:73