Expand description
Barnes-Hut 3D force simulation internals — Phase 224 Wave 2.
Parallel to the 2D implementation in crate::force, this module
hosts the 3D octree (OctNode) and the per-tick force-accumulation
helpers that Simulation::tick_3d calls. The public Simulation
API lives in force.rs; this file keeps the 3D tree mechanics off
to the side so the 2D hot path stays readable.
§Tree shape
Same flat-arena pattern as the quadtree: every node is a
self-contained OctNode stored in a Vec<OctNode>, children are
referenced by index with u32::MAX as the “no child” sentinel.
The split count is the only structural change — 8 children per
internal node instead of 4. The mass / centre-of-mass aggregation,
the one-body-leaf split-on-insert trick, and the
size^2 < theta^2 * dist^2 Barnes-Hut approximation check are
all identical in shape.
§SIMD
graph_core::util::dot_simd is the AVX2 fast-path for wide-float
dot products. A 3-float vector is still far below the
break-even point for that kernel (one FMA is enough), so the
per-pair force computation stays scalar. The fused center-gravity
reduction over all positions at once is the only 3D-specific place
where dot_simd would pay off (batched self-dot over the 3D
positions array flattened to &[f32]). That optimisation is
tracked as future work — Wave 2’s priority is correctness and
parity with the 2D path.