#include #include #include #include #include #include #include "physics.hh" typedef std::tr1::array vector3d; static const int seed = 42; /** * Generate initial condition for the three body problem */ void threebody (std::vector& r, std::vector& v, std::vector& m) { r.resize(3); v.resize(3); m.resize(3); m[0] = 3e12; m[1] = 1.0; m[2] = 1.0; r[0][0] = 0.0; r[0][1] = 0.0; r[0][2] = 0.0; r[1][0] = 1.0; r[1][1] = 0.0; r[1][2] = 0.0; r[2][0] =-1.0; r[2][1] = 0.0; r[2][2] = 0.0; v[0][0] = 0.0; v[0][1] = 0.0; v[0][2] = 0.0; v[1][0] = 0.0; v[1][1] = 0.1; v[1][2] = 0.0; v[2][0] = 0.0; v[2][1] =-0.1; v[2][2] = 0.0; } // hide helper function namespace { /** * Compute orbital velocity for given body (helper function) */ void orbitalVelocity (int p1, int p2, std::vector& x, std::vector& v, std::vector& m) { static const double gamma_1 = gamma_si/(pc_in_m*pc_in_m*pc_in_m)*mass_sun*(365.25*86400)*(365.25*86400); double x1 = x[p1][0], y1 = x[p1][1], m1 = m[p1]; double x2 = x[p2][0], y2 = x[p2][1]; // calculate distance from the planet p1 double r[2], dist; r[0] = x1 - x2; r[1] = y1 - y2; // distance in parsec dist = sqrt(r[0] * r[0] + r[1] * r[1]); // based on the distance from the sun, calculate the velocity needed to maintain a circular orbit double abs_v = sqrt(gamma_1 * m1 / dist); // calculate a suitable vector perpendicular to r for the velocity of the tracer v[p2][0] = ( r[1] / dist) * abs_v; v[p2][1] = (-r[0] / dist) * abs_v; v[p2][2] = 0.0; } } // end namespace /** * Generate initial condition for colliding galaxies */ void collision (std::vector& x, std::vector& v, std::vector& m) { srand48(seed); // initialize particles double ratio = 0.8; int b1 = 0; int b2 = (int) (ratio*m.size()); int i; // initialize 1st black hole x[b1][0] = x[b1][1] = x[b1][2] = 0.0; v[b1][0] = v[b1][1] = v[b1][2] = 0.0; m[b1] = 1e6; // 1 million Sonnenmassen // initialize 1st galaxy for (i=1; i& r, std::vector& v, std::vector& m, std::map options) { std::string init = options["init"]; if (init == "threebody") threebody(r,v,m); // if (init == "plummer") // plummer(r,v,m); if (init == "collision") collision(r,v,m); }