Skip to content
Projects

The Barnes-Hut tree: how a quadtree approximates distant charges.

Runs the experiments behind FlatQuadtree.evaluate, the library’s Barnes-Hut tree walk for point and line charges, and saves one figure per claim:

Source: examples/barnes_hut_tree.py. Run it yourself with python examples/barnes_hut_tree.py [--output examples/output] [--quick] (needs pip install "tree-d-3d[examples]").

two colliding star clusters evolved with the pure-Python Barnes-Hut gravity solver, animated, with the quadtree redrawn every frame.

a cloud of random charges and the leaf boxes of the quadtree built on them; boxes shrink where particles are dense and stay large where they are sparse.

for one target particle, which boxes the tree accepts as a single multipole (far enough), which it visits leaf by leaf (too close), and which it merely opens on the way down.

field error against the direct sum, and wall-clock time, both against the opening angle theta: smaller theta is more accurate and slower.

wall-clock time against N for the direct sum and the tree walk, on a log-log plot, next to reference slopes for their N^2 and N log N complexities.

--quick uses fewer particles and a narrower N range (well under a minute instead of a few minutes). Needs Plotly (pip install 'tree-d-3d[examples]').