Anne Reinarz Durham University

The Barnes-Hut Algorithm

The Barnes-Hut Algorithm

J. Barnes, P. Hut: A hierarchical O(N log N) force calculation algorithm. Nature 324, 1986, p. 446.


# Barnes Hut Method – Key Ideas

## Short-range Forces:


Barnes Hut Method – Key Ideas

Long-range Forces:

Is it possible to reduce the complexity for the computation of long-range forces?


Barnes Hut Method – Key Ideas

Consider Astrophysics:


Barnes Hut Method – Key Ideas


Octrees and Quadtrees for Domain Decomposition


Octrees and Quadtrees for Domain Decomposition


Octrees and Quadtrees for Domain Decomposition


Octrees and Quadtrees for Domain Decomposition


Octrees and Quadtrees for Domain Decomposition


Octrees and Quadtrees for Domain Decomposition


Barnes-Hut Algorithm

### Create point cloud - Visualisation by Jeffrey Heer - https://jheer.github.io/barnes-hut/
### Subdivide domain into quadtree - distribute long-range region into subdomains: $$ \Omega^{\rm{far}} = \bigcup_i \Omega^{\rm{far}}_i$$ For each particle (position $x\in\Omega$): - start in root node - descent into subdomains and subdivide until every domain contains 0 or 1 particles Add points
### Compute centers of mass or charge - assign a point $y_0^i$ to each $\Omega^{\rm{far}}_i$ corresponding to the center of mass - for each subdomain compute total mass by summing particles in that subdomain - decomposition depending on size of subdomains: $$ \text{diam} := \sup_{y\in\Omega^{\rm{far}}_i} \|y-y_0^i\| $$
### Force computation For each particle (position $x\in\Omega$): - start in root node - descent into subdomains, until $\theta$-rule satisfied: $$ \frac{diam}{r} \leq \theta,$$ $r$ the distance of pseudo particle from $x$ - accumulate corresp. partial force to current particle Change theta
</div>

Barnes-Hut: Computation of Forces

Implicit separation of short- and longe-range forces:


Barnes-Hut: Accuracy and Complexity

Accuracy of Barnes-Hut:


Complexity:


Barnes-Hut: Implementation