Crate barnes_hut

Source
Expand description

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.

See the readme for details, including an example.

Structs§

BhConfig
Cube
A cubical bounding box. length=width=depth.
Node
Tree
A recursive tree. Each node can be subdivided Terminates with NodeType::NodeTerminal.

Traits§

BodyModel
We use this to allow for arbitrary body (or particle etc) types in application code to use this library. Substitute charge for mass as required.

Functions§

run_bh
Calculate force using the Barnes Hut algorithm. The force function passed as a parameter has signature (acc_dir: Vec3 (unit), mass_src: f64, distance: f64) -> Vec3 id_target is the index in the body array used to make the tree; it prevents self-interaction. Note that mass can be interchanged with charge, or similar.