- Python 100%
| media | ||
| n_body | ||
| old | ||
| test | ||
| .gitignore | ||
| barnes_hut_n_body.py | ||
| body.py | ||
| damp_osc_with_rk_single.py | ||
| draw.py | ||
| draw.py.bak | ||
| draw_llm.py | ||
| gravity_sim.py | ||
| n_body_gravity.py | ||
| new_energy_n_body.py | ||
| one_body.py | ||
| README.md | ||
| rk.py | ||
| spring.py | ||
| test.py | ||
| test_particle_sim.py | ||
Setup
pip install numpy pyglet matplotlib panda3d
matplotlib is not necessary if not plotting
Note:
This is meant to be an educational project to further our knowledge of the topics we encounter while building a physics engine, hence there are sub-optimal implementations of certain components (like RK4).
new_energy_n_body.py and n_body_gravity.py are the only ones that will currently run due to changes made to rendering. Other files haven't been updated with the new syntax yet. There is some LLM generated code, and such code has been clearly marked as LLM generated (only instances are some test code, optimized draw.py, and some plotting). We are currently working on implementing the fast multipole method (as well as Barnes-Hut for fun).
Additionally, we are thinking if it would be possible to use a modified fluid sim (something like FLIP) to compute the potential of varios fields (like electromagnetic, or gravitational) for one way of simulating the n-body problem in O(n) runtime while preserving causality (which our current method, and fast multipole method don't do).
To-do
- Gravity on Earth
- Build a 2d renderer based on Pyglet
- Implement multi-object rendering
- Reuse old shapes
- Implement inelastic collision models
- Come up with different models for bodies colliding
- Supoort for different types of collisions (and respective energy+momentum changes)
- [WIP] Build a 3d renderer based on Panda3D
- Springs
- Diff eq. support
- Two-body problems
- One fixed body
- N-body problems
- basic N-body problems
- implement fast multipole method
- parallelization
- energy conservation
- Particle simulation
- similar to N-body sims, with perfectly elastic collisions
- Fluid simulation
Switched from RK4 to velocity verlet for significant performance gains, and energy+momentum conservation since veocity verlet is a symplectic integrator and preserves volume in phase space transformations. We considered other integrators like 4-th order Yoshida, but they are much more computationally expensive, and deemed that the performance tradeoff isn't worth the accuracy gains. Instead, we are working on Bodies are stored as numpy structured arrays instead of a class objects for optimization purposes.
Example System
Energy and momentum graphs for an 27 body gravitational system with velocity verlet (with perfectly inelastic collision) (time step = 0.05): Total energy = -24902.30544431605; Total energy final (1000 seconds) = -24902.25451983801
Note: The change in energy is due to inelastic collision b/w colliding bodies. Additionally, the radii have a minimum radius of 1, despite "true" raidus being proportional to cbrt of mass, which would give sub pixel radii. This 1000 seconds run took about 214 seconds to finish on a single core.
Zoomed in energy plot
<p_x, p_y, p_z> represent each of the 3 lines. Total momentum = <-733.67653462, 3488.15404837, 0.>; Total momentum final (1000 seconds) = <-733.67653456, 3488.15404354, 0.>. Change in momentum over the course of 1000s = <0.00000006, −0.00000483, 0.>


