This repo contains my final project for the Introduction to Computational Physics class with Professor Hy Trac for the academic year 20/21 at Carnegie Mellon University.
N-body simulations are used to solve the dynamics of a system of particles, commonly known as the many-body problem. Particles that interact with one another through a force can be solved analytically for a low number of bodies. A simple binary star system can be solved analytically with Newtons equations and is a common exercise for high school physics students. Upon adding another body, say a planet, the exercise becomes quite more difficult. If we wanted to study a system of millions of bodies, an anlytical approach is simply not feasible. This is where N-body algorithms have helped progress out understanding of complex many-body systems.
In this project, I use a particle mesh (PM) method. A typical approach woould be to use a particle-particle (PP) method, where the net force on a given particle is calculated by directly summing the pairwise force from all of its neighbors. In the PM method, particles are mapped onto a "mesh" and Poisson's equation for gravity is solved using Fast Fourier Transforms (FFT). The benefit of the PM method is that it is O(N*logN), where as the PP method is O(N^2), making a faster, but less accurate method.
Considering a system of N particles with fixed mass m, for each particle we evolve its position x and velocity v using Newton's equations:
Newton's 2nd law gives us a relation between the force per unit mass and the gravitational potential:
Using Poisson's equation we can then relate the gravitational potential
whose general solution is a convolution. The efficiency of the PM method is from solving Poisson's equation in Fourier space given by:
where the transformed kernel