/* Always call this on the root node. If you call this from another node, you're a dick. */ void QTnode::calc_global_accel() { int i; QTnode *t; std::queue <QTnode *> nodes; nodes.push(this); /* Perform a breadth-first traversal through all particles. */ while (!nodes.empty()) { t = nodes.front(); nodes.pop(); if (t->children.empty()) { for (std::list <Particle>::iterator p = t->particles.begin(); p != t->particles.end(); p++) { (*p).accel = calc_accel(*p); // printf("Particle has accel <%lf, %lf>\n", (*p).accel.x, (*p).accel.y); } } else { for (i = 0; i < t->children.size(); i++) { nodes.push(t->children[i]); } } } }
/** * @todo: * Make the storage of the previous calculated acceleration working. */ void integration_leap_frog(listv2d& r, listv2d& v, listv2d& a, const listdouble& m, double h, double ti) { // Store the previous accellerations so they don't have to be calculcated again static listv2d previous_accel; if (previous_accel.size() == 0) { for (int i = 0; i < ITEMS; i++) { previous_accel.push_back(calc_accel(r, m, i)); } } listv2d v1(ITEMS); for (int i = 0; i < ITEMS; i++) { // Use previous calculated f(t) for the new speed. v1[i] = v[i] + 0.5 * h * previous_accel[i]; r[i] = r[i] + h * v1[i]; } for (int i = 0; i < ITEMS; i++) { //Calculate f(t+1) for the new speed. previous_accel[i] = calc_accel(r, m, i); v[i] = v1[i] + 0.5 * h * previous_accel[i]; } }
/** * Calculate the accelleration of all bodies. */ void calc_accel_multiple(const listv2d& r, listv2d& a, const vector<double>&m) { for (int i = 0; i < ITEMS; i++) { a[i] = calc_accel(r, m, i); } }