/************************************************************************ Program name: Nbody Description: This program does the main Nbody computations,it takes the number of particles whose orbits is being calculated, calls the acceleration subroutine to calculate the subsequent position using the leap frog integration scheme. Output:Returns 0 if successful Input:none *************************************************************************/ #include #include #include #include #include /*define the number of particle*/ #define N 2 /*define the mass of the system in grams*/ #define MASS 2.0e+3 /*define the radius of the system in cm*/ #define RADIUS 10 /*define the number of orbits of the system*/ #define ORBIT 1 /*define the time resolution of the problem*/ #define TIME 1e-2 /*Universal gravitational constant*/ #define G 6.67e-8 /*dimensions in the problem*/ #define DIM 2 double fAccel(double*,double,double*,int); int main() { double dTotTime,dParticleMass,dTimeinc; int iTimeSteps; dParticleMass=MASS/N; double dAccelGravity[N]={0.0}; FILE * fp1; FILE * fp2; FILE * accfp; /*loop variables*/ int i,j,k,iCount; dTotTime=1/(sqrt(G*MASS/pow(RADIUS,3))); /*the total time steps is how many time stamps the system will take, this will be higher if the time resolution of the system is smaller*/ iTimeSteps=20; dTimeinc=dTotTime/(double)iTimeSteps; /*dummy variable used inside the loop to pass values as * a vector to the acceleration subroutine*/ double dPosition[DIM],dOtherPosition[DIM]; /*variables to store the x and y values over varying time * steps of N particles*/ double dPositionkx[iTimeSteps][N]; double dPositionky[iTimeSteps][N]; /*initial x and y positions of the particles at time -1 * for particle 0 and particle 1, they are placed in * opposite ends of the cooridinate system*/ dPositionkx[0][0]=-10; dPositionkx[0][1]=10; dPositionky[0][0]=0; dPositionky[0][1]=0; /*x and y positiions at time =0*/ dPositionkx[1][0]=-9.996; dPositionkx[1][1]=9.996; dPositionky[1][0]=0.04; dPositionky[1][1]=-0.04; fp1=fopen("particle1.dat","w+"); fp2=fopen("particle2.dat","w+"); accfp=fopen("accel.dat","w+"); /*the for loop that does the time integration and calculates particle positions for each time step*/ for(k=2;k