From f27ebfacd2e1b214dc71312fbaf31e6a840b9444 Mon Sep 17 00:00:00 2001 From: "armindamon.riess" <armindamon.riess@uzh.ch> Date: Wed, 7 Dec 2022 18:21:34 +0100 Subject: [PATCH] pass size of index vector in update, removed TODOs --- lib/node.cpp | 17 +++++------------ lib/node.hpp | 2 +- lib/tree.cpp | 2 +- lib/tree.hpp | 1 + 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/lib/node.cpp b/lib/node.cpp index e718ec4..108d063 100644 --- a/lib/node.cpp +++ b/lib/node.cpp @@ -37,10 +37,6 @@ Node::Node(Node* root, Node* parent, double* masses, double* particles, unsigned mass_ += masses_[localParticles_[i]]; } - // TODO - // allocate children - // check if child contains no particles, in that case set child to nullptr - // check if node is leaf (it contains a single particle), in that case all children are nullptr if (nLocalParticles <= 1) { isLeaf_ = true; for (unsigned i=0; i<8; ++i) @@ -93,13 +89,10 @@ Node& Node::operator=(const Node& other) { return *this; } -void Node::update(List& localParticles) { - // TODO - // update center of mass - // maybe subdivide? - // update this node - // update children - +void Node::update(List& localParticles, unsigned nLocalParticles) { + calculateCenterOfMass(); + localParticles_ = localParticles; + nLocalParticles_ = nLocalParticles; // for each local particle, determine which octant it is in List* particleDivision = new List[nLocalParticles_]; for (unsigned i=0; i<nLocalParticles_; ++i) { @@ -115,7 +108,7 @@ void Node::update(List& localParticles) { delete children_[i]; children_[i] = nullptr; } else { - children_[i]->update(particleDivision[i]); + children_[i]->update(particleDivision[i], particleDivision[i].size()); isLeaf_ = false; } } else { diff --git a/lib/node.hpp b/lib/node.hpp index d8c900d..661bd70 100644 --- a/lib/node.hpp +++ b/lib/node.hpp @@ -19,7 +19,7 @@ public: // Copy assignment Node& operator=(const Node&); // Update tree: visit each node, check if it needs to be split or merged (for example if a particle has left the region) - void update(List& allParticles); + void update(List& particles, unsigned nParticles); // Calculate force on a particle recursively double* calculateForce(unsigned particle); // Calculate center of mass diff --git a/lib/tree.cpp b/lib/tree.cpp index 7ff2bce..eb27fa8 100644 --- a/lib/tree.cpp +++ b/lib/tree.cpp @@ -32,5 +32,5 @@ void Tree::calculateForce(unsigned particle) { } void Tree::update() { - root_->update(allParticles_); + root_->update(allParticles_, nParticles_); } \ No newline at end of file diff --git a/lib/tree.hpp b/lib/tree.hpp index bdab71c..e95ed36 100644 --- a/lib/tree.hpp +++ b/lib/tree.hpp @@ -28,6 +28,7 @@ private: double size_; double center_[3]; + // allParticles contains all indices, so [0, 1, 2, ..., nParticles_-1]. It should never be changed. std::vector<unsigned> allParticles_; }; -- GitLab