Example #1
0
void problem_init(int argc, char* argv[]){
	dt = 0.01*2.*M_PI;						// initial timestep
	// integrator_epsilon = 1e-2;					// accuracy parameter, default is 1e-2 and should work in most cases.

#ifdef OPENGL
	display_wire	= 1;						// show instantaneous orbits
#endif // OPENGL
	init_boxwidth(10); 					

	struct particle star;
	star.m = 1;
	star.x = 0; 	star.y = 0; 	star.z = 0;
	star.vx = 0; 	star.vy = 0; 	star.vz = 0;
	particles_add(star);
	
	// Add planets
	int N_planets = 7;
	for (int i=0;i<N_planets;i++){
		double a = 1.+(double)i/(double)(N_planets-1);		// semi major axis
		double v = sqrt(1./a); 					// velocity (circular orbit)
		struct particle planet;
		planet.m = 1e-4; 
		planet.x = a; 	planet.y = 0; 	planet.z = 0;
		planet.vx = 0; 	planet.vy = v; 	planet.vz = 0;
		particles_add(planet); 
	}
	tools_move_to_center_of_momentum();				// This makes sure the planetary systems stays within the computational domain and doesn't drift.
}
Example #2
0
void problem_init(int argc, char* argv[]){
	// Setup constants
	G			= 1;		// Gravitational constant
#ifdef OPENGL
	display_wire		= 1; 		// show istantaneous orbits.
#endif // OPENGL


	double e_testparticle 	= 1.-1e-7;	
	double mass_scale	= 1.;		// Some integrators have problems when changing the mass scale, IAS15 does not. 
	double size_scale	= 1;		// Some integrators have problems when changing the size scale, IAS15 does not.


	boxsize 		= 25.*size_scale;
	init_box();
	
	struct particle star; 
	star.m  = mass_scale;
	star.x  = 0; star.y  = 0; star.z  = 0; 
	star.vx = 0; star.vy = 0; star.vz = 0;
	particles_add(star); 
	
	struct particle planet; 
	planet.m  = 0;
	planet.x  = size_scale*(1.-e_testparticle); planet.y  = 0; planet.z  = 0; 
	planet.vx = 0; planet.vy = sqrt((1.+e_testparticle)/(1.-e_testparticle)*mass_scale/size_scale); planet.vz = 0;
	particles_add(planet); 
	
	tools_move_to_center_of_momentum();
	
	// initial timestep
	dt 			= 1e-13*sqrt(size_scale*size_scale*size_scale/mass_scale); 
	tmax			= 1e2*2.*M_PI*sqrt(size_scale*size_scale*size_scale/mass_scale);
	
}
Example #3
0
void problem_init(int argc, char* argv[]){
	// Setup constants
	dt 		= 1e-3;
	boxsize 	= 3;
	N_active 	= 1; // Only star is massive
	init_box();

	// Initial conditions
	struct particle p; // Star
	// The WH integrator assumes a heliocentric coordinate system. 
	// Therefore the star has to be at the origin. 
	p.x  = 0; p.y  = 0; p.z  = 0; 
	p.vx = 0; p.vy = 0; p.vz = 0;
	p.ax = 0; p.ay = 0; p.az = 0;
	p.m  = 1;
	particles_add(p); 
	
	int _N = 100; // Number of test particles
	if(argc>1){
		_N = atoi(argv[1]);
	}

	const double shift = 0.0; // Change this number to put particles on eccetric orbits.
	for(int n=0; n<_N; n++){
		p.x  = cos(2.*M_PI/(double)(_N)*(double)(n)) + shift;
		p.y  = sin(2.*M_PI/(double)(_N)*(double)(n));
		p.z  = 0;
		p.vx = cos(2.*M_PI/(double)(_N)*(double)(n)+M_PI/2.);
		p.vy = sin(2.*M_PI/(double)(_N)*(double)(n)+M_PI/2.);
		p.vz = 0;
		p.ax = 0; p.ay = 0; p.az = 0;
		p.m  = 0;
		particles_add(p); // Test particle
	}
}
Example #4
0
void problem_init(int argc, char* argv[]){
	// Setup constants
	dt = 1e-3;
	tmax = 10000;
	boxsize = 3;
	coefficient_of_restitution = 1; // elastic collisions
	// Do not use any ghost boxes
	nghostx = 0; nghosty = 0; nghostz = 0;

	// Setup particle structures
	init_box();
	// Initial conditions
	struct particle p;
	p.x  = 1; p.y  = 1; p.z  = 1;
	p.vx = 0; p.vy = 0; p.vz = 0;
	p.ax = 0; p.ay = 0; p.az = 0;
	p.m  = 1;
	p.r  = 0.1;
	particles_add(p);
	p.x  = -1; p.y  = -1; p.z  = -1;
	p.vx =  0; p.vy =  0; p.vz =  0;
	p.ax =  0; p.ay =  0; p.az =  0;
	p.m  = 1;
	p.r  = 0.1;
	particles_add(p);
}
Example #5
0
void problem_init(int argc, char* argv[]){
	dt = 0.01*2.*M_PI;						// initial timestep

#ifdef OPENGL
	display_wire	= 1;						// show instantaneous orbits
#endif // OPENGL
	collision_resolve = collision_resolve_merger;			// Setup our own collision routine.
	init_boxwidth(10); 					

	struct particle star;
	star.m = 1;
	star.r = 0.1;
	star.x = 0; 	star.y = 0; 	star.z = 0;
	star.vx = 0; 	star.vy = 0; 	star.vz = 0;
	particles_add(star);
	
	// Add planets
	int N_planets = 7;
	for (int i=0;i<N_planets;i++){
		double a = 1.+(double)i/(double)(N_planets-1);		// semi major axis in AU
		double v = sqrt(1./a); 					// velocity (circular orbit)
		struct particle planet;
		planet.m = 1e-4; 
		planet.r = 4e-2; 					// radius in AU (it is unphysically large in this example)
		planet.lastcollision = 0;				// The first time particles can collide with each other
		planet.x = a; 	planet.y = 0; 	planet.z = 0;
		planet.vx = 0; 	planet.vy = v; 	planet.vz = 0;
		particles_add(planet); 
	}
	tools_move_to_center_of_momentum();				// This makes sure the planetary systems stays within the computational domain and doesn't drift.
}
void problem_init(int argc, char* argv[]){
	dt = 0.012*2.*M_PI;						// initial timestep
	integrator = HYBRID;
	//softening = 0.001;
	//integrator = IAS15;
	//integrator = WHFAST;
	integrator_whfast_corrector = 5;
	integrator_whfast_synchronize_manually = 1;

#ifdef OPENGL
	display_wire	= 1;						// show instantaneous orbits
#endif // OPENGL
	init_boxwidth(20); 					

	struct particle star;
	star.m = 1;
	star.x = 0; 	star.y = 0; 	star.z = 0;
	star.vx = 0; 	star.vy = 0; 	star.vz = 0;
	particles_add(star);
	
	// Add planets
	int N_planets = 3;
	for (int i=0;i<N_planets;i++){
		double a = 1.+.1*(double)i;		// semi major axis
		double v = sqrt(1./a); 					// velocity (circular orbit)
		struct particle planet;
		planet.m = 2e-5; 
		planet.x = a; 	planet.y = 0; 	planet.z = 0;
		planet.vx = 0; 	planet.vy = v; 	planet.vz = 0;
		particles_add(planet); 
	}
	tools_move_to_center_of_momentum();				// This makes sure the planetary systems stays within the computational domain and doesn't drift.
	e_init = tools_energy();
	system("rm -rf energy.txt");
}
void problem_init(int argc, char* argv[]) {
    // Setup constants
    integrator	= WHFAST;
    dt 		= 0.001*2.*M_PI;			// initial timestep (in days)
    init_boxwidth(200);

    // Initial conditions

    {
        struct particle p = {.m=1.,.x=0,.y=0.,.z=0.,.vx=0,.vy=0.,.vz=0.};
        particles_add(p);
    }
    {
        double e = 0.999;
        struct particle p = {.m=0.,.x=0.01,.y=0.,.z=0.,.vx=0,.vy=0.*sqrt((1.+e)/(1.-e)),.vz=0.};
        particles_add(p);
    }
    tools_move_to_center_of_momentum();
    //problem_additional_forces 	= additional_forces;
    // Add megno particles
    //tools_megno_init(1e-16);  // N = 6 after this function call.
    system("rm -f *.txt");
    ei = energy();
}

void additional_forces() {
    particles[1].ax += 0.12/6.;
}

double energy() {
    double e_kin = 0.;
    double e_pot = 0.;
    struct particle pi = particles[1];
    e_kin += 0.5 * (pi.vx*pi.vx + pi.vy*pi.vy + pi.vz*pi.vz);
    struct particle pj = particles[0];
    double dx = pi.x - pj.x;
    double dy = pi.y - pj.y;
    double dz = pi.z - pj.z;
    e_pot -= G*pj.m/sqrt(dx*dx + dy*dy + dz*dz);
    return e_kin +e_pot;
}
int no =0;
void problem_output() {
    no++;
//	printf("%d\n", no);
    if (output_check(1000.*dt)) {
        output_timing();
    }
//	FILE* f = fopen("Y.txt","a+");
//	fprintf(f,"%e %e %e\n",t,(energy()-ei)/ei,tools_megno());
//	fclose(f);
}
Example #8
0
void problem_init(int argc, char* argv[]){
	// Setup constants
	dt 			= 1e-4;	// Initial timestep.
	boxsize 		= 10;	
	tmax			= 1e6;
	N_active		= 2; 	// Only the star and the planet are massive.
	problem_additional_forces 	= force_radiation;
	init_box();
	
	
	// Star
	struct particle star;
	star.x  = 0; star.y  = 0; star.z  = 0;
	star.vx = 0; star.vy = 0; star.vz = 0;
	star.ax = 0; star.ay = 0; star.az = 0;
	star.m  = 1.;
	particles_add(star);


	// Planet 
	struct particle planet;
	planet.m  = 1e-3;
	planet.x  = 1; planet.y  = 0.; planet.z  = 0.;
	planet.ax = 0; planet.ay = 0; planet.az = 0;
	planet.vx = 0;
	planet.vy = sqrt(G*(star.m+planet.m)/planet.x);
	planet.vz = 0;
	particles_add(planet);
	
	

	// Dust particles
	while(N<3){ 	// Three particles in total (star, planet, dust particle) 
		struct particle p; 
		p.m  = 0;		// massless
		double r = 0.001;	// distance from planet planet
		double v = sqrt(G*planet.m/r);
		p.x  = r; p.y  = 0; p.z  = 0; 
		p.vx = 0; p.vy = v; p.vz = 0;
		p.x += planet.x; 	p.y += planet.y; 	p.z += planet.z;
		p.vx += planet.vx; 	p.vy += planet.vy; 	p.vz += planet.vz;
		p.ax = 0; p.ay = 0; p.az = 0;
		particles_add(p); 
	}
	
	tools_move_to_center_of_momentum();

	system("rm -v a.txt");	
}
Example #9
0
void problem_init(int argc, char* argv[]){
	// Setup constants
	opening_angle2	= 1.5;		// This constant determines the accuracy of the tree code gravity estimate.
	G 		= 1;		
	softening 	= 0.01;		// Gravitational softening length
	dt 		= 3e-3;		// Timestep
	boxsize 	= 1.2;		// Particles outside the box are removed
	root_nx = 1; root_ny = 1; root_nz = 1;
	nghostx = 0; nghosty = 0; nghostz = 0; 		
	init_box();

	// Setup particles
	double disc_mass = 2e-1;	// Total disc mass
	int _N = 10000;			// Number of particles
	// Initial conditions
	struct particle star;
	star.x 		= 0; star.y 	= 0; star.z	= 0;
	star.vx 	= 0; star.vy 	= 0; star.vz 	= 0;
	star.ax 	= 0; star.ay 	= 0; star.az 	= 0;
	star.m 		= 1;
#ifdef INTEGRATOR_WH
	// Insert particle manually. Don't add it to tree.
	Nmax 			+= 128;
	particles 		= realloc(particles,sizeof(struct particle)*Nmax);
	particles[N] 		= star;
	N++;
#else // INTEGRATOR_WH
	particles_add(star);
#endif // INTEGRATOR_WH
	while(N<_N){
		struct particle pt;
		double a	= tools_powerlaw(boxsize/10.,boxsize/2./1.2,-1.5);
		double phi 	= tools_uniform(0,2.*M_PI);
		pt.x 		= a*cos(phi);
		pt.y 		= a*sin(phi);
		pt.z 		= a*tools_normal(0.001);
		double mu 	= star.m + disc_mass * (pow(a,-3./2.)-pow(boxsize/10.,-3./2.))/(pow(boxsize/2./1.2,-3./2.)-pow(boxsize/10.,-3./2.));
		double vkep 	= sqrt(G*mu/a);
		pt.vx 		=  vkep * sin(phi);
		pt.vy 		= -vkep * cos(phi);
		pt.vz 		= 0;
		pt.ax 		= 0;
		pt.ay 		= 0;
		pt.az 		= 0;
		pt.m 		= disc_mass/(double)_N;
		particles_add(pt);
	}
}
Example #10
0
void problem_init(int argc, char* argv[]){
	// Setup constants
	G 		= 1;		
	integrator	= LEAPFROG;
	softening 	= 0.01;		
	dt 		= 3e-3;
	boxsize 	= 1.2;
	root_nx = 1; root_ny = 1; root_nz = 1;
	nghostx = 0; nghosty = 0; nghostz = 0; 		
	init_box();

	// Setup particles
	double disc_mass = 2e-1;
	int _N = 10000;
	// Initial conditions
	struct particle star;
	star.x 		= 0; star.y 	= 0; star.z	= 0;
	star.vx 	= 0; star.vy 	= 0; star.vz 	= 0;
	star.ax 	= 0; star.ay 	= 0; star.az 	= 0;
	star.m 		= 1;
#ifdef INTEGRATOR_WH
	// Insert particle manually. Don't add it to tree.
	Nmax 			+= 128;
	particles 		= realloc(particles,sizeof(struct particle)*Nmax);
	particles[N] 		= star;
	N++;
#else // INTEGRATOR_WH
	particles_add(star);
#endif // INTEGRATOR_WH
	while(N<_N){
		struct particle pt;
		double a	= tools_powerlaw(boxsize/10.,boxsize/2./1.2,-1.5);
		double phi 	= tools_uniform(0,2.*M_PI);
		pt.x 		= a*cos(phi);
		pt.y 		= a*sin(phi);
		pt.z 		= a*tools_normal(0.001);
		double mu 	= star.m + disc_mass * (pow(a,-3./2.)-pow(boxsize/10.,-3./2.))/(pow(boxsize/2./1.2,-3./2.)-pow(boxsize/10.,-3./2.));
		double vkep 	= sqrt(G*mu/a);
		pt.vx 		=  vkep * sin(phi);
		pt.vy 		= -vkep * cos(phi);
		pt.vz 		= 0;
		pt.ax 		= 0;
		pt.ay 		= 0;
		pt.az 		= 0;
		pt.m 		= disc_mass/(double)_N;
		particles_add(pt);
	}
}
Example #11
0
void problem_init(int argc, char* argv[]){
	// Setup constants
	OMEGA 				= 1.;
	OMEGAZ 				= 3.6;
	dt				= 2e-3*2.*M_PI/OMEGA;
	double particle_r 		= 1;
	double tau			= 1.64;
	coefficient_of_restitution 	= 0.5;
	boxsize 			= 1;
	root_nx = 200; 	root_ny = 5; 	root_nz = 20;
	nghostx = 1; 	nghosty = 1; 	nghostz = 0;
	init_box();

	// Initial conditions
	double _N = tau * boxsize_x * boxsize_y/(M_PI*particle_r *particle_r);
	while (N<_N){
		struct particle p;
		p.x 	= ((double)rand()/(double)RAND_MAX-0.5)*boxsize_x;
		p.y 	= ((double)rand()/(double)RAND_MAX-0.5)*boxsize_y;
		p.z 	= 10.0*((double)rand()/(double)RAND_MAX-0.5)*particle_r;
		p.vx 	= 0;
		p.vy 	= -1.5*p.x*OMEGA;
		p.vz 	= 0;
		p.ax 	= 0; p.ay 	= 0; p.az 	= 0;
		p.m 	= 1.;
		p.r 	= particle_r;
		particles_add(p);
	}
}
Example #12
0
void add_star(double Mcen){
	struct particle star;
	star.m  = Mcen;
	star.x  = 0; star.y  = 0; star.z  = 0; 
	star.vx = 0; star.vy = 0; star.vz = 0;
	particles_add(star); 
}
Example #13
0
void problem_init(int argc, char* argv[]){
	// Setup constants
	dt 		= 40;			// in days
	N_active	= 5;			// we treat pluto as a test particle. If all your particles have mass, remove this line.
	tmax		= 7.3e10;		// 200 Myr
	G		= k*k;			// These are the same units as used by the mercury6 code.
#ifdef OPENGL
	display_wire	= 1;			// Show orbits.
#endif // OPENGL
	init_boxwidth(200); 			// Init box with width 200 astronomical units

	// Initial conditions
	for (int i=0;i<6;i++){
		struct particle p;
		p.x  = ss_pos[i][0]; 		p.y  = ss_pos[i][1];	 	p.z  = ss_pos[i][2];
		p.vx = ss_vel[i][0]; 		p.vy = ss_vel[i][1];	 	p.vz = ss_vel[i][2];
		p.ax = 0; 			p.ay = 0; 			p.az = 0;
		p.m  = ss_mass[i];
		particles_add(p); 
	}
#ifdef INTEGRATOR_WH
	// Move to heliocentric frame (required by WH integrator)
	for (int i=1;i<N;i++){
		particles[i].x -= particles[0].x;	particles[i].y -= particles[0].y;	particles[i].z -= particles[0].z;
		particles[i].vx -= particles[0].vx;	particles[i].vy -= particles[0].vy;	particles[i].vz -= particles[0].vz;
	}
	particles[0].x = 0;	particles[0].y = 0;	particles[0].z = 0;
	particles[0].vx= 0;	particles[0].vy= 0;	particles[0].vz= 0;
#endif // INTEGRATOR_WH

	system("rm -f orbits.txt");
}
Example #14
0
void problem_init(int argc, char* argv[]){
	// Setup constants
#ifdef GRAVITY_TREE
	opening_angle2	= .5;
#endif
	OMEGA 				= 0.00013143527;	// 1/s
	tmax				= 2.*M_PI/OMEGA;
	G 				= 6.67428e-11;		// N / (1e-5 kg)^2 m^2
	softening 			= 0.1;			// m
	dt 				= 1e-2*2.*M_PI/OMEGA;	// s
	root_nx = 8; root_ny = 8; root_nz = 1;
	nghostx = 2; nghosty = 2; nghostz = 0; 			// Use three ghost rings
	double surfacedensity 		= 418; 			// kg/m^2
	double particle_density		= 400;			// kg/m^3
	double particle_radius_min 	= 1;			// m
	double particle_radius_max 	= 4;			// m
	double particle_radius_slope 	= -3;	
	boxsize 			= 70.7;
	if (argc>1){						// Try to read boxsize from command line
		boxsize = atof(argv[1]);
	}
	init_box();
	
	// Initial conditions
	// Use Bridges et al coefficient of restitution.
	coefficient_of_restitution_for_velocity = coefficient_of_restitution_bridges;
	minimum_collision_velocity = particle_radius_min*OMEGA*0.001;  // small fraction of the shear
	double total_mass = surfacedensity*boxsize*boxsize;
	for(int i=0;i<root_n;i++){
#ifdef MPI
		if (communication_mpi_rootbox_is_local(i)==0) continue;
#endif
		// Ring particles
		double mass = 0;
		while(mass<total_mass){
			struct particle pt;
			int ri = i%root_nx;
			int rj = ((i-ri)/root_nx)%root_ny;
			int xmin = -boxsize_x/2.+(double)(ri)*boxsize;
			int ymin = -boxsize_y/2.+(double)(rj)*boxsize;
			pt.x 		= tools_uniform(xmin,xmin+boxsize);
			pt.y 		= tools_uniform(ymin,ymin+boxsize);
			pt.z 		= tools_normal(1.);					// m
			pt.vx 		= 0;
			pt.vy 		= -1.5*pt.x*OMEGA;
			pt.vz 		= 0;
			pt.ax 		= 0;
			pt.ay 		= 0;
			pt.az 		= 0;
			double radius 	= tools_powerlaw(particle_radius_min,particle_radius_max,particle_radius_slope);
#ifndef COLLISIONS_NONE
			pt.r 		= radius;						// m
#endif // COLLISIONS_NONE
			double	particle_mass = particle_density*4./3.*M_PI*radius*radius*radius;
			pt.m 		= particle_mass; 	// kg
			particles_add(pt);
			mass += particle_mass;
		}
	}
}
Example #15
0
void problem_init(int argc, char* argv[]){
	// Setup constants
	boxsize 		= 8; 
	softening		= 1e-6;
	dt 			= 1.0e-2*2.*M_PI;
	N_active 		= 2; 	// Only the star and the planet have non-zero mass
	init_box();
	
	// Initial conditions for star
	struct particle star;
	star.x  = 0; 	star.y  = 0; 	star.z  = 0; 
	star.vx = 0; 	star.vy = 0; 	star.vz = 0;
	star.m  = 1;
	particles_add(star);

	// Initial conditions for planet
	double planet_e = 0.;
	struct particle planet;
	planet.x  = 1.-planet_e; 	planet.y  = 0; 				planet.z  = 0; 
	planet.vx = 0; 			planet.vy = sqrt(2./(1.-planet_e)-1.); 	planet.vz = 0;
	planet.m  = 1e-2;
	particles_add(planet);
	
	while(N<10000){
		double x 	= ((double)rand()/(double)RAND_MAX-0.5)*boxsize*0.9;
		double y 	= ((double)rand()/(double)RAND_MAX-0.5)*boxsize*0.9;
		double a 	= sqrt(x*x+y*y);
		double phi 	= atan2(y,x);
		if (a<.1) continue;
		if (a>boxsize_x/2.*0.9) continue;

		double vkep = sqrt(G*star.m/a);
		struct particle testparticle;
		testparticle.x  = x;
		testparticle.y  = y; 
		testparticle.z  = 1.0e-2*x*((double)rand()/(double)RAND_MAX-0.5);
		testparticle.vx = -vkep*sin(phi);
		testparticle.vy = vkep*cos(phi);
		testparticle.vz = 0;
		testparticle.ax = 0; 
		testparticle.ay = 0; 
		testparticle.az = 0;
		testparticle.m  = 0;
		particles_add(testparticle);
	}
}
Example #16
0
void tools_megno_init(double delta){
	int _N_megno = N;
	tools_megno_Ys = 0.;
	tools_megno_Yss = 0.;
	tools_megno_cov_Yt = 0.;
	tools_megno_var_t = 0.;
	tools_megno_n = 0;
	tools_megno_mean_Y = 0;
	tools_megno_mean_t = 0;
	tools_megno_delta0 = delta;
        for (int i=0;i<_N_megno;i++){ 
                struct particle megno = {
			.m  = particles[i].m,
			.x  = tools_normal(1.),
			.y  = tools_normal(1.),
			.z  = tools_normal(1.),
			.vx = tools_normal(1.),
			.vy = tools_normal(1.),
			.vz = tools_normal(1.) };
		double deltad = delta/sqrt(megno.x*megno.x + megno.y*megno.y + megno.z*megno.z + megno.vx*megno.vx + megno.vy*megno.vy + megno.vz*megno.vz); // rescale
		megno.x *= deltad;
		megno.y *= deltad;
		megno.z *= deltad;
		megno.vx *= deltad;
		megno.vy *= deltad;
		megno.vz *= deltad;

                particles_add(megno);
        }
	N_megno = _N_megno;
}
double tools_megno(void){ // Returns the MEGNO <Y>
	if (t==0.) return 0.;
	return tools_megno_Yss/t;
}
double tools_lyapunov(void){ // Returns the largest Lyapunov characteristic number (LCN), or maximal Lyapunov exponent
	if (t==0.) return 0.;
	return tools_megno_cov_Yt/tools_megno_var_t;
}
double tools_megno_deltad_delta(void){
        double deltad = 0;
        double delta2 = 0;
        for (int i=N-N_megno;i<N;i++){
                deltad += particles[i].vx * particles[i].x; 
                deltad += particles[i].vy * particles[i].y; 
                deltad += particles[i].vz * particles[i].z; 
                deltad += particles[i].ax * particles[i].vx; 
                deltad += particles[i].ay * particles[i].vy; 
                deltad += particles[i].az * particles[i].vz; 
                delta2 += particles[i].x  * particles[i].x; 
                delta2 += particles[i].y  * particles[i].y;
                delta2 += particles[i].z  * particles[i].z;
                delta2 += particles[i].vx * particles[i].vx; 
                delta2 += particles[i].vy * particles[i].vy;
                delta2 += particles[i].vz * particles[i].vz;
        }
        return deltad/delta2;
}
Example #17
0
void problem_init(int argc, char* argv[]){
	// Setup constants
#ifdef GRAVITY_TREE
	opening_angle2	= .5;
#endif // GRAVITY_TREE
	OMEGA 				= 0.00013143527;	// 1/s
	G 				= 6.67428e-11;		// N / (1e-5 kg)^2 m^2
	softening 			= 0.1;			// m
	dt 				= 1e-3*2.*M_PI/OMEGA;	// s
#ifdef OPENGL
	display_rotate_z		= 20;			// Rotate the box by 20 around the z axis, then 
	display_rotate_x		= 60;			// rotate the box by 60 degrees around the x axis	
#ifdef LIBPNG
	system("mkdir png");
#endif // LIBPNG
#endif // OPENGL
	root_nx = 2; root_ny = 2; root_nz = 1;
	nghostx = 2; nghosty = 2; nghostz = 0; 			// Use two ghost rings
	double surfacedensity 		= 400; 			// kg/m^2
	double particle_density		= 400;			// kg/m^3
	double particle_radius_min 	= 1;			// m
	double particle_radius_max 	= 4;			// m
	double particle_radius_slope 	= -3;	
	boxsize 			= 100;			// m
	if (argc>1){						// Try to read boxsize from command line
		boxsize = atof(argv[1]);
	}
	init_box();
	
	// Initial conditions
	printf("Toomre wavelength: %f\n",2.*M_PI*M_PI*surfacedensity/OMEGA/OMEGA*G);
	// Use Bridges et al coefficient of restitution.
	coefficient_of_restitution_for_velocity = coefficient_of_restitution_bridges;
	minimum_collision_velocity = particle_radius_min*OMEGA*0.001;  // small fraction of the shear
	double total_mass = surfacedensity*boxsize_x*boxsize_y;
	double mass = 0;
	while(mass<total_mass){
		struct particle pt;
		pt.x 		= tools_uniform(-boxsize_x/2.,boxsize_x/2.);
		pt.y 		= tools_uniform(-boxsize_y/2.,boxsize_y/2.);
		pt.z 		= tools_normal(1.);					// m
		pt.vx 		= 0;
		pt.vy 		= -1.5*pt.x*OMEGA;
		pt.vz 		= 0;
		pt.ax 		= 0;
		pt.ay 		= 0;
		pt.az 		= 0;
		double radius 	= tools_powerlaw(particle_radius_min,particle_radius_max,particle_radius_slope);
#ifndef COLLISIONS_NONE
		pt.r 		= radius;						// m
#endif
		double		particle_mass = particle_density*4./3.*M_PI*radius*radius*radius;
		pt.m 		= particle_mass; 	// kg
		particles_add(pt);
		mass += particle_mass;
	}
}
Example #18
0
void problem_init(int argc, char* argv[]){
	// Setup constants
#ifdef GRAVITY_TREE
	opening_angle2	= .5;
#endif
	OMEGA 				= 0.00013143527;	// 1/s
	G 				= 6.67428e-11;		// N / (1e-5 kg)^2 m^2
	softening 			= 0.1;			// m
	dt 				= 1e-3*2.*M_PI/OMEGA;	// s
	root_nx = 2; root_ny = 2; root_nz = 1;
	nghostx = 2; nghosty = 2; nghostz = 0; 			// Use two ghost rings
	double surfacedensity 		= 400; 			// kg/m^2
	double particle_density		= 400;			// kg/m^3
	double particle_radius_min 	= 1;			// m
	double particle_radius_max 	= 4;			// m
	double particle_radius_slope 	= -3;	
	boxsize 			= 100;
	if (argc>1){						// Try to read boxsize from command line
		boxsize = atof(argv[1]);
	}
	init_box();
	
	// Initial conditions
	printf("Toomre wavelength: %f\n",2.*M_PI*M_PI*surfacedensity/OMEGA/OMEGA*G);
	// Use Bridges et al coefficient of restitution.
	coefficient_of_restitution_for_velocity = coefficient_of_restitution_bridges;
	minimum_collision_velocity = particle_radius_min*OMEGA*0.001;  // small fraction of the shear
	double total_mass = surfacedensity*boxsize_x*boxsize_y;
#ifdef MPI
	// Only initialise particles on master. This should also be parallelied but the details depend on the individual problem.
	if (mpi_id==0){
#endif
		double mass = 0;
		while(mass<total_mass){
			struct particle pt;
			pt.x 		= tools_uniform(-boxsize_x/2.,boxsize_x/2.);
			pt.y 		= tools_uniform(-boxsize_y/2.,boxsize_y/2.);
			pt.z 		= tools_normal(1.);					// m
			pt.vx 		= 0;
			pt.vy 		= -1.5*pt.x*OMEGA;
			pt.vz 		= 0;
			pt.ax 		= 0;
			pt.ay 		= 0;
			pt.az 		= 0;
			double radius 	= tools_powerlaw(particle_radius_min,particle_radius_max,particle_radius_slope);
#ifndef COLLISIONS_NONE
			pt.r 		= radius;						// m
#endif
			double		particle_mass = particle_density*4./3.*M_PI*radius*radius*radius;
			pt.m 		= particle_mass; 	// kg
			particles_add(pt);
			mass += particle_mass;
		}
#ifdef MPI
	}
#endif
}
Example #19
0
void problem_init(int argc, char* argv[]){
	// Setup constants
	integrator	= WH;
	G 		= 1;		
	N_active	= 1;
	N_collisions	= 1; 	// Don't detect collisions for the star.
	softening 	= 0.01;		
	dt 		= 1e-3;
	boxsize 	= 2.4;
	root_nx = 1; root_ny = 1; root_nz = 1;
	nghostx = 0; nghosty = 0; nghostz = 0; 		
	init_box();

	// Setup particles
	int _N = 1000;
	// Initial conditions
	struct particle star;
	star.x 		= 0; star.y 	= 0; star.z	= 0;
	star.vx 	= 0; star.vy 	= 0; star.vz 	= 0;
	star.ax 	= 0; star.ay 	= 0; star.az 	= 0;
	star.m 		= 1;
	star.r		= 0.01;
	particles_add(star);
	while(N<_N){
		struct particle pt;
		double a	= tools_powerlaw(boxsize/2.9,boxsize/3.1,.5);
		double phi 	= tools_uniform(0,2.*M_PI);
		pt.x 		= a*cos(phi);
		pt.y 		= a*sin(phi);
		pt.z 		= a*tools_normal(0.0001);
		double vkep 	= sqrt(G*star.m/a);
		pt.vx 		=  vkep * sin(phi);
		pt.vy 		= -vkep * cos(phi);
		pt.vz 		= 0;
		pt.ax 		= 0;
		pt.ay 		= 0;
		pt.az 		= 0;
		pt.m 		= 0.0001;
		pt.r 		= .3/sqrt((double)_N);
		particles_add(pt);
	}
}
Example #20
0
void problem_init(int argc, char* argv[]){
	// Setup constants
	OMEGA 				= 0.00013143527;	// 1/s
	G 				= 6.67428e-11;		// N / (1e-5 kg)^2 m^2
	dt 				= 1e-3*2.*M_PI/OMEGA;	// s
	root_nx = 10; root_ny = 1; root_nz = 1;
	nghostx = 1; nghosty = 1; nghostz = 0; 			// Use two one ring (+cutoff, see below)
	double surfacedensity 		= 400; 			// kg/m^2
	double particle_density		= 400;			// kg/m^3
	double particle_radius_min 	= 1;			// m
	double particle_radius_max 	= 4;			// m
	double particle_radius_slope 	= -3;	
	boxsize 			= 100;
	if (argc>1){						// Try to read boxsize from command line
		boxsize = atof(argv[1]);
	}
	init_box();
#ifdef GRAVITY_GRAPE
	gravity_range = boxsize/2.;
#endif // GRAVITY_GRAPE
	
	// Initial conditions
	printf("Toomre wavelength: %f\n",2.*M_PI*M_PI*surfacedensity/OMEGA/OMEGA*G);
#ifndef COLLISIONS_NONE
	// Use Bridges et al coefficient of restitution.
	coefficient_of_restitution_for_velocity	= coefficient_of_restitution_bridges;
	minimum_collision_velocity		= particle_radius_min*OMEGA*0.001;  // small fraction of the shear
	softening 				= 0.1;			// m
#else  // COLLISIONS_NONE
	softening				= particle_radius_max;
#endif // COLLISIONS_NONE
	double total_mass = surfacedensity*boxsize_x*boxsize_y;
	double mass = 0;
	while(mass<total_mass){
		struct particle pt;
		pt.x 		= tools_uniform(-boxsize_x/2.,boxsize_x/2.);
		pt.y 		= tools_uniform(-boxsize_y/2.,boxsize_y/2.);
		pt.z 		= tools_normal(1.);					// m
		pt.vx 		= 0;
		pt.vy 		= -1.5*pt.x*OMEGA;
		pt.vz 		= 0;
		pt.ax 		= 0;
		pt.ay 		= 0;
		pt.az 		= 0;
		double radius 	= tools_powerlaw(particle_radius_min,particle_radius_max,particle_radius_slope);
#ifndef COLLISIONS_NONE
		pt.r 		= radius;						// m
#endif
		double		particle_mass = particle_density*4./3.*M_PI*radius*radius*radius;
		pt.m 		= particle_mass; 	// kg
		particles_add(pt);
		mass += particle_mass;
	}
}
Example #21
0
void problem_init(int argc, char* argv[]){
	// Setup constants
#ifdef GRAVITY_TREE
	opening_angle2	= .5;
#endif // GRAVITY_TREE
	integrator			= SEI;
	OMEGA 				= 0.00013143527;	// 1/s
	G 				= 6.67428e-11;		// N / (1e-5 kg)^2 m^2
	softening 			= 0.1;			// m
	dt 				= 1e-3*2.*M_PI/OMEGA;	// s
	root_nx = 2; root_ny = 2; root_nz = 1;
	nghostx = 2; nghosty = 2; nghostz = 0; 			// Use two ghost rings
	double surfacedensity 		= 840; 			// kg/m^2
	double particle_density		= 900;			// kg/m^3
	double particle_radius_min 	= 1.;			// m
	double particle_radius_max 	= 1.;			// m
	double particle_radius_slope 	= -3;	
	boxsize 			= 40;			// m
	if (argc>1){						// Try to read boxsize from command line
		boxsize = atof(argv[1]);
	}
	init_box();
	
	// Initial conditions
	printf("Toomre wavelength: %f\n",4.*M_PI*M_PI*surfacedensity/OMEGA/OMEGA*G);
	// Use Bridges et al coefficient of restitution.
	coefficient_of_restitution_for_velocity = coefficient_of_restitution_bridges;
	// Change collision_resolve routing from default.
	collision_resolve = collision_resolve_hardsphere_pullaway;
	// Small residual velocity to avoid particles from sinking into each other.
	minimum_collision_velocity = particle_radius_min*OMEGA*0.001;  // small fraction of the shear
	double total_mass = surfacedensity*boxsize_x*boxsize_y;
	double mass = 0;
	while(mass<total_mass){
		struct particle pt;
		pt.x 		= tools_uniform(-boxsize_x/2.,boxsize_x/2.);
		pt.y 		= tools_uniform(-boxsize_y/2.,boxsize_y/2.);
		pt.z 		= tools_normal(1.);					// m
		pt.vx 		= 0;
		pt.vy 		= -1.5*pt.x*OMEGA;
		pt.vz 		= 0;
		pt.ax 		= 0;
		pt.ay 		= 0;
		pt.az 		= 0;
		double radius 	= tools_powerlaw(particle_radius_min,particle_radius_max,particle_radius_slope);
#ifndef COLLISIONS_NONE
		pt.r 		= radius;						// m
#endif
		double		particle_mass = particle_density*4./3.*M_PI*radius*radius*radius;
		pt.m 		= particle_mass; 	// kg
		particles_add(pt);
		mass += particle_mass;
	}
}
Example #22
0
void problem_init(int argc, char* argv[]){
	// Setup constants
	G 		= 1;		
	softening 	= 0.01;		
	dt 		= 3e-3;
	boxsize 	= 2.4;
	integrator	= LEAPFROG;
	root_nx = 1; root_ny = 1; root_nz = 1;
	nghostx = 0; nghosty = 0; nghostz = 0; 		
	init_box();

	// Initial conditions
	struct particle star;
	star.x 		= 0; star.y 	= 0; star.z	= 0;
	star.vx 	= 0; star.vy 	= 0; star.vz 	= 0;
	star.ax 	= 0; star.ay 	= 0; star.az 	= 0;
	star.m 		= 1;
	particles_add(star);
	
	// Setup disk particles
	double disc_mass = 2e-1;
	int _N = 1024*4;
	while(N<_N){
		struct particle pt;
		double a	= tools_powerlaw(boxsize/20.,boxsize/4./1.2,-1.5);
		double phi 	= tools_uniform(0,2.*M_PI);
		pt.x 		= a*cos(phi);
		pt.y 		= a*sin(phi);
		pt.z 		= a*tools_normal(0.001);
		double mu 	= star.m + disc_mass * (pow(a,-3./2.)-pow(boxsize/20.,-3./2.))/(pow(boxsize/4./1.2,-3./2.)-pow(boxsize/20.,-3./2.));
		double vkep 	= sqrt(G*mu/a);
		pt.vx 		=  vkep * sin(phi);
		pt.vy 		= -vkep * cos(phi);
		pt.vz 		= 0;
		pt.ax 		= 0;
		pt.ay 		= 0;
		pt.az 		= 0;
		pt.m 		= disc_mass/(double)_N;
		particles_add(pt);
	}
}
Example #23
0
void problem_init(int argc, char* argv[]){
	// Setup constants
	dt 		= 1e-3*2.*M_PI;
	boxsize 	= 3;
#ifdef OPENGL
	display_wire 	= 1;
#endif 	// OPENGL
	init_box();

	// Initial conditions
	// Parameters are those of Lee & Peale 2002, Figure 4. 
	struct particle star;
	star.x  = 0; star.y  = 0; star.z  = 0;
	star.vx = 0; star.vy = 0; star.vz = 0;
	star.ax = 0; star.ay = 0; star.az = 0;
	star.m  = 0.32;		// This is a sub-solar mass star
	particles_add(star); 
	
	struct particle p1;	// Planet 1
	p1.x 	= 0.5;	p1.y = 0;	p1.z = 0;
	p1.ax 	= 0;	p1.ay = 0; 	p1.az = 0;
	p1.m  	= 0.56e-3;
	p1.vy 	= sqrt(G*(star.m+p1.m)/p1.x);
	p1.vx 	= 0;	p1.vz = 0;
	particles_add(p1); 
	
	struct particle p2;	// Planet 1
	p2.x 	= 1;	p2.y = 0; 	p2.z = 0;
	p2.ax 	= 0;	p2.ay = 0; 	p2.az = 0;
	p2.m  	= 1.89e-3;
	p2.vy 	= sqrt(G*(star.m+p2.m)/p2.x);
	p2.vx 	= 0;	p2.vz = 0;
	particles_add(p2); 

	tau_a = calloc(sizeof(double),N);
	tau_e = calloc(sizeof(double),N);

	tau_a[2] = 125663.;		// Migration timescale of planet 2 is 20000 years.
	tau_e[2] = tau_a[2]/100.; 	// Eccentricity damping timescale is 200 years (K=100). 
}
void problem_init(int argc, char* argv[]){
	// Setup constants
	integrator			= IAS15;
	dt 				= 1e-6;			// initial timestep
	boxsize 			= 0.01;	
	tmax				= 3e1;
	N_active			= 2; 			// only the star and the planet are massive.
	problem_additional_forces 	= force_J2;
	init_box();
	
	
	// Planet
	struct particle planet;
	planet.m  = Msaturn;
	planet.x  = 0; planet.y  = 0; planet.z  = 0;
	planet.vx = 0; planet.vy = 0; planet.vz = 0;
	particles_add(planet);
	// Read obliquity from command line. Default is 0. 
	ObliquityPlanet 		= input_get_double(argc,argv,"Obliquity",0.)/180.*M_PI;
	
	

	// Add one dust particles
	while(N<2){ 						// two particles in total (planet and dust particle) 
		struct particle p; 
		p.m  = 0;					// massless
		double a = Rplanet*3.;				// small distance from planet (makes J2 important)
		double e = 0.1;
		double v = sqrt((1.+e)/(1.-e)*G*planet.m/a);	// setup eccentric orbit (ignores J2)
		p.x  = (1.-e)*a; p.y  = 0; p.z  = 0; 
		p.vx = 0; p.vy = v; p.vz = 0;
		p.x += planet.x; 	p.y += planet.y; 	p.z += planet.z;
		p.vx += planet.vx; 	p.vy += planet.vy; 	p.vz += planet.vz;
		particles_add(p); 
	}
	
	tools_move_to_center_of_momentum();

	system("rm -v a.txt");					// delete previous output
}
Example #25
0
void parse_orbel2D_data(FILE *fi,int Npl,double Mcen){
	double mass,a,e,omega,M;
	add_star(Mcen);
	int i =0;
	for(i=0; i<Npl;i++){
		if ( fscanf(fi,"%lf %lf %lf %lf %lf",&mass,&a,&e,&omega,&M)!=5){
			printf("Error in planet file, line %d\n",i+1);
			exit(1);
		}
		
		double f = tools_MeanAnom2TrueAnom(M,e);
		particles_add( tools_init_orbit2d(Mcen,mass,a,e,omega,f) );
	}
}
void communication_mpi_distribute_particles(void){
	// Distribute the number of particles to be transferred.
	for (int i=0;i<mpi_num;i++){
		MPI_Scatter(particles_send_N, 1, MPI_INT, &(particles_recv_N[i]), 1, MPI_INT, i, MPI_COMM_WORLD);
	}
	// Allocate memory for incoming particles
	for (int i=0;i<mpi_num;i++){
		if  (i==mpi_id) continue;
		while (particles_recv_Nmax[i]<particles_recv_N[i]){
			particles_recv_Nmax[i] += 32;
			particles_recv[i] = realloc(particles_recv[i],sizeof(struct particle)*particles_recv_Nmax[i]);
		}
	}

	// Exchange particles via MPI.
	// Using non-blocking receive call.
	MPI_Request request[mpi_num];
	for (int i=0;i<mpi_num;i++){
		if (i==mpi_id) continue;
		if (particles_recv_N[i]==0) continue;
		MPI_Irecv(particles_recv[i], particles_recv_N[i], mpi_particle, i, i*mpi_num+mpi_id, MPI_COMM_WORLD, &(request[i]));
	}
	// Using blocking send call.
	for (int i=0;i<mpi_num;i++){
		if (i==mpi_id) continue;
		if (particles_send_N[i]==0) continue;
		MPI_Send(particles_send[i], particles_send_N[i], mpi_particle, i, mpi_id*mpi_num+i, MPI_COMM_WORLD);
	}
	// Wait for all particles to be received.
	for (int i=0;i<mpi_num;i++){
		if (i==mpi_id) continue;
		if (particles_recv_N[i]==0) continue;
		MPI_Status status;
		MPI_Wait(&(request[i]), &status);
	}
	// Add particles to local tree
	for (int i=0;i<mpi_num;i++){
		for (int j=0;j<particles_recv_N[i];j++){
			particles_add(particles_recv[i][j]);
		}
	}
	// Bring everybody into sync, clean up. 
	MPI_Barrier(MPI_COMM_WORLD);
	for (int i=0;i<mpi_num;i++){
		particles_send_N[i] = 0;
		particles_recv_N[i] = 0;
	}
}
Example #27
0
void problem_init(int argc, char* argv[]){

	// Integrator parameters
	OMEGA = 1.0;
	dt = 1.0e-3;										// timestep
	tmax = dt*Nsteps_per_output*Noutput;				// simulation stop time
//#ifdef OPENGL
//	display_rotate_z = 90;								// display rotation angle (deg)
//	display_rotate_x = 0;	
//#endif

	//Particle parameters
	double x0_max = 10;									// particles' initial -x0_max < x < x0_max
	double y0_max = 50;									// particles' initial y range
    double z0_max = 0.0;								// particles' initial z range
	boxsize = 1;
	root_nx	= 20;
	root_ny = 100;
	root_nz = 10;
	nghostx = 0;
	nghosty = 1;										// ghost boxes along y direction only
	nghostz = 0;
	double radius = 0.0;								// particle radius
	double density = 0.5;								// particle density in cgs when radius is in cm
	coefficient_of_restitution = 0.5;
	minimum_collision_velocity = 0.001;
	init_box();

	// Initial conditions
	for (int i=0; i<N_init; i++){
		struct particle p;
		p.x = tools_uniform(-x0_max, x0_max);
		p.y = tools_uniform(-y0_max, y0_max);
		p.z = tools_uniform(-z0_max, z0_max);
		p.vx = 0;
		p.vy = -1.5*p.x*OMEGA;
		p.vz = 0;
		p.ax = 0;
		p.ay = 0;
		p.az = 0;
		p.m = 4*M_PI*density*radius*radius*radius/3;
		p.r = radius;
	    //pt.id = i;
		particles_add(p);
	}
}
Example #28
0
void problem_init(int argc, char* argv[]) {
    // Check for command line arguments
    if (argc<3) {
        printf("Error. Please specify two command line arguments: r_h^* and s_x"\n);
        exit(1);
    }

    // Calculating parameters. See Daisaka et al for definitions.
    r_hstar = atof(argv[1]);
    double r_h 		= r_hstar*2.*particle_radius;
    double particle_mass 	= r_h*r_h*r_h*3./2.;
    double tau 		= 0.5;
    double surface_density 	= tau/(M_PI*particle_radius*particle_radius)*particle_mass;
    lambda_crit	 	= 4.*M_PI*M_PI*G*surface_density/OMEGA/OMEGA;
    sx2 			= 3.*lambda_crit/2.;
    sy2 			= 3.*lambda_crit/2.;
    boxsize 		= lambda_crit*atof(argv[2]);
    int _N 			= (int)round(tau*boxsize*boxsize/(M_PI*particle_radius*particle_radius));
    dt 			= 2e-3*2.*M_PI;
    tmax			= 40.*2.*M_PI;
    softening 		= 0.1*particle_radius;
    opening_angle2		= 0.9;
    coefficient_of_restitution = 0.5;
    minimum_collision_velocity = 2.*dt*particle_radius;
    nghostx = 3;
    nghosty = 3;
    nghostz = 0;
    init_box();

    // Initialize particles
    while(N<_N) {
        struct particle p;
        p.x 	= ((double)rand()/(double)RAND_MAX-0.5)*boxsize_x;
        p.y 	= ((double)rand()/(double)RAND_MAX-0.5)*boxsize_y;
        p.z 	= 3.*particle_radius*((double)rand()/(double)RAND_MAX-0.5);
        p.vx 	= 0;
        p.vy 	= -1.5*p.x*OMEGA;
        p.vz 	= 0;
        p.ax 	= 0;
        p.ay 	= 0;
        p.az 	= 0;
        p.m 	= particle_mass;
        p.r 	= particle_radius;
        particles_add(p);
    }
}
Example #29
0
void parse_cartesian_data(FILE *fi,int Npl, double Mcen){
	double mass;
	double x,y,z;
	double vx,vy,vz;
	int i =0;
	add_star(Mcen);
	for(i=0; i<Npl;i++){
		if ( fscanf(fi,"%lf %lf %lf %lf %lf %lf %lf",&mass,&x,&y,&z,&vx,&vy,&vz)!=7){
			printf("Error in planet file, line %d\n",i+1);
			exit(1);
		}
		struct particle planet;
		planet.m = mass;
		planet.x = x;	planet.y = y;	planet.z = z;
		planet.vx =vx;	planet.vy=vy;	planet.vz = vz;
		particles_add(planet);
	}
}
Example #30
0
void tools_init_plummer(int _N, double M, double R) {
	// Algorithm from:	
	// http://adsabs.harvard.edu/abs/1974A%26A....37..183A
	
	double E = 3./64.*M_PI*M*M/R;
	for (int i=0;i<_N;i++){
		struct particle star;
		double r = pow(pow(tools_uniform(0,1),-2./3.)-1.,-1./2.);
		double x2 = tools_uniform(0,1);
		double x3 = tools_uniform(0,2.*M_PI);
		star.z = (1.-2.*x2)*r;
		star.x = sqrt(r*r-star.z*star.z)*cos(x3);
		star.y = sqrt(r*r-star.z*star.z)*sin(x3);
		double x5,g,q;
		do{
			x5 = tools_uniform(0.,1.);
			q = tools_uniform(0.,1.);
			g = q*q*pow(1.-q*q,7./2.);
		}while(0.1*x5>g);
		double ve = pow(2.,1./2.)*pow(1.+r*r,-1./4.);
		double v = q*ve;
		double x6 = tools_uniform(0.,1.);
		double x7 = tools_uniform(0.,2.*M_PI);
		star.vz = (1.-2.*x6)*v;
		star.vx = sqrt(v*v-star.vz*star.vz)*cos(x7);
		star.vy = sqrt(v*v-star.vz*star.vz)*sin(x7);
		
		star.x *= 3.*M_PI/64.*M*M/E;
		star.y *= 3.*M_PI/64.*M*M/E;
		star.z *= 3.*M_PI/64.*M*M/E;
		
		star.vx *= sqrt(E*64./3./M_PI/M);
		star.vy *= sqrt(E*64./3./M_PI/M);
		star.vz *= sqrt(E*64./3./M_PI/M);

		star.m = M/(double)_N;


		particles_add(star);
	}
}