Skip to content
Snippets Groups Projects
Commit efe9ae0c authored by Paul Heinzlreiter's avatar Paul Heinzlreiter
Browse files

* added example data and body weight

parent b23a6c37
Branches
No related merge requests found
This diff is collapsed.
......@@ -37,7 +37,20 @@ namespace nbody {
this->nodes.front()->extendBBtoCube();
it = this->nodes.begin();
while (it != this->nodes.end()) {
(*it)->afterSubtree = it;
(*it)->afterSubtree++;
if ((*it)->isSplitable()) {
vector<Box> subboxes = this->splitBB(*it);
for (vector<Box>::iterator bit = subboxes.begin(); bit != subboxes.end(); bit++) {
TreeNode* current = new TreeNode();
current->bb = *bit;
current->bodies = bit->containedBodies((*it)->getBodies());
this->nodes.insert((*it)->afterSubtree, current);
}
(*it)->bodies.clear();
}
it++;
}
}
......
......@@ -24,6 +24,7 @@ namespace nbody {
this->velocity[i] = 0.0;
this->acceleration[i] = 0.0;
}
this->weight = 1.0;
}
Body::Body(double positionX, double positionY, double positionZ) {
......@@ -34,6 +35,7 @@ namespace nbody {
this->position[0] = positionX;
this->position[1] = positionY;
this->position[2] = positionZ;
this->weight = 1.0;
}
Body::Body(double positionX, double positionY, double positionZ, double velocityX, double velocityY, double velocityZ) {
......@@ -46,6 +48,31 @@ namespace nbody {
this->velocity[0] = velocityX;
this->velocity[1] = velocityY;
this->velocity[2] = velocityZ;
this->weight = 1.0;
}
Body::Body(double positionX, double positionY, double positionZ, double weight) {
for (int i = 0; i < 3; i++) {
this->velocity[i] = 0.0;
this->acceleration[i] = 0.0;
}
this->position[0] = positionX;
this->position[1] = positionY;
this->position[2] = positionZ;
this->weight = weight;
}
Body::Body(double positionX, double positionY, double positionZ, double velocityX, double velocityY, double velocityZ, double weight) {
for (int i = 0; i < 3; i++) {
this->acceleration[i] = 0.0;
}
this->position[0] = positionX;
this->position[1] = positionY;
this->position[2] = positionZ;
this->velocity[0] = velocityX;
this->velocity[1] = velocityY;
this->velocity[2] = velocityZ;
this->weight = weight;
}
Body::~Body() {
......
......@@ -10,12 +10,15 @@ namespace nbody {
double position[3];
double velocity[3];
double acceleration[3];
double weight;
Derivative evaluate(double dt, Derivative d);
public:
Body();
Body(double positionX, double positionY, double positionZ);
Body(double positionX, double positionY, double positionZ, double velocityX, double velocityY, double velocityZ);
Body(double positionX, double positionY, double positionZ, double weight);
Body(double positionX, double positionY, double positionZ, double velocityX, double velocityY, double velocityZ, double weight);
virtual ~Body();
virtual double getPosition(int index);
virtual void integrate();
......
......@@ -21,6 +21,9 @@ namespace nbody {
}
bool TreeNode::isSplitable() {
if (this->bodies.size() < 2) {
return false;
}
for (int i = 0; i < 3; i++) {
if (this->bb.max[i] - this->bb.min[i] < FLT_MIN) {
return false;
......@@ -50,4 +53,8 @@ namespace nbody {
void TreeNode::extendBBtoCube() {
this->bb.extendToCube();
}
vector<Body> TreeNode::getBodies() {
return this->bodies;
}
}
......@@ -10,10 +10,12 @@ namespace nbody {
using namespace std;
class TreeNode {
friend class Tree;
friend class BarnesHutTree;
protected:
Box bb;
vector<Body> bodies;
TreeNode* afterMySubtree;
vector<TreeNode*>::iterator afterSubtree;
public:
TreeNode();
virtual ~TreeNode();
......@@ -21,6 +23,7 @@ namespace nbody {
virtual void extendBBforBodies();
virtual void extendBBtoCube();
virtual Box getBB();
virtual vector<Body> getBodies();
};
}
......
#include "datastructures/BarnesHutTree.hpp"
using namespace nbody;
int main(int argc, char* argv[]) {
BarnesHutTree tree;
//tree.build()
return 0;
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment