gravitytest1.c (C++ version gravitytest1.cpp) shell program of a sequential (non-parallel) version of the n-body algorithm using 3 particles. Here's a version using 2 particles, gravity2.c. These are C and C++ versions adapted for our class from these two UNC sites: N-body particle system and BSP N-body particle system
An array of particle objects is used with:
The particles initial velocities particle.vx and particle.vy are 0 (these represent the velocities in the x and y directions. The mass of each particle is 100000000. The initial x,y location of the 3 particles (particle.px and particle.py) are (0,0), (0,5.0), (2.5, 4.33) - points in the shape roughly of an equalateral triangle. The program runs for 100 time steps.
Plot for gravity3.c, 100 time steps, 3 particles initially at (0,0),(0,5), (2.5,4.33):
Plot for gravity2.c, 180 time steps, 2 particles initially at (0,0) and (5,5):
For example, to help you start try gravitytestOrbitC.c: Mass 1 at (0,0) has mass 100000000, Mass 2 at (0,5) has mass 100 and an initial y velocity of 0.04. Run this for 1200 time steps. ./a.out > orbit1.out. In gnuplot use:
gnuplot> set xrange [-10:10]; gnuplot> set yrange [-10:10]; gnuplot> plot 'orbit1.out' using 1:2, 'orbit1.out' using 3:4;You should get an image such as:
gravitytestOpengl.c or gravitytestOpengl.cpp Use the following to compile this OpenGL program (C version):
./lgcc gravitytest1Opengl.c ./a.out Here's the file for lgcc: #!/bin/sh gcc $1 -lm -L/usr/lib -lGLU -lGL -lglut -L/usr/X11R6/lib -lX11 -lXext -lXi -lXmu Use chmod 755 lgcc inorder to make this executable
For the CPP version use:
./lg++ gravitytest1Opengl.cpp ./a.out Here's the file for lg++: #!/bin/sh g++ $1 -lm -L/usr/lib -lGLU -lGL -lglut -L/usr/X11R6/lib -lX11 -lXext -lXi -lXmu Use chmod 755 lg++ inorder to make this executable
(1,3), (4,3), (2.5, 3.6) - first triangle pattern
(6,3), (9,3), (7.5, 3.6) - second triangle pattern
Use the following Gnuplot commands:
gnuplot> set xrange[-1:10]; gnuplot> set yrange[-1:10]; gnuplot> plot 'gravity7.out' using 1:2, 'gravity7.out' using 3:4, \ > 'gravity7.out' using 5:6, 'gravity7.out' using 7:8, \ > 'gravity7.out' using 9:10, 'gravity7.out' using 11:12;
The image should look like: