darkmatter 0.0.1

Dark matter simulation engine — gravitational fields, particle dynamics, halo stability, and cosmological constants
Documentation
use crate::constants::physical::G;
use std::f64::consts::PI;

pub fn press_schechter_number_density(
    mass: f64,
    rho_mean: f64,
    sigma: f64,
    dsigma_dm: f64,
    delta_c: f64,
) -> f64 {
    let nu = delta_c / sigma;
    let prefactor = (2.0 / PI).sqrt() * rho_mean / (mass * mass) * nu * (-0.5 * nu * nu).exp();
    prefactor * dsigma_dm.abs()
}

pub fn sheth_tormen_multiplicity(nu: f64) -> f64 {
    let a = 0.707;
    let p = 0.3;
    let big_a = 0.3222;
    big_a
        * (1.0 + (a * nu * nu).powf(-p))
        * (a * nu * nu / (2.0 * PI)).sqrt()
        * (-a * nu * nu / 2.0).exp()
}

pub const SUBHALO_MASS_FUNCTION_SLOPE: f64 = -1.9;

pub fn subhalo_abundance(m_sub: f64, m_host: f64) -> f64 {
    0.012 * (m_sub / m_host).powf(SUBHALO_MASS_FUNCTION_SLOPE + 1.0)
}

pub fn tidal_stripping_mass_loss(m_sub: f64, rho_host: f64, rho_sub_avg: f64, dt: f64) -> f64 {
    if rho_host > rho_sub_avg {
        let rate = (G * rho_host).sqrt();
        m_sub * (-rate * dt).exp()
    } else {
        m_sub
    }
}

pub fn dynamical_friction_deceleration(
    m_satellite: f64,
    rho_background: f64,
    v_sat: f64,
    coulomb_log: f64,
) -> f64 {
    -4.0 * PI * G * G * m_satellite * rho_background * coulomb_log / (v_sat * v_sat)
}

pub fn tidal_radius(m_sub: f64, m_host: f64, distance: f64) -> f64 {
    distance * (m_sub / (3.0 * m_host)).powf(1.0 / 3.0)
}

#[derive(Clone, Copy, Debug, PartialEq)]
pub struct StellarStream {
    pub progenitor_mass: f64,
    pub width_kpc: f64,
    pub length_kpc: f64,
    pub velocity_dispersion: f64,
}

impl StellarStream {
    pub fn stream_density_per_kpc(&self) -> f64 {
        self.progenitor_mass / self.length_kpc
    }

    pub fn gap_sensitivity_mass_min(&self) -> f64 {
        let sigma = self.velocity_dispersion;
        1e5 * crate::constants::physical::SOLAR_MASS * (sigma / 1e3).powi(2)
    }
}