https://github.com/ahlusar1989/barnes-hut-simulation
Barnes Hut Simulation
https://github.com/ahlusar1989/barnes-hut-simulation
Last synced: 7 months ago
JSON representation
Barnes Hut Simulation
- Host: GitHub
- URL: https://github.com/ahlusar1989/barnes-hut-simulation
- Owner: ahlusar1989
- Created: 2016-11-28T01:03:32.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-11-28T23:14:59.000Z (almost 9 years ago)
- Last Synced: 2024-10-05T23:41:19.606Z (about 1 year ago)
- Language: Scala
- Homepage:
- Size: 14.6 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Barnes-Hut-Simulation
Implementation of a the parallel Barnes-Hut algorithm for N-body simulation.
N-body simulation is a simulation of a system of N particles that interact
with physical forces, such as gravity or electrostatic force. Given initial
positions and velocities of all the particles (or bodies), the N-body simulation
computes the new positions and velocities of the particles as the time progresses.
It does so by dividing time into discrete short intervals, and computing the
positions of the particles after each interval.To take advantage of this observation, the Barnes-Hut algorithm relies on a quadtree --
a data structure that divides the space into cells, and answers queries such as 'What is
the total mass and the center of mass of all the particles in this cell?'.An iteration of the Barnes-Hut algorithm is composed of the following steps:
1. Construct the quadtree for the current arrangement of the bodies.
2. Determine the boundaries, i.e. the square into which all bodies fit.
3. Construct a quadtree that covers the boundaries and contains all the bodies.4. Update the bodies -- for each body:
1. Update the body position according to its current velocity.
2. Using the quadtree, compute the net force on the body by adding the individual forces from all the other bodies.
3. Update the velocity according to the net force on that body.It turns out that, for most spatial distribution of bodies, the expected number of cells that contribute to the net force on a body is log n, so the overall complexity of the Barnes-Hut algorithm is O(n log n).
The main source directory contains an implementation of the following:
a quadtree and its combiner data structure
an operation that computes the total force on a body using the quadtree
a simulation step of the Barnes-Hut algorithm