#ifndef NBGENERATOR_HH #define NBGENERATOR_HH #include #include #include #include "nbio.hh" #include "nbtypes.hh" /* generate initial condition for the nbody problem */ void plummer (int n, vector3 x[], vector3 v[], double m[], long int seed = 0) { /* This is a copy from Pit Hut, Jun Makino: The Art of Computational Science, The Kali Code, vol. 5. Initial Conditions: Plummer's Model. */ int i; double radius,theta,phi,X,Y,velocity,maxr=-1.0; const double Pi = 3.141592653589793238462643383279; double s[3] = {0.0,0.0,0.0}; double t[3] = {0.0,0.0,0.0}; if (seed!=0) srand48(seed); for (i=0; imaxr) maxr=radius; theta = acos(-1.0+drand48()*2.0); phi = drand48()*2.0*Pi; x[i][0] = radius*sin(theta)*cos(phi); x[i][1] = radius*sin(theta)*sin(phi); x[i][2] = radius*cos(theta); s[0] += m[i]*x[i][0]; s[1] += m[i]*x[i][1]; s[2] += m[i]*x[i][2]; X = 0.0; Y = 0.1; while (Y>X*X*pow(1.0-X*X,3.5)) { X = drand48(); Y = drand48()*0.1; } velocity = X*sqrt(2.0)*pow(1.0+radius*radius,-0.25); theta = acos(-1.0+drand48()*2.0); phi = drand48()*2.0*Pi; v[i][0] = velocity*sin(theta)*cos(phi); v[i][1] = velocity*sin(theta)*sin(phi); v[i][2] = velocity*cos(theta); t[0] += m[i]*v[i][0]; t[1] += m[i]*v[i][1]; t[2] += m[i]*v[i][2]; } printf("center of mass: %g %g %g\n",s[0],s[1],s[2]); for (i=0; i