예제 #1
0
int main(int argc, char* argv[]) {
	struct reb_simulation* r = reb_create_simulation();
	// Setup constants
	r->opening_angle2	= .5;					// This determines the precission of the tree code gravity calculation.
	r->integrator			= REB_INTEGRATOR_SEI;
	r->boundary			= REB_BOUNDARY_SHEAR;
	r->gravity			= REB_GRAVITY_TREE;
	r->collision			= REB_COLLISION_TREE;
	double OMEGA 			= 0.00013143527;	// 1/s
	r->ri_sei.OMEGA 		= OMEGA;
	r->G 				= 6.67428e-11;		// N / (1e-5 kg)^2 m^2
	r->softening 			= 0.1;			// m
	r->dt 				= 1e-3*2.*M_PI/OMEGA;	// s
	// This example uses two root boxes in the x and y direction. 
	// Although not necessary in this case, it allows for the parallelization using MPI. 
	// See Rein & Liu for a description of what a root box is in this context.
	double surfacedensity 		= 600; 			// 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;	
	double boxsize 			= 100;			// m
	if (argc>1){						// Try to read boxsize from command line
		boxsize = atof(argv[1]);
	}
	reb_configure_box(r, boxsize, 2, 2, 1);
	r->nghostx = 2;
	r->nghosty = 2;
	r->nghostz = 0;
	
	// Use Bridges et al coefficient of restitution.
	r->coefficient_of_restitution = coefficient_of_restitution_bridges;
	// When two particles collide and the relative velocity is zero, the might sink into each other in the next time step.
	// By adding a small repulsive velocity to each collision, we prevent this from happening.
	r->minimum_collision_velocity = particle_radius_min*OMEGA*0.001;  // small fraction of the shear accross a particle


	// Add all ring paricles
	double total_mass = surfacedensity*r->boxsize.x*r->boxsize.y;
	double mass = 0;
	while(mass<total_mass){
		struct reb_particle pt = {0.};
		pt.x 		= reb_random_uniform(-r->boxsize.x/2.,r->boxsize.x/2.);
		pt.y 		= reb_random_uniform(-r->boxsize.y/2.,r->boxsize.y/2.);
		pt.z 		= reb_random_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 	= reb_random_powerlaw(particle_radius_min,particle_radius_max,particle_radius_slope);
		pt.r 		= radius;						// m
		double		particle_mass = particle_density*4./3.*M_PI*radius*radius*radius;
		pt.m 		= particle_mass; 	// kg
		reb_add(r, pt);
		mass += particle_mass;
	}
	reb_integrate(r, 2./OMEGA);
}
예제 #2
0
파일: problem.c 프로젝트: cshankm/rebound
int main(int argc, char* argv[]){
	{
		printf("Running simulation until t=10.\n");
		struct reb_simulation* r = reb_create_simulation();
		r->integrator	= REB_INTEGRATOR_SEI;
		r->collision	= REB_COLLISION_DIRECT;
		r->ri_sei.OMEGA	= 1.;	
		r->dt 		= 1e-4*2.*M_PI; 
		r->nghostx = 1; r->nghosty = 1; r->nghostz = 0;
		reb_configure_box(r,1.,1,1,1);

		while (r->N<50){
			struct reb_particle p = {0};
			p.x  = ((double)rand()/(double)RAND_MAX-0.5)*r->boxsize.x;
			p.y  = ((double)rand()/(double)RAND_MAX-0.5)*r->boxsize.y;
			p.z  = 0.1*((double)rand()/(double)RAND_MAX-0.5)*r->boxsize.z;
			p.vy = -1.5*p.x*r->ri_sei.OMEGA;
			p.m  = 0.01;
			p.r  = 0.05;
			reb_add(r, p);
		}
		reb_integrate(r,10.);
		printf("Saving simulation to binary file and freeing up memory.\n");
		reb_output_binary(r, "restart.bin");
		reb_free_simulation(r);
		r = NULL;
	}
	{
		printf("Creating simulation from binary file and integrating until t=20.\n");
		struct reb_simulation* r = reb_create_simulation_from_binary("restart.bin");
		reb_integrate(r,20.);
		printf("Done.\n");
	}
}
예제 #3
0
int main(int argc, char* argv[]){
	struct reb_simulation* r = reb_create_simulation();
	// Setup constants
	r->integrator		= REB_INTEGRATOR_WHFAST;
	r->boundary		= REB_BOUNDARY_OPEN;
	r->softening		= 1e-6;
	r->dt 			= 1.0e-2*2.*M_PI;
	r->N_active 		= 2; 	// Only the star and the planet have non-zero mass
	r->heartbeat		= heartbeat;

	reb_configure_box(r,8.,1,1,1); // Box with size 8 AU
	
	// Initial conditions for star
	struct reb_particle star;
	star.x  = 0; 	star.y  = 0; 	star.z  = 0; 
	star.vx = 0; 	star.vy = 0; 	star.vz = 0;
	star.m  = 1;
	reb_add(r, star);

	// Initial conditions for planet
	double planet_e = 0.;
	struct reb_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;
	reb_add(r, planet);
	reb_move_to_com(r);
	
	while(r->N<10000){
		double x 	= ((double)rand()/(double)RAND_MAX-0.5)*8.;
		double y 	= ((double)rand()/(double)RAND_MAX-0.5)*8.;
		double a 	= sqrt(x*x+y*y);
		double phi 	= atan2(y,x);
		if (a<.1) continue;
		if (a>4.) continue;

		double vkep = sqrt(r->G*star.m/a);
		struct reb_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;
		reb_add(r, testparticle);
	}

	reb_integrate(r, INFINITY);
}
예제 #4
0
파일: problem.c 프로젝트: SeanBE/rebound
void run_sim(){
	struct reb_simulation* const r = reb_create_simulation();
	// Setup constants
	r->integrator	= REB_INTEGRATOR_LEAPFROG;
	r->gravity	= REB_GRAVITY_BASIC;
	r->boundary	= REB_BOUNDARY_OPEN;
	r->opening_angle2	= 1.5;	// This constant determines the accuracy of the tree code gravity estimate.
	r->G 		= 1;		
	r->softening 	= 0.02;		// Gravitational softening length
	r->dt 		= 3e-2;		// Timestep
	const double boxsize = 10.2;
	reb_configure_box(r,boxsize,1,1,1);

	// Setup particles
	double disc_mass = 2e-1;	// Total disc mass
	int N = 2000;			// Number of particles
	// Initial conditions
	struct reb_particle star = {0};
	star.m 		= 1;
	reb_add(r, star);
	for (int i=0;i<N;i++){
		struct reb_particle pt = {0};
		double a	= reb_random_powerlaw(boxsize/10.,boxsize/2./1.2,-1.5);
		double phi 	= reb_random_uniform(0,2.*M_PI);
		pt.x 		= a*cos(phi);
		pt.y 		= a*sin(phi);
		pt.z 		= a*reb_random_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(r->G*mu/a);
		pt.vx 		=  vkep * sin(phi);
		pt.vy 		= -vkep * cos(phi);
		pt.vz 		= 0;
		pt.m 		= disc_mass/(double)N;
		reb_add(r, pt);
	}

	reb_integrate(r, 1.0);
	reb_free_simulation(r);
}
예제 #5
0
파일: problem.c 프로젝트: SeanBE/rebound
int main(int argc, char* argv[]){
	struct reb_simulation* const r = reb_create_simulation();
	// Setup constants
	r->integrator	= REB_INTEGRATOR_LEAPFROG;
	r->gravity	= REB_GRAVITY_TREE;
	r->boundary	= REB_BOUNDARY_OPEN;
	r->opening_angle2	= 1.5;		// This constant determines the accuracy of the tree code gravity estimate.
	r->G 		= 1;		
	r->softening 	= 0.02;		// Gravitational softening length
	r->dt 		= 3e-2;		// Timestep
	const double boxsize = 10.2;
    // Setup root boxes for gravity tree.
    // Here, we use 2x2=4 root boxes (each with length 'boxsize')
    // This allows you to use up to 4 MPI nodes.
	reb_configure_box(r,boxsize,2,2,1);

    // Initialize MPI
    // This can only be done after reb_configure_box.
    reb_mpi_init(r);

	// Setup particles only on master node
    // In the first timestep, the master node will 
    // distribute particles to other nodes. 
    // Note that this is not the most efficient method
    // for very large particle numbers.
    double disc_mass = 2e-1/r->mpi_num;	// Total disc mass
    int N = 10000/r->mpi_num;			// Number of particles
    // Initial conditions
    struct reb_particle star = {0};
    star.m 		= 1;
    if (r->mpi_id==0){
        reb_add(r, star);
    }
    for (int i=0;i<N;i++){
        struct reb_particle pt = {0};
        double a	= reb_random_powerlaw(boxsize/10.,boxsize/2./1.2,-1.5);
        double phi 	= reb_random_uniform(0,2.*M_PI);
        pt.x 		= a*cos(phi);
        pt.y 		= a*sin(phi);
        pt.z 		= a*reb_random_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(r->G*mu/a);
        pt.vx 		=  vkep * sin(phi);
        pt.vy 		= -vkep * cos(phi);
        pt.vz 		= 0;
        pt.m 		= disc_mass/(double)N;
        reb_add(r, pt);
    }
	r->heartbeat = heartbeat;

#ifdef OPENGL
    // Hack to artificially increase particle array.
    // This cannot be done once OpenGL is activated. 
    r->allocatedN *=8;
    r->particles = realloc(r->particles,sizeof(struct reb_particle)*r->allocatedN);
#endif // OPENGL
    
	// Start the integration
    reb_integrate(r, INFINITY);

    // Cleanup
    reb_mpi_finalize(r);
    reb_free_simulation(r); 
}
예제 #6
0
int main(int argc, char* argv[]) {
    int np = 20;
    omp_set_num_threads(np);
    FILE *fp2;
    char hash_name[] = "hash.csv";
    fp2 = fopen(hash_name, "w+");
    fprintf(fp2, "Hash, Mass, Radius\n");
    char filename[512] = "veras_no_frag.bin";
    // Trying to restart from the Simulation Archive.
    struct reb_simulation* r = reb_create_simulation_from_simulationarchive(filename);
    printf("Loaded Simulation Successfully\n");
    printf("Time is: %.16f\n", r->t);
    printf("N_active is: %i\n", r->N);
    printf("Timestep is: %.3f\n", r->dt);
    r->heartbeat	= heartbeat;
    r->dt = 10.0;
    r->gravity = REB_GRAVITY_TREE;
    r->integrator = REB_INTEGRATOR_WHFAST;
    r->collision = REB_COLLISION_TREE;
    r->boundary     = REB_BOUNDARY_OPEN;
    const double boxsize = 2.5e10; // about 0.15 AU, with fragments at 0.0054 AU
    reb_configure_box(r,boxsize,1,1,1);
    struct rebx_extras* rebx = rebx_init(r);
    /*
    struct rebx_effect* rad_params = rebx_add(rebx, "radiation_forces");
    double* c = rebx_add_param(rad_params, "c", REBX_TYPE_DOUBLE);
    *c = 3.e8;                          // speed of light in SI units    */


    struct reb_particle* wd = reb_get_particle_by_hash(r, reb_hash("wd"));
    int wd_index = reb_get_particle_index(wd);
    /*
    int* rad_source = rebx_add_param(&r->particles[wd_index], "radiation_source", REBX_TYPE_INT);
    *rad_source = 1;    */


    struct rebx_effect* gr_params = rebx_add(rebx, "gr");
    double* c_2 = rebx_add_param(gr_params, "c", REBX_TYPE_DOUBLE);
    *c_2 = 3.e8;
    int* source = rebx_add_param(&r->particles[wd_index], "gr_source", REBX_TYPE_INT);
    *source = 1;
    double wd_rad = wd->r;
    double disk_rad_in = 10.0*wd_rad;
    double disk_rad_out = 90.0*wd_rad;
    printf("Inner disk radius is: %f AU\n", disk_rad_in/1.496e11);
    printf("Outer disk radius is: %f AU\n", disk_rad_out/1.496e11);
    int N_disk = 2000;
    double disk_inc_low = 0.0;
    double disk_inc_high = 0.0;
    double e_low = 0.0;
    double e_high = 0.0;
    r->N_active = r->N;
    double* add_beta;
    while(r->N<N_disk + r->N_active){
        struct reb_particle pt = {0};
        double a = reb_random_uniform(disk_rad_in, disk_rad_out);
        double e = reb_random_uniform(e_low, e_high);
        double inc = reb_random_uniform(disk_inc_low, disk_inc_high);
        double Omega = reb_random_uniform(0, 2.*M_PI);
        double apsis = reb_random_uniform(0, 2.*M_PI);
        double phi = reb_random_uniform(0.0, 2.*M_PI);
        pt = reb_tools_orbit_to_particle(r->G, r->particles[wd_index], 0.0, a, e, inc, Omega, apsis, phi);
        int N_count = r->N - r->N_active;
        pt.hash = N_count + 8000;
        reb_add(r, pt);
        add_beta = rebx_add_param(&r->particles[N_count], "beta", REBX_TYPE_DOUBLE);
        *add_beta = 0.01;
    }
    r->simulationarchive_interval = 6.32e6;
    char sim_name[1000];
    filename[strlen(filename) - 4] = 0;
    sprintf(sim_name, "%s_months.bin", filename);
    r->simulationarchive_filename = sim_name;

    for (int i=0; i < r->N; i=i+1){
        fprintf(fp2, "%u, %f, %f\n", r->particles[i].hash, r->particles[i].m, r->particles[i].r);
     }
    fclose(fp2);
    reb_integrate(r, 1.6e8); // ~5 years
    rebx_free(rebx);
}
예제 #7
0
int main(int argc, char* argv[]){
	struct reb_simulation* r = reb_create_simulation();
	// Setup constants
	r->dt 			= 1e-1;	
	r->gravity		= REB_GRAVITY_NONE;
	r->integrator		= REB_INTEGRATOR_LEAPFROG;
	r->collision		= REB_COLLISION_TREE;
	r->boundary		= REB_BOUNDARY_PERIODIC;
	// Override default collision handling to account for border particles
	r->collision_resolve	 = collision_resolve_hardsphere_withborder;
	r->heartbeat		= heartbeat;
	reb_configure_box(r, 20., 1, 1, 4);
	
	r->nghostx = 1; r->nghosty = 1; r->nghostz = 0; 	
	
	double N_part 	= 0.00937*r->boxsize.x*r->boxsize.y*r->boxsize.z;

	// Add Border Particles
	double radius 		= 1;
	double mass		= 1;
	double border_spacing_x = r->boxsize.x/(floor(r->boxsize.x/radius/2.)-1.);
	double border_spacing_y = r->boxsize.y/(floor(r->boxsize.y/radius/2.)-1.);
	struct reb_particle pt = {0};
	pt.r 		= radius;
	pt.m 		= mass;
	pt.id		= 1;
	for(double x = -r->boxsize.x/2.; x<r->boxsize.x/2.-border_spacing_x/2.;x+=border_spacing_x){
		for(double y = -r->boxsize.y/2.; y<r->boxsize.y/2.-border_spacing_y/2.;y+=border_spacing_y){
			pt.x 		= x;
			pt.y 		= y;
			
			// Add particle to bottom
			pt.z 		= -r->boxsize.z/2.+radius;
			pt.vy 		= 1;
			reb_add(r, pt);

			// Add particle to top
			pt.z 		= r->boxsize.z/2.-radius;
			pt.vy 		= -1;
			reb_add(r, pt);
		}
	}

	N_border = r->N;
	
	// Add real particles
	while(r->N-N_border<N_part){
		struct reb_particle pt = {0};
		pt.x 		= reb_random_uniform(-r->boxsize.x/2.,r->boxsize.x/2.);
		pt.y 		= reb_random_uniform(-r->boxsize.y/2.,r->boxsize.y/2.);
		pt.z 		= 0.758*reb_random_uniform(-r->boxsize.z/2.,r->boxsize.z/2.);
		pt.vx 		= reb_random_normal(0.001);
		pt.vy 		= reb_random_normal(0.001);
		pt.vz 		= reb_random_normal(0.001);
		pt.r 		= radius;						// m
		pt.m 		= 1;
		pt.id		= 2;
		reb_add(r, pt);
	}

	reb_integrate(r, INFINITY);
}