Skip to main content

A simple implementation of the Barnes-Hut algorithm for N-body simulations in python 3.7

Project description

The N-Body Problem

what is it
    Newton tried to use analytical geometry to predict the planets' motions from its orbital properties (position, orbital diameter, period and orbital velocity) and failed
    realised that there is a gravitational interaction between the planets that is affecting their orbits
    In the solar system, every planet is gravitationally affected by all the other planets to some degree.
    This is also true for other bodies inside and outside the solar system
    it is easy to calculate the gravitationally interactive forces between two bodies using newtonian physics
    as soon as there are more than two bodies involved, things get harder to predict
    This technique is pretty close to reality -- the moon landings used newtonian mechanics to calculate their orbits -- but it has to be said that einstein showed that there are small micro-interactions between bodies that newtonian physics cannot predict

why is it hard
    This is because every body's gravity influences all the other bodies orbital parameters, which in turn influence all OTHER bodies
    for n bodies, there are n^2 interactions to calculate
    you have to take all bodies into account, or your result will be very imprecise
    You can use this to find bodies you don't know about: Plug all bodies you know about into the equations, calculate, and if the result differs from reality, Boom, you know where to look for your new dark moon

approximation using Barnes-Hut
    organise all bodies into an octo-tree (or quad-tree for 2d), ordered by their distance from each other
    each Body is a leaf on the end of the tree, and saves its mass, plus its orbital parameters
    save the combined mass of the attached bodies for each node
    for far away bodies, do not calculate every body's mass and gravitational interaction individually -- instead, with increasing distance, retreat further and further up the tree and use the mass information in the upper nodes
    it can be proven that due to the inverse square root relation of gravity to mass over distance, this only gives us very small errors as opposed to calculating every individual body
    However, the complexity sinks from O(n^2) to O(n log n)

Reference Code (java)

http://physics.princeton.edu/~fpretori/Nbody/code.htm

Sources

https://en.m.wikipedia.org/wiki/Barnes–Hut_simulation https://en.m.wikipedia.org/wiki/N-body_simulation https://en.wikipedia.org/wiki/Celestial_mechanics

J. Barnes & P. Hut (December 1986). "A hierarchical O(N log N) force-calculation algorithm". Nature. 324 (4): 446–449. Bibcode:1986Natur.324..446B. doi:10.1038/324446a0.

Troubleshooting:

https://stackoverflow.com/questions/13316397/matplotlib-animation-no-moviewriters-available https://stackoverflow.com/questions/47736457/runtimeerror-no-moviewriters-available-in-matplotlib-animation?rq=1

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

CrudeBHT-1.0.7.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

CrudeBHT-1.0.7-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file CrudeBHT-1.0.7.tar.gz.

File metadata

  • Download URL: CrudeBHT-1.0.7.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5

File hashes

Hashes for CrudeBHT-1.0.7.tar.gz
Algorithm Hash digest
SHA256 00c56ba3262b1d1ef5cdb3188aeb912dcb07fda959399c1ed15ab5f653ac29b4
MD5 6f7d5e1114c28f023ef14345bad9359b
BLAKE2b-256 e9943c16d75ccebb9e0d04fca6539eb71c54021a16a933226b440d013178445d

See more details on using hashes here.

File details

Details for the file CrudeBHT-1.0.7-py3-none-any.whl.

File metadata

  • Download URL: CrudeBHT-1.0.7-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5

File hashes

Hashes for CrudeBHT-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 92b2235d1b072df6e370d534e6a4ed01fa32940a6decd569b8d0b906f50e8c5f
MD5 6aef19c771039f4c5665439580da168e
BLAKE2b-256 20d721ed53d36b446611f30228ad6bef3450a66a14482070ea688ccda9af5972

See more details on using hashes here.

Supported by

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