use crate::constants::cosmic::{CMB_TEMPERATURE, HUBBLE_CONSTANT};
use crate::constants::physical::C;
use std::f64::consts::PI;
pub fn dm_contribution_to_matter_density(omega_dm: f64, h: f64) -> f64 {
omega_dm * h * h
}
pub const RECOMBINATION_REDSHIFT: f64 = 1089.0;
pub fn matter_radiation_equality_redshift(omega_m_h2: f64) -> f64 {
let omega_r_h2 = 4.15e-5 * (CMB_TEMPERATURE / 2.7255).powi(4);
omega_m_h2 / omega_r_h2 - 1.0
}
pub fn sound_horizon_at_recombination(omega_b_h2: f64, omega_m_h2: f64) -> f64 {
let z_rec = RECOMBINATION_REDSHIFT;
let z_eq = matter_radiation_equality_redshift(omega_m_h2);
let r_s = omega_b_h2 / (omega_m_h2 * (1.0 + z_rec));
let c_over_h = C / HUBBLE_CONSTANT;
2.0 * c_over_h / (3.0 * omega_m_h2 * 100.0 * 1e3 / 3.0857e22).sqrt()
* (((1.0 + r_s) * (1.0 + z_eq) / (1.0 + z_rec)).sqrt() - r_s.sqrt())
/ (1.0 + z_rec).sqrt()
}
pub fn acoustic_peak_scale(omega_b_h2: f64, omega_m_h2: f64) -> f64 {
let r_s = sound_horizon_at_recombination(omega_b_h2, omega_m_h2);
PI / r_s
}
pub fn silk_damping_scale(omega_b_h2: f64, omega_m_h2: f64) -> f64 {
let z_eq = matter_radiation_equality_redshift(omega_m_h2);
8.13e-2 / (omega_b_h2 * omega_m_h2.sqrt()) * (1.0 + z_eq).sqrt()
}
pub fn integrated_sachs_wolfe_temperature(delta_phi: f64) -> f64 {
2.0 * delta_phi / (C * C) * CMB_TEMPERATURE
}
pub fn cmb_lensing_convergence_power(l: f64, omega_m: f64, sigma8: f64) -> f64 {
let prefactor = 9.0 * omega_m * omega_m * HUBBLE_CONSTANT.powi(4) / (4.0 * C.powi(4));
prefactor * sigma8 * sigma8 * l.powf(-0.8)
}
pub fn baryon_fraction_from_peaks(peak_ratio: f64) -> f64 {
peak_ratio / (1.0 + peak_ratio) * 0.16
}
pub fn number_effective_neutrinos_from_damping(
damping_tail_slope: f64,
n_eff_standard: f64,
) -> f64 {
n_eff_standard + (damping_tail_slope - 1.0) * 10.0
}
pub fn dm_annihilation_cmb_effect(sigma_v: f64, m_dm_gev: f64, f_eff: f64) -> f64 {
f_eff * sigma_v / m_dm_gev
}
pub fn cmb_constraint_sigma_v(m_dm_gev: f64, f_eff: f64) -> f64 {
let p_ann_limit = 3.2e-28;
p_ann_limit * m_dm_gev / f_eff
}
pub fn dm_decay_cmb_constraint(tau_seconds: f64) -> bool {
tau_seconds > 1e25
}
pub fn spectral_distortion_mu(energy_injection_rate: f64) -> f64 {
1.4 * energy_injection_rate
}
pub fn spectral_distortion_y(energy_injection_rate: f64) -> f64 {
0.25 * energy_injection_rate
}