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])
Documentation
Full documentation, including installation instructions, examples, and library reference, are at Read The Docs
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:
- Clone or download the git repository
git clone https://github.com/jbailinua/gravhopper.git
- Go into the gravhopper directory and build the code.
cd gravhopper
python setup.py build_ext --inplace
- 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
Built Distributions
File details
Details for the file gravhopper-1.1.2.tar.gz
.
File metadata
- Download URL: gravhopper-1.1.2.tar.gz
- Upload date:
- Size: 24.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff699eb0ad71a40c49b81fea7bfecc2e5d56301d1fe26b30930b4dbd6b3a07d5 |
|
MD5 | eba87c2c604c63b561a41b5179b9ae91 |
|
BLAKE2b-256 | 8f7aee4b94c7a12f8610b612ee7d9e0022d5360387fd12c6840c19e68b1b47d7 |
File details
Details for the file gravhopper-1.1.2-cp312-cp312-win_amd64.whl
.
File metadata
- Download URL: gravhopper-1.1.2-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 28.8 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 017294f9055965e6d63337c7be051cea3e6012f19b45f475e89d2d55bed3eea1 |
|
MD5 | b8c3691b85e44f10287711a36b42deba |
|
BLAKE2b-256 | 012b6cb83cd60cf06000575d15c11a714904b0c52d25d35e0905d0db07564366 |
File details
Details for the file gravhopper-1.1.2-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: gravhopper-1.1.2-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 46.6 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f9c6c7e532f1e398afc0f7ef2e5c803ded1f6e575a668adbbca72d73d044d99 |
|
MD5 | c771c238b5570df2d4523d414ce58df5 |
|
BLAKE2b-256 | c93f076e788627d10409c4f6a3001f1e7183e09dd100b4ac3cd8f34101539f92 |
File details
Details for the file gravhopper-1.1.2-cp312-cp312-macosx_11_0_arm64.whl
.
File metadata
- Download URL: gravhopper-1.1.2-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 25.9 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7917d8fad35174bf0d50b605fd5ff147dfc5744b5162164b5edb91ee1b69ed6 |
|
MD5 | 49c444b0071a88cc567e38dc69ee670b |
|
BLAKE2b-256 | cfb47c4a7d841146728b08341779544b0212b204c0fba31f6db259c3b06ccdbb |
File details
Details for the file gravhopper-1.1.2-cp312-cp312-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: gravhopper-1.1.2-cp312-cp312-macosx_10_9_x86_64.whl
- Upload date:
- Size: 26.1 kB
- Tags: CPython 3.12, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d1774ed8ebdc17457ef5e684ae29c2cedf9faca040db4404a1add70e7d58129 |
|
MD5 | bb19eaa14fc0196acf55c2e914bb66ac |
|
BLAKE2b-256 | 0ed1d6886dbfde95fc85e854569356b1f6301c9ad470a58186f68c5fb90cb4d6 |
File details
Details for the file gravhopper-1.1.2-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: gravhopper-1.1.2-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 28.8 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 257666635ecbc091b47ab00b08af0408fca38e02e3a4f41d3481d41d66a7b18b |
|
MD5 | 45ca98853776677a9dbc92a22879534f |
|
BLAKE2b-256 | 45bc6ae95add693093351af9769b8323d08a290532a4df1990fa6a11eae56e56 |
File details
Details for the file gravhopper-1.1.2-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: gravhopper-1.1.2-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 45.8 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc059ef814e0999645a33301ee743f2b5e85788cf86773ea862ba2f7a6379776 |
|
MD5 | 94ee30938a477657a57dbd7c74d1e9a1 |
|
BLAKE2b-256 | 589ec434a2345d321b3488f600ec56d4ff93fc3e0ac6809ef01bf75fbded44d5 |
File details
Details for the file gravhopper-1.1.2-cp311-cp311-macosx_11_0_arm64.whl
.
File metadata
- Download URL: gravhopper-1.1.2-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 25.9 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 710ca3478432d388276227a415be7df2b0af644bd01d139bb0040874c70d5a4b |
|
MD5 | e40a6addf1284050f8007d18af2f8012 |
|
BLAKE2b-256 | cc25a3fbcff5de459ccd3152b9fe9ec952c0d88af3bc47c1b5855934c7387085 |
File details
Details for the file gravhopper-1.1.2-cp311-cp311-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: gravhopper-1.1.2-cp311-cp311-macosx_10_9_x86_64.whl
- Upload date:
- Size: 26.1 kB
- Tags: CPython 3.11, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d68e10ccb841ca9243267af001165bdca50121194b11b386ebb21cfcb67a3e2 |
|
MD5 | bd8f1ac4c91864b070d69c29d1e49dd5 |
|
BLAKE2b-256 | 31410b8d0e71816b8b084051d694c25d43845d1deca2eec56d345161a10fb5e9 |
File details
Details for the file gravhopper-1.1.2-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: gravhopper-1.1.2-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 28.8 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 073f724ae9d5deeeebbb045808a7811b57197b0ba439addd13ba7c7eb085657a |
|
MD5 | cd8dbb7e06a2094afa7d4d69ee223cd0 |
|
BLAKE2b-256 | b1c6014931b6f6680d8798571e36f401591b88dcc83260271bc65ffe886abdbb |
File details
Details for the file gravhopper-1.1.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: gravhopper-1.1.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 45.7 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33e4ab141bb1197b8fa45dc6a4440d99c6d8208840a58d03bf8cf0f259291669 |
|
MD5 | 85dde8aaa7391b719713c44a12bf4e17 |
|
BLAKE2b-256 | 54d26959426fe3c4824857692edde9206f61e02c4ffafc1949b29143b074eed7 |
File details
Details for the file gravhopper-1.1.2-cp310-cp310-macosx_11_0_arm64.whl
.
File metadata
- Download URL: gravhopper-1.1.2-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 25.9 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d0183460a393babd8737704067bbed4dfb54410ed0d54891d0d2c9c9256b48f |
|
MD5 | cdbbfd53fd5b7f8c5cc57b51d52c38ba |
|
BLAKE2b-256 | ab9f1cdd1aefe70d19d9e1e04f51d3681ebcfb03887a51ef7f26136a4b5f95ac |
File details
Details for the file gravhopper-1.1.2-cp310-cp310-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: gravhopper-1.1.2-cp310-cp310-macosx_10_9_x86_64.whl
- Upload date:
- Size: 26.1 kB
- Tags: CPython 3.10, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e791315bbafefe5208c105148deab5bf0b94bd4d47a214dab3d470ed4668b8ab |
|
MD5 | 63a7a289e3eaba257dafb0a7a6a62f14 |
|
BLAKE2b-256 | f2d30451ee826abcdb241ae0f703bb741db6abba37550dfab643ff423204e714 |
File details
Details for the file gravhopper-1.1.2-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: gravhopper-1.1.2-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 28.8 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa5c3575ce66a42ad78146341bc672e0bef25d4673d674845fefda60f6a5b3ce |
|
MD5 | 53c1fa3b3fcd611206ce9adb00a5c6a2 |
|
BLAKE2b-256 | af19be27ae3212d66f7838c27fcc9340d1804811a433c42b82e3c8d545751ba9 |
File details
Details for the file gravhopper-1.1.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: gravhopper-1.1.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 45.6 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | df82dd0be375dc1d8b705198c596187ede6ae71ce552b72c82369b2e88e2773f |
|
MD5 | 231bf3269894b7a8fd32081214515cfc |
|
BLAKE2b-256 | fffe83fb4be324fd8b054adc426d13d6ee1ac1d96e22921bb1e28b449eba96ca |
File details
Details for the file gravhopper-1.1.2-cp39-cp39-macosx_11_0_arm64.whl
.
File metadata
- Download URL: gravhopper-1.1.2-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 25.9 kB
- Tags: CPython 3.9, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aefa7574e205a1fa0159d2184779a266ff83f9d902f795279a98e8fa93493d09 |
|
MD5 | c5d599ec8b60b6b9eb0125bcedf3e364 |
|
BLAKE2b-256 | 703f52abcc9939b18af51e4df7d24485fee98ec1bf146bfef30e932aec4d165a |
File details
Details for the file gravhopper-1.1.2-cp39-cp39-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: gravhopper-1.1.2-cp39-cp39-macosx_10_9_x86_64.whl
- Upload date:
- Size: 26.1 kB
- Tags: CPython 3.9, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e84c1ac5781ac5f0b683bb7696c9644b5bc17e5f8228774fe18bb4c1986fb4bc |
|
MD5 | 7b620db2e710cbd47762e2f04a002b17 |
|
BLAKE2b-256 | fa76d36949179555261de7b049a33efb3cc8f6acb3cffa9845a0f3979310e874 |
File details
Details for the file gravhopper-1.1.2-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: gravhopper-1.1.2-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 28.8 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3f1cd34db3e7fc69c0f16e0b209b1ed5473c582cfa0d54cf36414f819ef9dc3 |
|
MD5 | 9922cab0165c6d26f5bc4390f694976a |
|
BLAKE2b-256 | 0228cba7b3b24e8e07dd2b9bdbdcb0c1c7264a177ec486a9681310fab068cf12 |
File details
Details for the file gravhopper-1.1.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: gravhopper-1.1.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 46.5 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee7957e00aee738e5bc6d68d2dc11b9ab96366c09e182a2f27daf423155af674 |
|
MD5 | de60d672f78a7a685dcc7cc2671fcc24 |
|
BLAKE2b-256 | 46634681b08c9e34dbd9f223b33361a750540c3378e0853dc02ba72a130fe190 |
File details
Details for the file gravhopper-1.1.2-cp38-cp38-macosx_11_0_arm64.whl
.
File metadata
- Download URL: gravhopper-1.1.2-cp38-cp38-macosx_11_0_arm64.whl
- Upload date:
- Size: 25.9 kB
- Tags: CPython 3.8, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f1b3759dc9eed1b732d81cb774097693ff297e0909b5f1f929b1cc547f47bad |
|
MD5 | fd8cbfcadf107e50d4dfccafadcbf3a0 |
|
BLAKE2b-256 | 1a16c65ce06756e208626165e27abc09bca2e6a8260842a14f10e76e6a6930e9 |
File details
Details for the file gravhopper-1.1.2-cp38-cp38-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: gravhopper-1.1.2-cp38-cp38-macosx_10_9_x86_64.whl
- Upload date:
- Size: 26.1 kB
- Tags: CPython 3.8, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | db92f55d8f07f2699bf8d69b5103b5b64c382339fb5dfcc35aacb667811d0340 |
|
MD5 | 8764de1bab0d029c4f887cff6f0d0c32 |
|
BLAKE2b-256 | d7784fe8959ef147528c5ca55bfb63ca10e551f4d945f4a33d575c78e21229a6 |
File details
Details for the file gravhopper-1.1.2-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: gravhopper-1.1.2-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 28.6 kB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0d4ec382dcd2f6e9e8133f195f280c18bf4cfc84d2ed3f3936538a920c6db81 |
|
MD5 | 8ea69fcd7b46f9c5ade599b7abd9718e |
|
BLAKE2b-256 | 7b0fc4a16a4ff8a5bf055937ad9897a81f089c277bbe660c91aa88e9d56e758e |
File details
Details for the file gravhopper-1.1.2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: gravhopper-1.1.2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 44.8 kB
- Tags: CPython 3.7m, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e62fb487bb2f73072c90bc302fe87308c8fb953b6a09b2d4a37bdd1947c4852 |
|
MD5 | f45fe0f808a18ba40231de509f8852e3 |
|
BLAKE2b-256 | d258236e54220bc7d15f9985dd848f78aca2a976c8487f311eb43172aa19defd |
File details
Details for the file gravhopper-1.1.2-cp37-cp37m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: gravhopper-1.1.2-cp37-cp37m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 25.9 kB
- Tags: CPython 3.7m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e0cb678135d324b2008367f1708272d8c489494ed929e9d609eeec8fc818357 |
|
MD5 | a20d96bb996e87dc8e53b5f34ec792dc |
|
BLAKE2b-256 | b75dbb2fd27b3e7c3150b9e35058b894bc69a76a52632f93437253ad5b2eb3db |