Writing N-body gravity simulations code in Python
alvinng4.github.io
Writing N-body gravity simulations code in Python
1–10 of 51 posts
Re: Writing N-body gravity simulations code in Python
#2Re: Writing N-body gravity simulations code in Python
#3For a few-body system (e.g., the Solar System) this probably won't provide any speedup. But once you get to ~100 bodies you should start to see substantial speedups by running the simulator on a GPU.
Re: Writing N-body gravity simulations code in Python
#4Re: Writing N-body gravity simulations code in Python
#5Edit: To answer myself, I think this is because one of the factors is to normalize the vector between the two bodies to length 1, and the other two factors are the standard inverse square relationship.
Re: Writing N-body gravity simulations code in Python
#6Re: Writing N-body gravity simulations code in Python
#7Once you have the matrix implementation in Step 2 (Implementation 3) it's rather straightforward to extend your N-body simulator to run on a GPU with Jax --- you can just add `import jax.numpy as jnp` and replace all the `np.`s with `jnp`s. For a few-body system (e.g., the Solar System) this probably won't provide any speedup. But once you get to ~100 bodies you should start to see substantial speedups by running the…
For the programmer, yes it is easy enough.
But there is a lot of complexity hidden behind that change. If you care about how your tools work that might be a problem (I'm not judging).
Re: Writing N-body gravity simulations code in Python
#8Re: Writing N-body gravity simulations code in Python
#9Every time I see anything on the N-Body problem I am reminded by my final high school project... I had 2-3 weeks of time to write an n-body simulation. Back then I used C++ and my hardware was really bad (2 GHz single core CPU or so…). The result was not really impressive because it did not really work. :D But I was able to show that my code correctly predicted that the moon and the earth would eventually collide wit…
laughs in 32kb of RAM
Sounds like a great project, though. There's a lot of fundamental concepts involved in something like this, so it's a great learning exercise (and fun as well!) :)