blackholesfactory 0.0.4

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

pub struct ThermalRadiation {
    pub temperature: f64,
}

impl ThermalRadiation {
    pub fn new(temperature: f64) -> Self {
        Self { temperature }
    }

    pub fn planck_radiance(&self, wavelength: f64) -> f64 {
        let nu = C / wavelength;
        2.0 * H * nu * nu * nu / (C * C) * 1.0 / ((H * nu / (K_B * self.temperature)).exp() - 1.0)
    }

    pub fn wien_peak_wavelength(&self) -> f64 {
        2.898e-3 / self.temperature
    }

    pub fn wien_peak_frequency(&self) -> f64 {
        5.879e10 * self.temperature
    }

    pub fn stefan_boltzmann_flux(&self) -> f64 {
        SIGMA_SB * self.temperature.powi(4)
    }
}

pub struct AccretionRadiation {
    pub mass: f64,
    pub mdot: f64,
    pub efficiency: f64,
}

impl AccretionRadiation {
    pub fn new(mass: f64, mdot: f64) -> Self {
        Self {
            mass,
            mdot,
            efficiency: 0.1,
        }
    }

    pub fn with_efficiency(mut self, eta: f64) -> Self {
        self.efficiency = eta.clamp(0.001, 0.42);
        self
    }

    pub fn luminosity(&self) -> f64 {
        self.efficiency * self.mdot * C * C
    }

    pub fn eddington_luminosity(&self) -> f64 {
        eddington_luminosity(self.mass)
    }

    pub fn eddington_ratio(&self) -> f64 {
        self.luminosity() / self.eddington_luminosity()
    }

    pub fn characteristic_temperature(&self) -> f64 {
        let rs = schwarzschild_radius(self.mass);
        (self.luminosity() / (4.0 * PI * rs * rs * SIGMA_SB))
            .max(0.0)
            .powf(0.25)
    }

    pub fn disk_inner_temperature(&self, spin: f64) -> f64 {
        let r_isco = isco_radius(self.mass, spin);
        (3.0 * G * self.mass * self.mdot / (8.0 * PI * SIGMA_SB * r_isco.powi(3)))
            .max(0.0)
            .powf(0.25)
    }
}

pub fn synchrotron_power(charge: f64, mass: f64, gamma: f64, b_field: f64) -> f64 {
    let sigma_t = 6.652e-29;
    let beta2 = 1.0 - 1.0 / (gamma * gamma);
    let u_b = b_field * b_field / (2.0 * 4.0 * PI * 1e-7);
    4.0 / 3.0
        * sigma_t
        * C
        * gamma
        * gamma
        * beta2
        * u_b
        * (charge / 1.602e-19).powi(4)
        * (9.109e-31 / mass).powi(2)
}

pub fn bremsstrahlung_emissivity(temperature: f64, electron_density: f64) -> f64 {
    1.4e-27 * temperature.sqrt() * electron_density * electron_density
}