Esempio n. 1
0
EditorState *
initialize(int *argc, char **argv[]) {
	gtk_init(argc, argv);

	FileContainer* file_container = read_file((*argv)[1]);

	load_css("/home/lee/dev/src/tyreese/styles/style.css");

	/* INITIALIZE COMPONENTS */
	GtkWidget *main_window = init_window(file_container);
	GtkBox *horizontal_box = init_box(GTK_ORIENTATION_HORIZONTAL, TRUE);
	GtkBox *vertical_box = init_box(GTK_ORIENTATION_VERTICAL, FALSE);
	
	GtkEntry *tag = init_tag();

	GtkContainer *scroll_container = GTK_CONTAINER(init_scroll_container());
	GtkSourceBuffer *source_buffer = init_buffer(file_container);
	GtkSourceView *source_view = init_buffer_view(source_buffer);
	GtkSourceSearchSettings *search_settings = gtk_source_search_settings_new();
	gtk_source_search_settings_set_regex_enabled (search_settings, TRUE);

	/* PACK COMPONENTS */
	gtk_container_add(scroll_container, GTK_WIDGET(source_view));
	gtk_box_pack_start(vertical_box, GTK_WIDGET(tag), FALSE, FALSE, 0);
	gtk_box_pack_start(vertical_box, GTK_WIDGET(scroll_container), TRUE, TRUE, 0);
	gtk_widget_set_size_request(GTK_WIDGET(main_window), 480, 768-24);
	gtk_box_pack_start(horizontal_box, GTK_WIDGET(vertical_box), TRUE, TRUE, 0);
	gtk_container_add(GTK_CONTAINER(main_window), GTK_WIDGET(horizontal_box));
	gtk_widget_grab_focus(GTK_WIDGET(source_view));

	/* INITIALIZE EDITOR STATE */
	EditorState *editor_state = malloc(sizeof(EditorState));
	editor_state->root = main_window;
	editor_state->view = source_view;
	editor_state->buffer = source_buffer;
	editor_state->search.settings = search_settings;
	editor_state->search.context = NULL;
	editor_state->mode = NO_MODE;
	editor_state->tag = tag;
	editor_state->fc = file_container;
	
	/* BIND EVENTS */
	g_signal_connect(editor_state->root, "destroy", G_CALLBACK(gtk_main_quit), NULL);
	g_signal_connect(editor_state->root, "key-press-event", G_CALLBACK(window_key_press), editor_state);
	g_signal_connect(editor_state->tag, "key-press-event", G_CALLBACK(tag_key_press), editor_state);
	
	return editor_state;
}
Esempio n. 2
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
	}
}
Esempio n. 3
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);
	}
}
Esempio n. 4
0
//box *get_next_box(unsigned char *mem, long int *pos) {
box *get_next_box(FILE *fd) {
	println_start(INFO);
	//box *box = malloc(sizeof(box));

	int read = 0;
	box *box = init_box();

	if( (box->lbox = read_bytes(box->lbox, fd, 4)) == NULL)
		return NULL;

	box->length = hex_to_long(box->lbox, 4);
	if(box->length == 0) {
		return NULL;
	}

	if( (box->tbox = read_bytes(box->tbox, fd, 4)) == NULL) {
		println(INFO, "Corrupted JP2 file. Exitting.");
		return NULL;
	}
	read = 8;

	if(box->length == 1) { //there should be XLbox field present;
		box->xlbox = (unsigned char*)malloc(9 * sizeof(char));
		box->xlbox = read_bytes(box->xlbox, fd, 8);
		box->length = hex_to_long(box->xlbox, 8);
		read += 8;
	}
	box->content_length = box->length - read;

	box->dbox = (unsigned char*)malloc((box->content_length + 1) * sizeof(char));
	box->dbox = read_bytes(box->dbox, fd, box->content_length);
	println_end(INFO);
	return box;
}
Esempio n. 5
0
void problem_init(int argc, char* argv[]){
	// Setup constants
	G 		= 1;		

	// Setup particles
	int _N = 100; 			// Number of particles
	double M = 1;			// Total mass of the cluster
	double R = 1;			// Radius of the cluster
	double E = 3./64.*M_PI*M*M/R;	// Energy of the cluster
	double r0 = 16./(3.*M_PI)*R;	// Chacateristic length scale
	double t0 = G*pow(M,5./2.)*pow(4.*E,-3./2.)*(double)_N/log(0.4*(double)_N); // Rellaxation time
	printf("Characteristic size:              %f\n", r0);
	printf("Characteristic time (relaxation): %f\n", t0);

	dt 		= 1e-4*t0; 	// timestep
	tmax		= 20.*t0;	// Integration time
	boxsize 	= 20.*r0;	// Size of box (open boundaries)
	softening 	= 0.01*r0;	// Softening parameter

	init_box();			// Set up box (uses variable 'boxsize')
	
	tools_init_plummer(_N, M, R);	// Add particles
	
	tools_move_to_center_of_momentum(); // Move to rest frame 
}
Esempio n. 6
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);
	
}
Esempio n. 7
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);
}
Esempio n. 8
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;
		}
	}
}
Esempio n. 9
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;
	}
}
Esempio n. 10
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
}
Esempio n. 11
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;
	}
}
Esempio n. 12
0
 explicit GridSpec(
     const ndarray<real_t, 2> position,
     const real_t scale) :
     n_dim_  (n_dim),
     scale	(scale),
     box		(init_box(position)),
     shape	(init_shape()),
     zeros   (init_zeros()),
     strides	(init_strides())
 {
 }
Esempio n. 13
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;
	}
}
Esempio n. 14
0
void
fz_layout_html(fz_context *ctx, fz_html *box, float w, float h, float em)
{
	fz_html page_box;

	init_box(ctx, &page_box);
	page_box.w = w;
	page_box.h = 0;

	layout_block(ctx, box, &page_box, em, 0, h);
}
Esempio n. 15
0
pedphrase * init_phrase(pedphrase * phrase) {
	pedphrase * newphrase;
	if (phrase == NULL)
	        newphrase = (pedphrase *)malloc (sizeof(pedphrase));
	else
		newphrase = phrase;
	newphrase->chars = init_list(NULL);
	newphrase->length = 0;
	newphrase->phrasebox = init_box(NULL);
	newphrase->font = NULL;
	newphrase->dir = PEDDIRECT_UNSET;
	return newphrase;
}
Esempio n. 16
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");	
}
Esempio n. 17
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);
	}
}
Esempio n. 18
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);
	}
}
Esempio n. 19
0
peddoc * init_doc(peddoc * doc, char * docname) {
	peddoc * newdoc;
	int strl;
	if (doc == NULL)
		newdoc = (peddoc *)malloc(sizeof(peddoc));
	else
		newdoc = doc;
	newdoc->pages = init_list(NULL);
	newdoc->docbox = init_box(NULL);
	newdoc->fontcache = init_font_cache(NULL);
	strl = strlen (docname);
	newdoc->docname = (char *)malloc(strl+1);
	strcpy(newdoc->docname,docname);
	newdoc->pagecounts = 0;
	newdoc->length = 0;
	return newdoc;
}
Esempio n. 20
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);
	}
}
Esempio n. 21
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);
	}
}
Esempio n. 22
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);
    }
}
Esempio n. 23
0
int axe_init(LIFE_S *self)
{
    DOTA_RETURN_IF_NULL(self, ERR_NULL_POINTER);

    /* 初始化链表头 */
    INIT_LIST_HEAD(&(self->buff_list));
    INIT_LIST_HEAD(&(self->life_list));

    self->kill_queue = queue_init(TMP_SIZE);
    if (!self->kill_queue)
        return ERR_MALLOC_FAILED;

    /* 把道具真正的装备上 */
    init_box(self);

    self->life_state = LIFE_RUNNING;
    return DOTA_OK;
}
Esempio n. 24
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);
	}
}
Esempio n. 25
0
int			main_option_client(t_global *global, t_xtree *tree)
{
  char			*hostname;

  global->scene = NULL;
  my_putstr("[*] Raytracer: Creation of the window ...");
  if ((global->window = obj_create_window(global, tree)) == NULL)
    return (my_puterror(" \033[31mFail !\033[0m\n"));
  my_putstr(" \033[32mDone !\033[00m\n");
  my_putstr("[*] Raytracer: Creation of the scene ...");
  if ((global->scene = obj_create_scene			\
       (tree, global->window->mlx_ptr)) == NULL)
    return (my_puterror(" \033[31mFail !\033[0m\n"));
  my_putstr(" \033[32mDone !\033[00m\n");
  hostname = ((t_client_info *)global->info.arg)->hostname;
  init_box(global->scene->object);
  if ((client_main(hostname, global->info.port)) == EXIT_FAILURE)
    return (EXIT_FAILURE);
  return (EXIT_SUCCESS);
}
Esempio n. 26
0
int		main_option_server(t_global *global, t_xtree *tree)
{
  global->scene = NULL;
  global->count_trame = 0;
  my_putstr("[*] Raytracer: Creation of the window ...");
  if ((global->window = obj_create_window(global, tree)) == NULL)
    return (my_puterror(" \033[31mFail !\033[0m\n"));
  my_putstr(" \033[32mDone !\033[00m\n");
  my_putstr("[*] Raytracer: Creation of the scene ...");
  if (!(global->scene = obj_create_scene(tree, global->window->mlx_ptr)))
    return (my_puterror(" \033[31mFail !\033[0m\n"));
  my_putstr(" \033[32mDone !\033[00m\n");
  init_box(global->scene->object);
  if ((server_main(global->info.port)) == EXIT_FAILURE)
    return (EXIT_FAILURE);
  mlx_key_hook(global->window->win_ptr, &event_key, global);
  mlx_expose_hook(global->window->win_ptr, &event_expose, global);
  mlx_loop(global->window->mlx_ptr);
  return (EXIT_SUCCESS);
}
Esempio n. 27
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);
	}
}
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
}
Esempio n. 29
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). 
}
Esempio n. 30
0
int main(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 reb_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;
	reb_add(r, star);
	while(N<_N){
		struct reb_particle pt;
		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(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;
		reb_add(r, pt);
	}
}