N-body simulation powered with Rust backend
Project description
N-body simulation library in Rust with Python bindings.
Features
- [-] Integrators:
- Euler
- Runge-Kutta 4
- Bulirsch-Stoer
- [x]Leapfrog (Symplectic)
- Wisdom-Holman
- Adaptive time stepping.
- Collision detection and handling.
- Solid body collisions.
- Merging bodies.
- [-] Close encounter detection.
- Softening.
- Truncated.
- Regularization.
- Force calculation.
- Direct summation.
- Barnes-Hut tree (octree).
- Fast multipole method.
- Parallelization.
- CPU multi-threading.
- GPU acceleration.
Installation
pip install bima
Quick Start
from bima.body import Body
from bima import Config
import numpy as np
import bima
from matplotlib import pyplot as plt
v = np.sqrt(2)
arr = np.array([[1, -1, 0, 0, 0, -2/3 * v, 0], [2, 0.5, 0, 0, 0, 1/3 * v, 0]])
initial = bima.Initial.from_arr(arr)
config = Config(
force=bima.ForceMethod.Direct,
# integrator=bima.Integrator.Euler,
integrator=bima.Integrator.LeapFrog,
timestep=bima.TimestepMethod.Constant(0.1),
# timestep=bima.TimestepMethod.Constant(1),
close_encounter=bima.CloseEncounterMethod.Regularized,
)
sim = bima.Simulation(initial)
bodies = sim.in_memory.run(config, 100)
# bodies = sim.in_memory.run(config, 1)
# print(len(energy.t))
def plot(bodies: list[Body]):
body0 = bodies[0]
length = len(body0)
sample_n = np.min([1000, length])
skip = length//sample_n
x0 = body0.x[::skip]
y0 = body0.y[::skip]
body1 = bodies[1]
length = len(body1)
skip = length//sample_n
x1 = body1.x[::skip]
y1 = body1.y[::skip]
fig, ax = plt.subplots()
ax.plot(x0, y0)
ax.scatter(x0[-1], y0[-1])
ax.plot(x1, y1)
ax.scatter(x1[-1], y1[-1])
ax.set_aspect("equal")
plt.show()
# plot(bodies)
energy = bima.Energy.from_bodies(bodies)
e0 = energy.e[0]
plt.plot(energy.t, (e0-energy.e)/e0)
plt.show()
License
GNU General Public License v3.0. See LICENSE for more details.
Documentation
under construction
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
bima-0.6.6.tar.gz
(682.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bima-0.6.6.tar.gz.
File metadata
- Download URL: bima-0.6.6.tar.gz
- Upload date:
- Size: 682.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7eb9b44d2e1d9a351a6b4c852a858a95a3defcaf231432dc6a66f25d05fd723
|
|
| MD5 |
97d633893b02e46c80de0f41aa07c55d
|
|
| BLAKE2b-256 |
86308324c38417dfc17139c6a03d9e3a0b6d44cd9fcc01c2d5d6e25e83549d5e
|
File details
Details for the file bima-0.6.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: bima-0.6.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.7 MB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7dd06c318da4e66aa13935d0b09fecf4bddbcecfae77f8c4de5b7f995edcb2e9
|
|
| MD5 |
6d05d496f543853affa1c90575326e14
|
|
| BLAKE2b-256 |
fe9e47f18efa2667d36e643c0c7246cc3382c3c19a355a32195973950e9488d2
|