pub struct Cosmology {
pub t_cmb: f64,
pub omega_b: f64,
pub omega_cdm: f64,
pub h: f64,
pub n_eff: f64,
pub y_p: f64,
/* private fields */
}Expand description
Cosmological parameters with cached derived quantities.
Fields§
§t_cmb: f64CMB temperature today, in K.
omega_b: f64Physical baryon density ω_b = Ω_b h²
omega_cdm: f64Physical CDM density ω_cdm = Ω_cdm h²
h: f64Dimensionless Hubble parameter h = H₀/(100 km/s/Mpc)
n_eff: f64Effective number of neutrino species
y_p: f64Primordial helium mass fraction Y_p
Implementations§
Source§impl Cosmology
impl Cosmology
Sourcepub fn validate(&self) -> Result<(), String>
pub fn validate(&self) -> Result<(), String>
Construct a Cosmology with all cached derived quantities. Validate cosmological parameters.
Returns Err with a descriptive message if any parameter is
non-physical or would cause numerical failure.
Sourcepub fn new(
t_cmb: f64,
omega_b: f64,
omega_cdm: f64,
h: f64,
n_eff: f64,
y_p: f64,
) -> Result<Self, String>
pub fn new( t_cmb: f64, omega_b: f64, omega_cdm: f64, h: f64, n_eff: f64, y_p: f64, ) -> Result<Self, String>
Construct a Cosmology from dimensionless parameters, validating the inputs.
Returns Err if any parameter is non-finite, negative where physical
positivity is required, or outside the supported range.
Sourcepub fn new_unchecked(
t_cmb: f64,
omega_b: f64,
omega_cdm: f64,
h: f64,
n_eff: f64,
y_p: f64,
) -> Self
pub fn new_unchecked( t_cmb: f64, omega_b: f64, omega_cdm: f64, h: f64, n_eff: f64, y_p: f64, ) -> Self
Construct a Cosmology without validation.
Escape hatch for hardcoded presets and test fixtures where the inputs
are known a priori to be valid. Using non-finite or zero h / y_p
here will produce NaN/Inf in derived quantities — prefer Self::new
for any input the caller does not fully control.
Sourcepub fn planck2015() -> Self
pub fn planck2015() -> Self
Planck 2015 cosmological parameters (matching CosmoTherm DI files).
Sourcepub fn planck2018() -> Self
pub fn planck2018() -> Self
Planck 2018 cosmological parameters (Planck Collaboration VI, 2020).
Sourcepub fn omega_b_frac(&self) -> f64
pub fn omega_b_frac(&self) -> f64
Ω_b = ω_b / h²
Sourcepub fn omega_cdm_frac(&self) -> f64
pub fn omega_cdm_frac(&self) -> f64
Ω_cdm = ω_cdm / h²
Sourcepub fn omega_gamma(&self) -> f64
pub fn omega_gamma(&self) -> f64
Ω_γ (photon density parameter)
Sourcepub fn omega_lambda(&self) -> f64
pub fn omega_lambda(&self) -> f64
Ω_Λ = 1 - Ω_m - Ω_rel (flat universe)
Sourcepub fn theta_z(&self, z: f64) -> f64
pub fn theta_z(&self, z: f64) -> f64
Dimensionless photon temperature: θ_z(z) = k_B T_z / (m_e c²) Uses this cosmology’s T_CMB rather than the hardcoded default.
Sourcepub fn n_he(&self, z: f64) -> f64
pub fn n_he(&self, z: f64) -> f64
Helium number density at z [1/m³] N_He = Y_p / (4(1-Y_p)) × N_H
Sourcepub fn n_e(&self, z: f64, x_e: f64) -> f64
pub fn n_e(&self, z: f64, x_e: f64) -> f64
Free electron density at z (1/m³), given ionization fraction X_e.
Sourcepub fn t_compton(&self, z: f64, x_e: f64) -> f64
pub fn t_compton(&self, z: f64, x_e: f64) -> f64
Thomson scattering time t_C = 1/(σ_T N_e c), in s.
Sourcepub fn baryon_photon_ratio(&self, z: f64) -> f64
pub fn baryon_photon_ratio(&self, z: f64) -> f64
Baryon-to-photon energy density ratio R(z) = 3ρ_b/(4ρ_γ).
In the tight-coupling limit this sets the sound speed: c_s² = 1 / (3(1+R)).
Sourcepub fn compton_y_parameter(&self, z: f64) -> f64
pub fn compton_y_parameter(&self, z: f64) -> f64
Compton y-parameter integrated from z’ = 0 to z.
y_C(z) = ∫₀ᶻ (kT_e / m_e c²) × σ_T n_e c / ((1+z’) H(z’)) dz’
Quantifies the total Compton optical depth for energy exchange. At z >> 1100: y_C >> 1 (efficient Comptonization). At z << 1100: y_C << 1 (Compton scattering inefficient).
Uses 128-point midpoint quadrature in ln(1+z).
Sourcepub fn compton_y_parameter_with_recomb(
&self,
z: f64,
recomb: &RecombinationHistory,
) -> f64
pub fn compton_y_parameter_with_recomb( &self, z: f64, recomb: &RecombinationHistory, ) -> f64
Compton y-parameter with a pre-built RecombinationHistory.
Use this variant in loops to avoid rebuilding the recombination table (~3000 ODE steps) on every call.
Sourcepub fn cosmic_time(&self, z: f64) -> f64
pub fn cosmic_time(&self, z: f64) -> f64
Cosmic time t(z) by numerical integration, in s.
Integrates from z_upper (≈ 10^9) down to z.
Trait Implementations§
Source§impl Default for Cosmology
impl Default for Cosmology
Source§fn default() -> Self
fn default() -> Self
Default parameters matching Chluba (2013) Green’s function paper.
These are intentionally not the latest Planck values. The defaults match CosmoTherm v1.0.3 (Y_p=0.24, T₀=2.726 K, Ω_m=0.26, Ω_b=0.044, h=0.71, N_eff=3.046) so that PDE output can be validated against published CosmoTherm results without cosmology mismatch.
For Planck-era parameters use Cosmology::planck2015 or
Cosmology::planck2018.