Beispiel #1
0
void heartbeat(struct reb_simulation* sim){
    if(reb_output_check(sim, 1.e8)){
        const struct reb_particle* particles = sim->particles;
        const struct reb_particle saturn = particles[1];
        const double t = sim->t;
        struct reb_orbit orbit = reb_tools_particle_to_orbit(sim->G, sim->particles[2], saturn); /* calculate orbit of particles[2] around Saturn */
        double e2 = orbit.e;
        orbit = reb_tools_particle_to_orbit(sim->G, sim->particles[3], saturn); 
        double e3 = orbit.e;
        printf("%e\t%f\t%f\n", t, e2, e3);

    }
}
Beispiel #2
0
void heartbeat(struct reb_simulation* r){
	if(reb_output_check(r, 4000.*r->dt)){				// output something to screen	
		reb_output_timing(r, tmax);
	}
	if(reb_output_check(r,M_PI*2.*0.01)){				// output semimajor axis to file
		FILE* f = fopen("a.txt","a");
		const struct reb_particle planet = r->particles[0];
		const int N = r->N;
		for (int i=1;i<N;i++){
			struct reb_orbit o = reb_tools_particle_to_orbit(r->G, r->particles[i],planet);
			fprintf(f,"%.15e\t%.15e\t%.15e\t%.15e\n",r->t,o.a,o.e,o.omega);
		}
		fclose(f);
	}
}
Beispiel #3
0
void reb_output_orbits(struct reb_simulation* r, char* filename){
	const int N = r->N;
#ifdef MPI
	char filename_mpi[1024];
	sprintf(filename_mpi,"%s_%d",filename,r->mpi_id);
	FILE* of = fopen(filename_mpi,"a"); 
#else // MPI
	FILE* of = fopen(filename,"a"); 
#endif // MPI
	if (of==NULL){
		reb_exit("Can not open file.");
	}
	struct reb_particle com = r->particles[0];
	for (int i=1;i<N;i++){
		struct reb_orbit o = reb_tools_particle_to_orbit(r->G, r->particles[i],com);
		fprintf(of,"%e\t%e\t%e\t%e\t%e\t%e\t%e\t%e\t%e\n",r->t,o.a,o.e,o.inc,o.Omega,o.omega,o.l,o.P,o.f);
		com = reb_get_com_of_pair(com,r->particles[i]);
	}
	fclose(of);
}
Beispiel #4
0
void reb_display(void){
	if (reb_dc.pause){
		return;
	}
	sem_wait(reb_dc.mutex);	
	const struct reb_particle* particles = reb_dc.r->particles;
	if (reb_dc.clear){
	        glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
	}
	glEnable(GL_POINT_SMOOTH);
	glVertexPointer(3, GL_DOUBLE, sizeof(struct reb_particle), particles);
	//int _N_active = ((N_active==-1)?N:N_active);
	if (reb_dc.reference>=0){
		glTranslatef(-particles[reb_dc.reference].x,-particles[reb_dc.reference].y,-particles[reb_dc.reference].z);
	}
	for (int i=-reb_dc.ghostboxes*reb_dc.r->nghostx;i<=reb_dc.ghostboxes*reb_dc.r->nghostx;i++){
	for (int j=-reb_dc.ghostboxes*reb_dc.r->nghosty;j<=reb_dc.ghostboxes*reb_dc.r->nghosty;j++){
	for (int k=-reb_dc.ghostboxes*reb_dc.r->nghostz;k<=reb_dc.ghostboxes*reb_dc.r->nghostz;k++){
		struct reb_ghostbox gb = reb_boundary_get_ghostbox(reb_dc.r, i,j,k);
		glTranslatef(gb.shiftx,gb.shifty,gb.shiftz);
		if (!(!reb_dc.clear&&reb_dc.wire)){
			if (reb_dc.spheres==0 || reb_dc.spheres==2){
				// Drawing Points
				glEnableClientState(GL_VERTEX_ARRAY);
				glPointSize(3.);
				glColor4f(1.0,1.0,1.0,0.5);
				//glDrawArrays(GL_POINTS, _N_active, N-_N_active);
				glColor4f(1.0,1.0,0.0,0.9);
				glPointSize(5.);
				glDrawArrays(GL_POINTS, 0, reb_dc.r->N-reb_dc.r->N_var);
				glDisableClientState(GL_VERTEX_ARRAY);
			}
			if (reb_dc.spheres){
				glDisable(GL_BLEND);                    
				glEnable(GL_DEPTH_TEST);
				glEnable(GL_LIGHTING);
				glEnable(GL_LIGHT0);
				GLfloat lightpos[] = {0, reb_dc.r->boxsize_max, reb_dc.r->boxsize_max, 0.f};
				glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
				// Drawing Spheres
				glColor4f(1.0,1.0,1.0,1.0);
				for (int i=0;i<reb_dc.r->N-reb_dc.r->N_var;i++){
					struct reb_particle p = particles[i];
					if (p.r>0){
						glTranslatef(p.x,p.y,p.z);
						glScalef(p.r,p.r,p.r);
#ifdef _APPLE
						glCallList(reb_dc.dlist_sphere);
#else //_APPLE
						glutSolidSphere(1,40,10);
#endif //_APPLE
						glScalef(1./p.r,1./p.r,1./p.r);
						glTranslatef(-p.x,-p.y,-p.z);
					}
				}
				glEnable(GL_BLEND);                    
				glDisable(GL_DEPTH_TEST);
				glDisable(GL_LIGHTING);
				glDisable(GL_LIGHT0);
			}
		}
		// Drawing wires
		if (reb_dc.wire){
			if(reb_dc.r->integrator!=REB_INTEGRATOR_SEI){
				double radius = 0;
				struct reb_particle com = particles[0];
				for (int i=1;i<reb_dc.r->N-reb_dc.r->N_var;i++){
					struct reb_particle p = particles[i];
					if (reb_dc.r->N_active>0){
						// Different colors for active/test particles
						if (i>=reb_dc.r->N_active){
							glColor4f(0.9,1.0,0.9,0.9);
						}else{
							glColor4f(1.0,0.9,0.0,0.9);
						}
					}else{
						// Alternating colors
						if (i%2 == 1){
							glColor4f(0.0,1.0,0.0,0.9);
						}else{
							glColor4f(0.0,0.0,1.0,0.9);
						}
					}
					//if (reb_dc.r->integrator==REB_INTEGRATOR_WHFAST && reb_dc.r->ri_whfast.is_synchronized==0){
					//	double m = p.m;
					//	p = reb_dc.r->ri_whfast.p_j[i];
					//	p.m = m;
					//}
					struct reb_orbit o = reb_tools_particle_to_orbit(reb_dc.r->G, p,com);
					glPushMatrix();
					
					glTranslatef(com.x,com.y,com.z);
					glRotatef(o.Omega/DEG2RAD,0,0,1);
					glRotatef(o.inc/DEG2RAD,1,0,0);
					glRotatef(o.omega/DEG2RAD,0,0,1);
					
					glBegin(GL_LINE_LOOP);
					for (double trueAnom=0; trueAnom < 2.*M_PI; trueAnom+=M_PI/100.) {
						//convert degrees into radians
						radius = o.a * (1. - o.e*o.e) / (1. + o.e*cos(trueAnom));
						glVertex3f(radius*cos(trueAnom),radius*sin(trueAnom),0);
					}
					glEnd();
					glPopMatrix();
					com = reb_get_com_of_pair(p,com);
				}
			}else{
				for (int i=1;i<reb_dc.r->N;i++){
					struct reb_particle p = particles[i];
					glBegin(GL_LINE_LOOP);
					for (double _t=-100.*reb_dc.r->dt;_t<=100.*reb_dc.r->dt;_t+=20.*reb_dc.r->dt){
						double frac = 1.-fabs(_t/(120.*reb_dc.r->dt));
						glColor4f(1.0,(_t+100.*reb_dc.r->dt)/(200.*reb_dc.r->dt),0.0,frac);
						glVertex3f(p.x+p.vx*_t, p.y+p.vy*_t, p.z+p.vz*_t);
					}
					glEnd();
				}
			}
		}
		glTranslatef(-gb.shiftx,-gb.shifty,-gb.shiftz);
	}
	}
	}
	glColor4f(1.0,0.0,0.0,0.4);
	glScalef(reb_dc.r->boxsize.x,reb_dc.r->boxsize.y,reb_dc.r->boxsize.z);
	if (reb_dc.r->boundary == REB_BOUNDARY_NONE){
		glBegin(GL_LINES);
		glVertex3f(0,0,0.04);
		glVertex3f(0,0,-0.04);
		glVertex3f(0,0.04,0);
		glVertex3f(0,-0.04,0);
		glVertex3f(0.04,0,0);
		glVertex3f(-0.04,0,0);
		glEnd();

	}else{
		glutWireCube(1);
	}
	glScalef(1./reb_dc.r->boxsize.x,1./reb_dc.r->boxsize.y,1./reb_dc.r->boxsize.z);
	if (reb_dc.reference>=0){
		glTranslatef(particles[reb_dc.reference].x,particles[reb_dc.reference].y,particles[reb_dc.reference].z);
	}
	glFlush();
	sem_post(reb_dc.mutex);	
}