From 81a92aa576501649563325df434bbd0e65785596 Mon Sep 17 00:00:00 2001 From: Thomas Steinreiter Date: Thu, 17 Nov 2016 17:18:55 +0100 Subject: [PATCH] * removed dead code * added move optimizations --- .../src/datastructures/BarnesHutTree.hpp | 2 +- bhtree_mpi/src/datastructures/Body.cpp | 2 +- bhtree_mpi/src/datastructures/Box.cpp | 20 ------------------- bhtree_mpi/src/datastructures/Box.hpp | 1 - bhtree_mpi/src/datastructures/Node.cpp | 3 +++ bhtree_mpi/src/datastructures/Node.hpp | 3 ++- bhtree_mpi/src/datastructures/Tree.hpp | 2 +- 7 files changed, 8 insertions(+), 25 deletions(-) diff --git a/bhtree_mpi/src/datastructures/BarnesHutTree.hpp b/bhtree_mpi/src/datastructures/BarnesHutTree.hpp index ff5a4e6..a765067 100644 --- a/bhtree_mpi/src/datastructures/BarnesHutTree.hpp +++ b/bhtree_mpi/src/datastructures/BarnesHutTree.hpp @@ -12,7 +12,7 @@ namespace nbody { static std::vector splitBB(const Node* node); static bool splitNode(Node* current); virtual void update(); - virtual void init(const std::vector& bodies, const Box& domain); //TODO(steinret): ctor + virtual void init(const std::vector& bodies, const Box& domain); static void split(Node* current); public: BarnesHutTree(int parallelId); diff --git a/bhtree_mpi/src/datastructures/Body.cpp b/bhtree_mpi/src/datastructures/Body.cpp index ca095a6..f458d58 100644 --- a/bhtree_mpi/src/datastructures/Body.cpp +++ b/bhtree_mpi/src/datastructures/Body.cpp @@ -75,7 +75,7 @@ namespace nbody { return mass >= 0.0; } - void Body::print(int parallelId) const { //TODO(steinret): do printing via put + void Body::print(int parallelId) const { std::cout << parallelId << " " << id << " Position: " << position[0] << " " << position[1] << " " << position[2] << '\n'; std::cout << parallelId << " " << id << " Velocity: " << velocity[0] << " " << velocity[1] << " " << velocity[2] << '\n'; std::cout << parallelId << " " << id << " Acceleration: " << acceleration[0] << " " << acceleration[1] << " " << acceleration[2] << '\n'; diff --git a/bhtree_mpi/src/datastructures/Box.cpp b/bhtree_mpi/src/datastructures/Box.cpp index b3609ef..c16a257 100644 --- a/bhtree_mpi/src/datastructures/Box.cpp +++ b/bhtree_mpi/src/datastructures/Box.cpp @@ -148,26 +148,6 @@ namespace nbody { std::cout << '\n'; } - //check for box/sphere overlap - bool Box::overlapsSphere(const double* sphereCenter, double sphereRadius) const { - double dmin = 0.0; - - if (!isValid()) { - return false; - } - for (int i = 0; i < 3; i++) { - if (sphereCenter[i] < min[i]) { - double dist = sphereCenter[i] - min[i]; - - dmin += dist * dist; - } else if (sphereCenter[i] > max[i]) { - double dist = sphereCenter[i] - max[i]; - - dmin += dist * dist; - } - } - return dmin <= sphereRadius * sphereRadius; - } //distance from nearest box order to position double Box::distanceToPosition(const double* position) const { diff --git a/bhtree_mpi/src/datastructures/Box.hpp b/bhtree_mpi/src/datastructures/Box.hpp index 8a4da43..1bff6e8 100644 --- a/bhtree_mpi/src/datastructures/Box.hpp +++ b/bhtree_mpi/src/datastructures/Box.hpp @@ -20,7 +20,6 @@ namespace nbody { bool isCorrectBox() const; bool isValid() const; void printBB(int parallelId) const; - bool overlapsSphere(const double* sphereCenter, double sphereRadius) const; //TODO(steinret): double* srsly? double distanceToPosition(const double* position) const; double distanceToBox(const Box& box2) const; std::vector octreeSplit() const; diff --git a/bhtree_mpi/src/datastructures/Node.cpp b/bhtree_mpi/src/datastructures/Node.cpp index 2cf6279..f42853f 100644 --- a/bhtree_mpi/src/datastructures/Node.cpp +++ b/bhtree_mpi/src/datastructures/Node.cpp @@ -177,6 +177,9 @@ namespace nbody { void Node::setBodies(const std::vector& bodies) { this->bodies = bodies; } + void Node::setBodies(std::vector&& bodies) { + this->bodies = std::move(bodies); + } //get local bodies void Node::extractLocalBodiesTo(std::vector& result) { diff --git a/bhtree_mpi/src/datastructures/Node.hpp b/bhtree_mpi/src/datastructures/Node.hpp index 9633290..279104a 100644 --- a/bhtree_mpi/src/datastructures/Node.hpp +++ b/bhtree_mpi/src/datastructures/Node.hpp @@ -42,7 +42,8 @@ namespace nbody { virtual void print(int parallelId) const; virtual bool sufficientForBody(const Body& body) const; virtual bool sufficientForBox(const Box& box) const; - virtual void setBodies(const std::vector& bodies); //TODO(steinret): && optimization + virtual void setBodies(const std::vector& bodies); + virtual void setBodies(std::vector&& bodies); virtual void extractLocalBodiesTo(std::vector& bodies); }; } diff --git a/bhtree_mpi/src/datastructures/Tree.hpp b/bhtree_mpi/src/datastructures/Tree.hpp index d7599e4..91289f3 100644 --- a/bhtree_mpi/src/datastructures/Tree.hpp +++ b/bhtree_mpi/src/datastructures/Tree.hpp @@ -29,7 +29,7 @@ namespace nbody { virtual void setSimulation(Simulation* simulation); virtual void clean(); virtual void build(const std::vector& bodies) = 0; - virtual void build(const std::vector& bodies, const Box& domain) = 0; //TODO(steinret) dead? + virtual void build(const std::vector& bodies, const Box& domain) = 0; virtual int numberOfChildren() const = 0; virtual size_t numberOfNodes() const; virtual bool isCorrect() const; -- GitLab