https://alvinng4.github.io/grav_sim/5_steps_to_n_body_simulation/ [ ] [ ] Skip to content logo grav_sim 5 steps to N-body simulation ( ) ( ) [ ] Initializing search alvinng4/grav_sim * Home * Getting started * Documentations * Examples * 5 steps to N-body simulation logo grav_sim alvinng4/grav_sim * [ ] Home Home + Getting started + Documentations + Examples + 5 steps to N-body simulation * [ ] Getting started Getting started + Installation in C + Installation in Python + Tutorial (Python) * [ ] Documentations Documentations + Integrators + Barnes-Hut algorithm + Comoving coordinates + Particle-Mesh algorithm + Massless acceleration + Output formats + Force Softening + Reducing round off error + Why C? + [ ] Python API Python API o GravitySimulatorAPI o Parameters o Plotting o System o Simulator o Utils + [ ] C API C API o Grav sim * [ ] Examples Examples + Evolving Solar system simulation for one million years + Asteroid belt animation + Formation of Kirkwood gaps + Galaxy collision + Cosmic Structure Formation * [*] 5 steps to N-body simulation 5 steps to N-body simulation + Step 1 + Step 2 + Step 3 + Step 4 + Step 5 + Extra + Conclusion 5 steps to N-body simulation This is a series of tutorials inspired by the course "CFD Python: 12 steps to Navier-Stokes". The goal is to teach beginners how to write fast and clean N-body gravity simulations code in Python. Although basic knowledge in Python and Calculus is assumed, everything is explained in detail so beginners should be able to follow along. After completing this tutorial, you would be able to write your own N-body simulation code in Python. At the end of the tutorial, you are encouraged to make your own project related to N-body simulation. How to use this tutorial? The source code for the python scripts and the markdown files are available on * https://github.com/alvinng4/grav_sim/tree/main/ 5_steps_to_n_body_simulation but I strongly recommend reading this tutorial on our website: * https://alvinng4.github.io/grav_sim/5_steps_to_n_body_simulation/ Snippets of the code will be shown as we progress, but you don't have to copy them one by one as the full code is always available at the end of each step. However, I do recommend you to translate it into your own code in order to have a better understanding. Contents * Step 1: Initial setup * Step 2: Gravity * Step 3: Your first N-body program * Step 4: Higher-order algorithms * Step 5: Adaptive time-stepping * Extra: Plotting and animation * Conclusion and Final Project References 1. Lorena Barba and Gilbert Forsyth. CFD Python: the 12 steps to Navier-Stokes equations. Journal of Open Source Education, 2 (16):21, 2019. doi:10.21105/jose.00021. 2. Javier Roa, Adrian S. Hamers, Maxwell X. Cai, and Nathan W. C. Leigh. Moving Planets Around: An Introduction to N-Body Simulations Applied to Exoplanetary Systems. MIT Press, 2020. 3. Richard L. Burden and J. Douglas Faires. Numerical Analysis. Cengage Learning, nineth edition, 2011. Comments Back to top Copyright (c) 2025 Ching-Yin Ng Made with Material for MkDocs