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

minor changes to update function

parent f19bbcfa
No related branches found
No related tags found
No related merge requests found
...@@ -19,7 +19,7 @@ Node::Node() { ...@@ -19,7 +19,7 @@ Node::Node() {
*/ */
Node::Node(Node* root, Node* parent, double* masses, double* particles, unsigned nParticles, unsigned depth, Node::Node(Node* root, Node* parent, double* masses, double* particles, unsigned nParticles, unsigned depth,
double size, double center[3], std::vector<unsigned> localParticles, unsigned nLocalParticles) { double size, double center[3], std::vector<unsigned>& localParticles, unsigned nLocalParticles) {
parent_ = parent; parent_ = parent;
particles_ = particles; particles_ = particles;
nParticles_ = nParticles; nParticles_ = nParticles;
...@@ -37,9 +37,10 @@ Node::Node(Node* root, Node* parent, double* masses, double* particles, unsigned ...@@ -37,9 +37,10 @@ Node::Node(Node* root, Node* parent, double* masses, double* particles, unsigned
mass_ += masses_[localParticles_[i]]; mass_ += masses_[localParticles_[i]];
} }
// TODO
// allocate children // allocate children
// check if child contains no particles, in that case set child to nullptr // check if child contains no particles, in that case set child to nullptr
// TODO // check if node is leaf
} }
Node::~Node() { Node::~Node() {
...@@ -63,12 +64,18 @@ Node& Node::operator=(const Node& other) { ...@@ -63,12 +64,18 @@ Node& Node::operator=(const Node& other) {
return *this; return *this;
} }
void Node::update() { void Node::update(std::vector<unsigned>& localParticles) {
// update this node
// TODO // TODO
// update center of mass
// maybe subdivide?
// update this node
// update children // update children
isLeaf_ = true;
for (unsigned i=0; i<8; ++i) { for (unsigned i=0; i<8; ++i) {
if (children_[i] != nullptr) children_[i]->update(); if (children_[i] != nullptr) {
// children_[i]->update();
isLeaf_ = false;
}
} }
} }
...@@ -81,10 +88,18 @@ double* Node::calculateForce(unsigned particle) { ...@@ -81,10 +88,18 @@ double* Node::calculateForce(unsigned particle) {
+ (center_[1] - py)*(center_[1] - py) + (center_[1] - py)*(center_[1] - py)
+ (center_[2] - pz)*(center_[2] - pz)); + (center_[2] - pz)*(center_[2] - pz));
double theta = size_/lambda; double theta = size_/lambda;
// if angle too large, call this function for every child. If a child is a nullptr, calculate force on particle from particles in this node
// else calculate force on particle from particles in this node // TODO
// If angle too large, call this function for every child which is not a nullptr.
// If the node is a leaf, calculate force on particle from particles in this node.
// If the node is not a leaf, call this function for every child which is not a nullptr.
// If angle small enough, calculate force on particle from this node.
if (theta > theta0_) { if (theta > theta0_) {
// TODO if (isLeaf_) {
// TODO
} else {
// TODO
}
} else { } else {
// TODO // TODO
} }
......
...@@ -10,7 +10,7 @@ public: ...@@ -10,7 +10,7 @@ public:
// whoever creates the node is responsible for deciding which particles are in which octant and for allocating the localParticles array // whoever creates the node is responsible for deciding which particles are in which octant and for allocating the localParticles array
// node will write to localParticles array // node will write to localParticles array
Node(Node* root, Node* parent, double* masses, double* particles, unsigned nParticles, unsigned depth, Node(Node* root, Node* parent, double* masses, double* particles, unsigned nParticles, unsigned depth,
double size, double center[3], std::vector<unsigned> localParticles, unsigned nLocalParticles); double size, double center[3], std::vector<unsigned>& localParticles, unsigned nLocalParticles);
// destuctor // destuctor
~Node(); ~Node();
// copy constructor // copy constructor
...@@ -18,7 +18,7 @@ public: ...@@ -18,7 +18,7 @@ public:
// copy assignment // copy assignment
Node& operator=(const Node&); 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) // 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(); void update(std::vector<unsigned>& allParticles);
// calculate force on a particle recursively // calculate force on a particle recursively
double* calculateForce(unsigned particle); double* calculateForce(unsigned particle);
private: private:
...@@ -35,6 +35,7 @@ private: ...@@ -35,6 +35,7 @@ private:
unsigned nLocalParticles_; unsigned nLocalParticles_;
double mass_; double mass_;
const double theta0_ = 0.4; const double theta0_ = 0.4;
bool isLeaf_;
}; };
#endif /* NODE_HPP */ #endif /* NODE_HPP */
\ No newline at end of file
...@@ -17,6 +17,9 @@ Tree::Tree(double* masses, double* particles, double* forces, unsigned nParticle ...@@ -17,6 +17,9 @@ Tree::Tree(double* masses, double* particles, double* forces, unsigned nParticle
root_ = new Node(); root_ = new Node();
*root_ = Node(root_, root_, masses_, particles_, nParticles_, 0, *root_ = Node(root_, root_, masses_, particles_, nParticles_, 0,
size_, center_, localParticles_, nParticles_); size_, center_, localParticles_, nParticles_);
allParticles_ = std::vector<unsigned>(nParticles_);
for (unsigned i=0; i < nParticles_; ++i) allParticles_[i] = i;
} }
Tree::~Tree() { Tree::~Tree() {
...@@ -29,5 +32,5 @@ void Tree::calculateForce(unsigned particle) { ...@@ -29,5 +32,5 @@ void Tree::calculateForce(unsigned particle) {
} }
void Tree::update() { void Tree::update() {
root_->update(); root_->update(allParticles_);
} }
\ No newline at end of file
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
#include "node.hpp" #include "node.hpp"
#include <vector>
class Tree { class Tree {
public: public:
// constructor // constructor
...@@ -22,6 +24,7 @@ private: ...@@ -22,6 +24,7 @@ private:
unsigned nParticles_; unsigned nParticles_;
double size_; double size_;
double center_[3]; double center_[3];
std::vector<unsigned> allParticles_;
}; };
#endif /* TREE_HPP */ #endif /* TREE_HPP */
\ No newline at end of file
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