blackholesfactory 0.0.1

Black hole factory — create and simulate stellar, intermediate-mass, and supermassive black holes with full Kerr physics
Documentation
use crate::config::parameters::{C, G};
use std::f64::consts::PI;

pub struct GravitationalField {
    pub mass: f64,
}

impl GravitationalField {
    pub fn new(mass: f64) -> Self {
        Self { mass }
    }

    pub fn acceleration(&self, r: f64) -> f64 {
        G * self.mass / (r * r)
    }

    pub fn potential(&self, r: f64) -> f64 {
        -G * self.mass / r
    }

    pub fn escape_velocity(&self, r: f64) -> f64 {
        (2.0 * G * self.mass / r).sqrt().min(C)
    }

    pub fn orbital_velocity(&self, r: f64) -> f64 {
        (G * self.mass / r).sqrt()
    }

    pub fn orbital_period(&self, r: f64) -> f64 {
        2.0 * PI * r / self.orbital_velocity(r)
    }

    pub fn tidal_force(&self, r: f64, dr: f64) -> f64 {
        2.0 * G * self.mass * dr / (r * r * r)
    }

    pub fn sphere_of_influence(&self, distance: f64, host_mass: f64) -> f64 {
        distance * (self.mass / host_mass).powf(2.0 / 5.0)
    }

    pub fn bondi_radius(&self, sound_speed: f64) -> f64 {
        2.0 * G * self.mass / (sound_speed * sound_speed)
    }
}

pub fn two_body_force(m1: f64, m2: f64, r: f64) -> f64 {
    G * m1 * m2 / (r * r)
}

pub fn hill_sphere(semi_major: f64, mass: f64, host_mass: f64) -> f64 {
    semi_major * (mass / (3.0 * host_mass)).cbrt()
}

pub fn roche_limit(r_primary: f64, rho_primary: f64, rho_secondary: f64) -> f64 {
    r_primary * (2.0 * rho_primary / rho_secondary).cbrt()
}