I made an N-body simulation program

In summary, the programmer has created a program that solves the three-body gravity problem. later, they gained an interest in the underlying physics and expanded the program to solve problems involving both electromagnetic and gravitational interactions.
  • #1
My little project - 3body simulator started as a programming exercise, which I attempted to make a program that solves the famous 3-body gravity problem using numerical integration.
Later I gained interest in the underlying physics and expanded the program to solve N-body problems involving both electromagnetic and gravitational interactions. I also replaced Newtonian mechanics with special relativistic mechanics (as for the model of gravity, general relativity is too challenging for me, so I used an approximation under the weak field limit which was Lorentz-invariant).
You can do all sorts of weird simulation such as the following:

Object 1 (e-) and object 2 (p+) form a hydrogen atom under the classical Bohr's model, with n = 10; object 3 is a hypothetical microscopic blackhole with the mass of the Moon, placed 10 mm under the hydrogen atom.

Object 1:
mass: 9.11e-31 / charge: -1.60e-19
position: 5.29e-9,0,0 / velocity: 0,218500,0

Object 2:
mass: 1.67e-27 / charge: 1.60e-19
position: 0,0,0 / velocity: 0,0,0

Object 3:
mass: 7.35e22 / charge: 0
position: 0,0,-0.01 / velocity: 0,0,0

Duration of simulation: 1e-12 / number of steps: 1000
-> Use advanced option and turn on scientific notation (to show the position of the electron)

(Note: the Schwarzschild radius of the blackhole is about 0.11mm (<<10mm), so general relativistic effects like gravitational time dilation are insignificant.)

Please try out my little program and you comments are appreciated!
  • Like
Likes davyzhu, Bandersnatch, vanhees71 and 4 others
Phys.org - latest science and technology news stories on Phys.org
  • #2

Congratulation. I did an N-body simulation (yours is N=3) some time ago. It is really not easy nor it is dead, in my eyes. Perhaps you are interested in the following material: N-Body

Have fun!
  • Like
Likes aaroman and vanhees71
  • #3
Great work @Random Physics Fan and @Omega0

While I can't comment on the accuracy of your simulations, from a programming standpoint, I'm sure others can benefit from what you folks did.

As an aside, there are also some good simulations at the Open Source Physics website done in Java using the OSP library of simulation routines.


And with that said, its a good time to close this thread.


1. What is an N-body simulation program?

An N-body simulation program is a computer program that simulates the movement and interactions of multiple objects, or bodies, in a physical system. These bodies can represent anything from stars and planets in a galaxy to molecules in a chemical reaction. The program uses mathematical equations and algorithms to calculate the positions and velocities of each body over time.

2. How does an N-body simulation program work?

An N-body simulation program works by using Newton's laws of motion and the law of universal gravitation to calculate the forces between each body in the system. These forces are then used to update the positions and velocities of the bodies at each time step, allowing the simulation to progress and show the movement and interactions of the bodies over time.

3. What can an N-body simulation program be used for?

An N-body simulation program can be used for a variety of purposes, including studying the dynamics of celestial bodies, modeling the behavior of particles in a physical system, and predicting the outcome of complex interactions between multiple objects. It is commonly used in fields such as astrophysics, cosmology, and molecular dynamics.

4. What are the limitations of an N-body simulation program?

One limitation of an N-body simulation program is the computational power required to accurately model large numbers of bodies. As the number of bodies increases, the time and resources needed to run the simulation also increase. Additionally, the accuracy of the simulation may be affected by simplifications and assumptions made in the mathematical equations used.

5. How can I create my own N-body simulation program?

To create your own N-body simulation program, you will need a strong understanding of physics and mathematical concepts such as Newton's laws of motion and the law of universal gravitation. You will also need to be proficient in a programming language, such as C++ or Python, to write the code for the simulation. There are also existing N-body simulation software packages available that you can customize for your specific needs.

Suggested for: I made an N-body simulation program