From cdac5604527f3dc676106a84bf8b37d3efce7742 Mon Sep 17 00:00:00 2001 From: "armindamon.riess" <armindamon.riess@uzh.ch> Date: Wed, 14 Dec 2022 14:59:33 +0100 Subject: [PATCH] use std::list for local particle indices --- lib/node.cpp | 4 ++-- lib/node.hpp | 3 ++- lib/tree.cpp | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/node.cpp b/lib/node.cpp index 5f75e6e..ce11458 100644 --- a/lib/node.cpp +++ b/lib/node.cpp @@ -48,7 +48,7 @@ void Node::update(List localParticles, unsigned nLocalParticles) { // for each local particle, determine which octant it is in // get the mass in this node while we're at it for (unsigned i=0; i<8; ++i) { - childParticles_[i] = List{}; + childParticles_[i] = {}; } for (unsigned i : localParticles) { childParticles_[getOctant(i)].push_back(i); @@ -169,7 +169,7 @@ Vector Node::multipole(Vector y, double ynorm) const { double qij = 0; // go through every local particle for (unsigned c=0; c<8; ++c) { - for (auto k : childParticles_[c]) { + for (unsigned k : childParticles_[c]) { // calculate using the formula from page 17 of the pdf for lecture 7 qij += 3*(centerOfMass_[i] - positions_[3*k+i])*(centerOfMass_[j] - positions_[3*k+j]); if (i!=j) continue; diff --git a/lib/node.hpp b/lib/node.hpp index 1b4e732..0102ac4 100644 --- a/lib/node.hpp +++ b/lib/node.hpp @@ -2,11 +2,12 @@ #define NODE_HPP #include <vector> +#include <list> #include <fstream> using Vector = std::vector<double>; using Matrix = std::vector<Vector>; -using List = std::vector<unsigned>; +using List = std::list<unsigned>; class Node { public: diff --git a/lib/tree.cpp b/lib/tree.cpp index c9b84e0..5b6ef26 100644 --- a/lib/tree.cpp +++ b/lib/tree.cpp @@ -14,8 +14,8 @@ Tree::Tree(double mass, double* positions, double* forces, double softening, uns center_ = Vector(3); for (unsigned i=0; i < 3; ++i) center_[i] = center[i]; - allParticles_ = List(nParticles_); - for (unsigned i=0; i < nParticles_; ++i) allParticles_[i] = i; + allParticles_ = {}; + for (unsigned i=0; i < nParticles_; ++i) allParticles_.push_back(i); root_ = new Node(mass_, positions_, nParticles_, softening_, 0, size_, center_, allParticles_, nParticles_); } -- GitLab