Skip to content
Projects

Gravity tree

The equations of tree_d_3d.gravity, declared on the code that implements them and checked by the tests.

BarnesHutSimulation

classsource

N-body simulation using Barnes-Hut algorithm.

kick
vn+1/2=vn+Δt2F(rn)m,vn+1=vn+1/2+Δt2F(rn+1)m\mathbf v^{n+1/2} = \mathbf v^n + \frac{\Delta t}{2}\frac{\mathbf F(\mathbf r^n)}{m}, \qquad \mathbf v^{n+1} = \mathbf v^{n+1/2} + \frac{\Delta t}{2}\frac{\mathbf F(\mathbf r^{n+1})}{m}
drift
rn+1=rn+Δt vn+1/2\mathbf r^{n+1} = \mathbf r^n + \Delta t\, \mathbf v^{n+1/2}
Order
2
Assumes
  • kick-drift-kick leapfrog; the tree is rebuilt and all forces summed twice per step
  • bodies outside the fixed bounds are left out of the tree: they feel forces but exert none
Built from

BarnesHutTree

classsource

Quadtree-based Barnes-Hut N-body tree.

force
Fi=∑jGmimj (rj−ri)(∣rj−ri∣2+ε2)3/2\mathbf F_i = \sum_j \frac{G m_i m_j\, (\mathbf r_j - \mathbf r_i)}{\left(|\mathbf r_j - \mathbf r_i|^2 + \varepsilon^2\right)^{3/2}}
monopole
Fi+=GmiM (rcm−ri)ρ3,ρ=∣rcm−ri∣2+ε2,if s/ρ<θ\mathbf F_i \mathrel{+}= \frac{G m_i M\, (\mathbf r_\mathrm{cm} - \mathbf r_i)}{\rho^3}, \qquad \rho = \sqrt{|\mathbf r_\mathrm{cm} - \mathbf r_i|^2 + \varepsilon^2}, \qquad \text{if } s/\rho < \theta
Assumes
  • an object quadtree, one body per leaf, inserted one at a time; ss the cell side, ρ\rho the softened distance to the centre of mass
  • monopole only; no rule opens the cell containing the body; coincident bodies are not handled
  • a reference and teaching code, not used by the electrostatic solvers
References