chombo-discharge
Loading...
Searching...
No Matches
CD_KDNodeImplem.H
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2021-2026 SINTEF Energy Research
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
13#ifndef CD_KDNODEIMPLEM_H
14#define CD_KDNODEIMPLEM_H
15
16// Std includes
17#include <utility>
18#include <type_traits>
19
20// Our includes
21#include <CD_KDNode.H>
22#include <CD_NamespaceHeader.H>
23
24template <class P>
25inline KDNode<P>::KDNode() : m_left(nullptr), m_right(nullptr), m_weight(0.0)
26{}
27
28template <class P>
30 : m_left(nullptr), m_right(nullptr), m_weight(0.0), m_particles(std::move(a_particles))
31{}
32
33template <class P>
35{}
36
37template <class P>
38inline const typename KDNode<P>::ParticleList&
43
44template <class P>
45inline typename KDNode<P>::ParticleList&
50
51template <class P>
52inline const Real&
54{
55 return m_weight;
56}
57
58template <class P>
59inline Real&
61{
62 return m_weight;
63}
64
65template <class P>
66inline bool
68{
69 return (m_left == nullptr) && (m_right == nullptr);
70}
71
72template <class P>
73inline bool
75{
76 return !(this->isLeafNode());
77}
78
79template <class P>
80inline typename KDNode<P>::ParticleList
82{
84
85 this->gatherParticles(primitives);
86
87 return primitives;
88}
89
90template <class P>
91inline void
93{
94 if (this->isLeafNode()) {
95 a_particles.reserve(a_particles.size() + m_particles.size());
96 a_particles.insert(a_particles.end(), m_particles.begin(), m_particles.end());
97 }
98 else {
99 m_left->gatherParticles(a_particles);
100 m_right->gatherParticles(a_particles);
101 }
102}
103
104template <class P>
105inline typename KDNode<P>::ParticleList
107{
109
110 this->moveParticles(primitives);
111
112 return primitives;
113}
114
115template <class P>
116inline void
118{
119 if (this->isLeafNode()) {
120 a_particles.reserve(a_particles.size() + m_particles.size());
121
122 std::move(m_particles.begin(), m_particles.end(), std::back_inserter(a_particles));
123 }
124 else {
125 m_left->moveParticles(a_particles);
126 m_right->moveParticles(a_particles);
127 }
128}
129
130template <class P>
133{
134 return m_left;
135}
136
137template <class P>
140{
141 return m_right;
142}
143
144#include <CD_NamespaceFooter.H>
145
146#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:106
const Real & weight() const noexcept
Get the node weight.
Definition CD_KDNodeImplem.H:53
const ParticleList & getParticles() const noexcept
Get particles in this node.
Definition CD_KDNodeImplem.H:39
KDNode()
Default constructor.
Definition CD_KDNodeImplem.H:25
std::shared_ptr< KDNode< P > > & getRight() noexcept
Get the right node.
Definition CD_KDNodeImplem.H:139
ParticleList gatherParticles() const noexcept
Gather particles further down in the subtree and return all particles (in the leaf nodes)
Definition CD_KDNodeImplem.H:81
virtual ~KDNode()
Destructor. Does nothing.
Definition CD_KDNodeImplem.H:34
std::shared_ptr< KDNode< P > > & getLeft() noexcept
Get the left node.
Definition CD_KDNodeImplem.H:132
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:40
bool isLeafNode() const noexcept
Is leaf node or not.
Definition CD_KDNodeImplem.H:67
bool isInteriorNode() const noexcept
Is leaf node or not.
Definition CD_KDNodeImplem.H:74
Base class for a tracer particle solver. This solver can advance particles in a pre-defined velocity ...
Definition CD_TracerParticleSolver.H:38
ParticleContainer< P > m_particles
Computational particles.
Definition CD_TracerParticleSolver.H:412
TracerParticleSolver()
Default constructor.
Definition CD_TracerParticleSolverImplem.H:26