Skip to content
DARC
■ Change #56 · wiki.edited

Gravitational N-body simulation: Normalize Markdown to canonical form

by DARC wiki2026-10-22 20:31:03 UTCOpen the page →
explainer.student
**The problem.** Newtonian gravity gives each of N bodies an acceleration equal to the sum of pulls from the other N − 1 bodies. Computing every pair is called direct summation, and its cost grows as N², the square of the number of bodies. Doubling the bodies quadruples the work. At N = 10⁹ that is hopeless on any machine.
− **Tree codes (Barnes–Hut).** Put the bodies in a tree. Space is cut into a cube, each cube is cut into eight smaller cubes, and so on until each cell has few bodies (an octree). For a target body, walk down the tree. If a cell is small compared with its distance, replace all the bodies in it by one point at their centre of mass. If not, open the cell and look at its children. The *opening angle* θ sets how strict this test is: small θ is accurate but slow, large θ is fast but rough. The cost drops from N² to about N log N.
+ **Tree codes (Barnes–Hut).** Put the bodies in a tree. Space is cut into a cube, each cube is cut into eight smaller cubes, and so on until each cell has few bodies (an octree). For a target body, walk down the tree. If a cell is small compared with its distance, replace all the bodies in it by one point at their centre of mass. If not, open the cell and look at its children. The _opening angle_ θ sets how strict this test is: small θ is accurate but slow, large θ is fast but rough. The cost drops from N² to about N log N.
**Fast multipole method (FMM).** Instead of only grouping the sources, it also groups the targets. It describes the pull of a cell as a short series of terms (a monopole, dipole, quadrupole and so on, called a multipole expansion) and passes those terms between cells. The cost drops to about N.
**Particle-mesh (PM).** Spread the mass onto a regular grid, then solve Poisson's equation, which links mass density to the gravitational field, using the fast Fourier transform. This handles long-range forces cheaply but blurs short ranges. TreePM codes use PM for far pulls and a tree for near ones.
**Details that matter.**
− - *Softening*: two point masses that pass very close would get an enormous force and a huge time step. Codes round off the force at short range with a small softening length.
− - *Time integration*: symplectic integrators such as leapfrog keep the energy error bounded over long runs, where a naive method slowly gains or loses energy.
− - *Sanity check*: total energy should stay nearly constant. A steady energy drift means something is wrong.
+ - _Softening_: two point masses that pass very close would get an enormous force and a huge time step. Codes round off the force at short range with a small softening length.
+ - _Time integration_: symplectic integrators such as leapfrog keep the energy error bounded over long runs, where a naive method slowly gains or loses energy.
+ - _Sanity check_: total energy should stay nearly constant. A steady energy drift means something is wrong.
+
**What it is not.** These are approximations, and many simulated systems are chaotic, so the exact path of one body is not trustworthy. What can be trusted are statistics, such as how clumpy the whole system becomes.
hash 224ff94156b18edf13da60a21d80b5e0c42e905a214f0a8ef45642f4d065b880
previous 2d8f43f19f6c1529d802b62c8080749fc79de7f2955e2fe866cffba2bcef9f3a