Skip to main content

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

Metadata

Release files for bima 0.6.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bima 0.6.6
File Size Uploaded
bima-0.6.6.tar.gz 682.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bima 0.6.6
File Interpreter ABI Platform
bima-0.6.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.17+ x86-64 Details

Total release size: 2.4 MB

Release files / bima-0.6.6.tar.gz

Download URL bima-0.6.6.tar.gz
Size 682.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e7eb9b44d2e1d9a351a6b4c852a858a95a3defcaf231432dc6a66f25d05fd723
BLAKE2b-256 checksum
How to use checksums
86308324c38417dfc17139c6a03d9e3a0b6d44cd9fcc01c2d5d6e25e83549d5e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.10.2

Release files / bima-0.6.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL bima-0.6.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.7 MB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
7dd06c318da4e66aa13935d0b09fecf4bddbcecfae77f8c4de5b7f995edcb2e9
BLAKE2b-256 checksum
How to use checksums
fe9e47f18efa2667d36e643c0c7246cc3382c3c19a355a32195973950e9488d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.10.2

Release history Release notifications | RSS feed

This release

0.6.6 This release

2 release files

0.2.3

12 release files

0.2.0

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page