Runs the Barnes Hut algorithm for fast n-body simulations.
This algorithm uses Tree Code to group source bodies, as an approximation. It leads to O(N(log N)) computation time, where N is the number of bodies. Canonical use cases include gravity, and charged particle simulations.
This is much faster than a naive N-body approach, at high body counts. It is slower than Fast Multiple Methods (FMM), which group target bodies in addition to source ones. Note that FMM methods are more difficult to implement, but if you have a good implementation, use that instead of this library. There are currently, as of January 2025, no published implementations in Rust.
Uses the Rayon library for parallelization.
Currently hard-coded for f64. Post an issue on Github if you'd like f32 support.
This library is generic over Body and acceleration function . Here's an example of adapting your type for use here:
Example use:
use ;