Skip to content
Snippets Groups Projects
Commit cdac5604 authored by Armin Damon Riess's avatar Armin Damon Riess
Browse files

use std::list for local particle indices

parent 53899b9b
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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:
......
......@@ -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_);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment