# grav_sim

N-body gravity simulation library with C and Python API

Project Homepage and documentations: https://alvinng4.github.io/grav_sim/

**Target Audience:**

* Physics students
* Anyone interested in N-body simulations

**Features:**

* Ten integrators including WHFast and IAS15
* Barnes-Hut algorithm with linear octree
* Particle-Mesh method for cosmological structure formation
* Multiple sample projects

## 5 steps to N-body simulation

A short course to teach beginners how to write fast and clean N-body gravity simulations code in Python.

Homepage: https://alvinng4.github.io/grav_sim/5_steps_to_n_body_simulation/

**Contents**

- Step 1: Initial setup
- Step 2: Acceleration
- Step 3: Your first N-body program
- Step 4: Higher-order algorithms
- Step 5: Adaptive time-stepping
- Conclusion and Final Project

<img src="./examples/media/solar_plus_3d.png" alt="Image" width="300">
<img src="./examples/media/rel_energy.png" alt="Image" width="300">

## Sample projects

### Evolving the solar system for 1 million years

<img src="./examples/media/eccentricity.png" alt="Image" width="300">
<img src="./examples/media/inclination.png" alt="Image" width="300">

### Asteroid belt animation

<img src="./examples/media/asteroid_belt.png" alt="Image" width="300">

### Formation of Kirkwood gaps

<img src="./examples/media/Kirkwood_gap_semi_major_axes.png" alt="Image" width="300">
<img src="./examples/media/Kirkwood_gap_visualization.png" alt="Image" width="225">

### Galaxy collision

<img src="./examples/media/galaxy_collision.png" alt="Image" width="400">

### Cosmological structure formation

<img src="./examples/media/cosmic_structure_a_1.0.png" alt="Image" width="400">

## Feedback and Bugs
If you found any bugs or want to leave some feedback, please feel free to let me know by opening an issue or sending an email to alvinng324(at)gmail.com.
