Conserving tree code
A tree code that conserves both momentum and energy, with the evidence as figures.
Runs the experiments behind tree_d_3d.smooth and saves one figure per claim:
Source: examples/conserving_tree_code.py. Run it yourself with python examples/conserving_tree_code.py [--output examples/output] [--quick] (needs pip install "tree-d-3d[examples]").
Animations
Section titled “Animations”
Loading figure…the trapped cloud under the conserving scheme, animated, with its energy error.

Loading figure…the ring of like charges, tree code over direct sum, animated.

Loading figure…a tracer crossing leaf edges, animated, with its leaf weights; the dotted boxes are the leaves grown by the smooth band.

Loading figure…the quadtree rebuilt every frame while the particles move, animated: leaves that split and merge (new leaves green, just removed ones red dashed).
Figures
Section titled “Figures”
Loading figure…field error against the expansion order for the rectangle (standard) and triangle (symmetric) M2L truncations.

Loading figure…the net force of the same runs; the triangle gives roundoff at every order, the rectangle the truncation error.

Loading figure…the leaf boxes of an adaptive tree and the weight of one leaf with its smooth band, plus the sum of all weights (one everywhere).

Loading figure…analytic force against finite differences of the energy, for particles blended into several leaves.

Loading figure…relative energy error over a Verlet run for the direct sum, hard membership (fixed boxes and rebuilt every step), smooth membership, and smooth membership with co-moving boxes.

Loading figure…the net force over the same runs.

Loading figure…the particle trajectories of the conserving run over the fixed leaf boxes (red: positive, blue: negative charges, dots: start), and the distance of each variant’s trajectories from the direct sum’s, which grows exponentially for every variant (N-body chaos).

Loading figure…a small ring of like charges orbiting in the trap, where the orbits are recognisable: the conserving tree code’s trajectories over the direct sum’s, and the energy error of both.
--quick uses fewer particles and steps (about 20 s instead of a few minutes). Needs Plotly (pip install 'tree-d-3d[examples]').