Skip to main content

Simple N-body code for Python

Project description

GravHopper

"They told me computers could only do arithmetic." -- Grace Hopper

Gravitational N-body simulation code written by Jeremy Bailin.

Named in honour of pioneering computer scientist Grace Hopper. Doubly appropriate because it uses a leapfrog integrator.

This is a simple Python-interface code for performing gravitational N-body simulations. It combines a simple Python interface for ease of use with a C backend for speed, and has the following features:

  • Choice of Barnes-Hut tree or direct summation algorithm.
  • Ability to include external potentials from galpy, gala, or user-supplied functions.
  • Ability to return output as pynbody snapshots.
  • Functions that generate equilibrium or near-equilibrium initial conditions (ICs) for several density profiles (Plummer, Hernquist, exponential disk), along with the ability to create ICs from galpy distribution function objects or pynbody snapshots.
  • Utility functions for plotting snapshots and making movies.

For now, it uses a constant uniform timestep and constant uniform Plummer softening.

Requirements:

  • Astropy
  • NumPy, SciPy, Matplotlib
  • C compiler
  • To use galpy, gala, or pynbody interface functions, they will need to be installed.
  • Saving movies requires ffmpeg.

For example, this will create a Plummer sphere with 2000 particles, run it for a few dynamical times, and plot the particle positions before and after to show that it is in equilibrium:

from gravhopper import Simulation, IC
from astropy import units as u
import matplotlib.pyplot as plt

# Create Plummer initial conditions.
Plummer_IC = IC.Plummer(N=2000, b=1*u.pc, totmass=1e6*u.Msun)

# Create a new simulation with a time step of 0.005 Myr and a softening of 0.05 pc.
sim = Simulation(dt=0.005*u.Myr, eps=0.05*u.pc)
# Add the Plummer model to the simulation
sim.add_IC(Plummer_IC)
# Run for 400 time steps
sim.run(400)

# Plot the x-y positions at the beginning and end.
fig = plt.figure(figsize=(12,4))
ax1 = fig.add_subplot(121, aspect=1.0)
ax2 = fig.add_subplot(122, aspect=1.0)
sim.plot_particles(snap='IC', unit=u.pc, xlim=[-10,10], ylim=[-10,10], ax=ax1)
sim.plot_particles(snap='final', unit=u.pc, xlim=[-10,10], ylim=[-10,10], ax=ax2)

To make a movie of the whole evolution of the simulation:

# Make and save a movie of the simulation running
sim.movie_particles('Plummer_sim.mp4', unit=u.pc, xlim=[-10,10], ylim=[-10,10])

Installation

Option 1: Pip

If all goes well, you should be able to install GravHopper simply with:

pip install gravhopper

Option 2: Install from source

To install directly from the current source:

  1. Clone or download the git repository
git clone https://github.com/jbailinua/gravhopper.git
  1. Go into the gravhopper directory and build the code.
cd gravhopper
python setup.py build_ext --inplace
  1. Copy the gravhopper subdirectory to wherever you want to use it.

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

gravhopper-1.0.6.tar.gz (22.1 kB view details)

Uploaded Source

Built Distributions

gravhopper-1.0.6-cp39-cp39-win_amd64.whl (26.7 kB view details)

Uploaded CPython 3.9Windows x86-64

gravhopper-1.0.6-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (47.0 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.12+ x86-64manylinux: glibc 2.5+ x86-64

gravhopper-1.0.6-cp39-cp39-macosx_10_9_x86_64.whl (24.1 kB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

gravhopper-1.0.6-cp38-cp38-win_amd64.whl (26.7 kB view details)

Uploaded CPython 3.8Windows x86-64

gravhopper-1.0.6-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (48.2 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.12+ x86-64manylinux: glibc 2.5+ x86-64

gravhopper-1.0.6-cp38-cp38-macosx_10_9_x86_64.whl (24.1 kB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

gravhopper-1.0.6-cp37-cp37m-win_amd64.whl (26.6 kB view details)

Uploaded CPython 3.7mWindows x86-64

gravhopper-1.0.6-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (47.4 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.12+ x86-64manylinux: glibc 2.5+ x86-64

gravhopper-1.0.6-cp37-cp37m-macosx_10_9_x86_64.whl (24.1 kB view details)

Uploaded CPython 3.7mmacOS 10.9+ x86-64

gravhopper-1.0.6-cp36-cp36m-win_amd64.whl (26.6 kB view details)

Uploaded CPython 3.6mWindows x86-64

gravhopper-1.0.6-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (46.5 kB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.12+ x86-64manylinux: glibc 2.5+ x86-64

gravhopper-1.0.6-cp36-cp36m-macosx_10_9_x86_64.whl (24.1 kB view details)

Uploaded CPython 3.6mmacOS 10.9+ x86-64

File details

Details for the file gravhopper-1.0.6.tar.gz.

File metadata

  • Download URL: gravhopper-1.0.6.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.8

File hashes

Hashes for gravhopper-1.0.6.tar.gz
Algorithm Hash digest
SHA256 db8281edd22af0886dd7eeb90a482c52a26ba29b9fb72b4d96aeae478c2ac73d
MD5 ab467dc403cf646aa26d4b458083c51f
BLAKE2b-256 a88aa4dd07f0d6d31211b10ab1b029290864ef38217273b1c66f1bc2f0f24a04

See more details on using hashes here.

File details

Details for the file gravhopper-1.0.6-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: gravhopper-1.0.6-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 26.7 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.8

File hashes

Hashes for gravhopper-1.0.6-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 3a377b42a385def2338bd7e723cd496818821f3430435ffc57cbb7c209bb249e
MD5 dda2aab63a9a3151193d791a51e62e15
BLAKE2b-256 60be54b4fd820b3598b13395c60379b9ab5081b4dd18a73df6e99945e6ec1d93

See more details on using hashes here.

File details

Details for the file gravhopper-1.0.6-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for gravhopper-1.0.6-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 4bc9f1bc9e5ce71335bb4d581bd47506c16fb9d28efc1925232074eeddc07135
MD5 00a7c678ee442b05adf867ef085e6220
BLAKE2b-256 633af0d114e0d7decad9c00fd4b39c1089a87b39cb4eaf609eec54920c80fe01

See more details on using hashes here.

File details

Details for the file gravhopper-1.0.6-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: gravhopper-1.0.6-cp39-cp39-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 24.1 kB
  • Tags: CPython 3.9, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.8

File hashes

Hashes for gravhopper-1.0.6-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a801692a43dee9d2a63de2eb66b1ff747028ea8f4511890d2f29f2b1aa299525
MD5 5d0eaac1055b599859eb75b60f6ef5de
BLAKE2b-256 7dab13fcedd5993c7220d4d9deb5730930cc6462a4d81b9d6f8a885a25790670

See more details on using hashes here.

File details

Details for the file gravhopper-1.0.6-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: gravhopper-1.0.6-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 26.7 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.8

File hashes

Hashes for gravhopper-1.0.6-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 937b94cb458b39ab7a44a572ecbc9c5003c8960f6aa5b09b9ad1691c5b728c65
MD5 7a1c3a1c083e459542d2eb2a1b4c5293
BLAKE2b-256 68807557c47520e749667004c50d1aab21a7258fada7facaef222f7fd4e6ff95

See more details on using hashes here.

File details

Details for the file gravhopper-1.0.6-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for gravhopper-1.0.6-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 10253ce051a92a7d6282fc227a373924c8a68b2b53ed67d7bfd42a72c8570619
MD5 06d5eb02f5f07eea6a3510dfdd79bb24
BLAKE2b-256 324cd55f7356ebe41646f581a9ce673fedbf9d8e784c5e4d88beccfc9551b1ed

See more details on using hashes here.

File details

Details for the file gravhopper-1.0.6-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: gravhopper-1.0.6-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 24.1 kB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.8

File hashes

Hashes for gravhopper-1.0.6-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ba83a0cf5c064f0a6477fe40eae80bb87ef8be7c9511d9e7f0107452aa403646
MD5 95c701b50656b1cce4c77a1be8bacb4c
BLAKE2b-256 99af52599f47916b728024d0d377a49a9d84c91ab4fb536d201d6626d24b9854

See more details on using hashes here.

File details

Details for the file gravhopper-1.0.6-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: gravhopper-1.0.6-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 26.6 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.8

File hashes

Hashes for gravhopper-1.0.6-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 5e5f2c10b7dcb7f0ce7631418938ff4576927d8f2eedfe54bed411f6bcb05519
MD5 554e6dec6063700209a926ee51c14384
BLAKE2b-256 0e48827f9b159965b9906c74e1d03e60c78e9582561fa9df2e5ea134abaed581

See more details on using hashes here.

File details

Details for the file gravhopper-1.0.6-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for gravhopper-1.0.6-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 dc3bbb152a2acef783b3dc0d0c9ed521aaee579e2608bd2f83834f97c18a5cf6
MD5 89b6da001ec79d67db4485fd06a172f5
BLAKE2b-256 22a90da56f5b7c526eb22c87e1c9116550313c6722d9e0d358001368fc9228c1

See more details on using hashes here.

File details

Details for the file gravhopper-1.0.6-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: gravhopper-1.0.6-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 24.1 kB
  • Tags: CPython 3.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.8

File hashes

Hashes for gravhopper-1.0.6-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 151d47ec80bd743590ef1ae5a536ae79f566d9d04161c0f52d75a3fd0e6fa26c
MD5 326621c63472e3cdc1f9e44aede9c340
BLAKE2b-256 c632c2a91a5e63864c0779da946fc60ba41818e08e362a6308536d59203b3a42

See more details on using hashes here.

File details

Details for the file gravhopper-1.0.6-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: gravhopper-1.0.6-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 26.6 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.8

File hashes

Hashes for gravhopper-1.0.6-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 3bb2ad474599e460c2d7538b01368441df0b0ee5b540c57c0b59291fb831a8be
MD5 785a51d20395bec3f2ec0a5d7a0b6587
BLAKE2b-256 42ddfcfdba638d2fdbb18b163d21829c55024a14ac6ec7473ec3f874841d15bc

See more details on using hashes here.

File details

Details for the file gravhopper-1.0.6-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for gravhopper-1.0.6-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 b8a64e95bd64da87edd141b128f2a6e3f4ef8668fd412f166054a9264b3c014d
MD5 e329edcf202f8f17c0184313a7262262
BLAKE2b-256 bd457fa9e3b6869ad850f0225134dec84f6cd10046e781f99d0311808c91d123

See more details on using hashes here.

File details

Details for the file gravhopper-1.0.6-cp36-cp36m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: gravhopper-1.0.6-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 24.1 kB
  • Tags: CPython 3.6m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.8

File hashes

Hashes for gravhopper-1.0.6-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 538d29229281d45188e06fdb68c32c41912d7dd4d4958d652b6109e2b7b3b2b7
MD5 bdc1e89434d52df4d76a35e3a9e0cc6f
BLAKE2b-256 b1ddf480eb469e9f60f53d60c7d1b1b3a69fe85817325eca57198570ee670054

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page