Nbody Simulation

3H Computing Project

Martin Woodward

Animated GIF of Nbody Simulation

As part of my 3H Computing Project I was set the task of modelling the gravitation forces produced from 500 individual particles using the basic newtonian laws of gravity. The calculation process works by setting up the particles with a random distribution in a sphere and then working out the force exerted by each particle due to another particles.

Using Newtonian mechanics it is possible to work out the force on a single particle due to another particle but is extreamly difficult to take another particle into account. Therefore the program works by taking pairs of particles and then working out the vector sum of all the forces.

Obviously this is very computationally intensive when the number of particles is large. A neat trick to reduce the number of calculations by half is by using Newton's third law "For every action there is an equal but opposite reaction" so that once you have worked out the force on partcle X due to partcle Y you know what the force is exerted on particle Y from particle X.

The result of the program is displayed above in the form of an animated GIF file which some older browsers may have a problem viewing.

The density of the sphere is shown in the graph below for each time step shown in the animated graph above.

A plot of density as a function of distance form the origin

This simulation took ten hours to run as an overnight job on the main time-sharing UNIX machine here in Durham.


This page was written by Martin Woodward