Struct Cosmology

Source
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: f64

CMB temperature today, in K.

§omega_b: f64

Physical baryon density ω_b = Ω_b h²

§omega_cdm: f64

Physical CDM density ω_cdm = Ω_cdm h²

§h: f64

Dimensionless Hubble parameter h = H₀/(100 km/s/Mpc)

§n_eff: f64

Effective number of neutrino species

§y_p: f64

Primordial helium mass fraction Y_p

Implementations§

Source§

impl Cosmology

Source

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.

Source

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.

Source

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.

Source

pub fn planck2015() -> Self

Planck 2015 cosmological parameters (matching CosmoTherm DI files).

Source

pub fn planck2018() -> Self

Planck 2018 cosmological parameters (Planck Collaboration VI, 2020).

Source

pub fn h0(&self) -> f64

H₀ in 1/s

Source

pub fn omega_b_frac(&self) -> f64

Ω_b = ω_b / h²

Source

pub fn omega_cdm_frac(&self) -> f64

Ω_cdm = ω_cdm / h²

Source

pub fn omega_m(&self) -> f64

Ω_m = Ω_b + Ω_cdm

Source

pub fn omega_gamma(&self) -> f64

Ω_γ (photon density parameter)

Source

pub fn omega_rel(&self) -> f64

Ω_rel (all relativistic species: photons + neutrinos)

Source

pub fn omega_lambda(&self) -> f64

Ω_Λ = 1 - Ω_m - Ω_rel (flat universe)

Source

pub fn e_of_z(&self, z: f64) -> f64

E(z) = H(z)/H₀ = sqrt(Ω_m(1+z)³ + Ω_rel(1+z)⁴ + Ω_Λ)

Source

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.

Source

pub fn hubble(&self, z: f64) -> f64

Hubble rate H(z) in 1/s

Source

pub fn dt_dz(&self, z: f64) -> f64

dt/dz in seconds

Source

pub fn z_eq(&self) -> f64

Matter-radiation equality redshift

Source

pub fn n_h(&self, z: f64) -> f64

Hydrogen number density at z [1/m³] N_H = (1 - Y_p) ρ_b / m_p

Source

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

Source

pub fn f_he(&self) -> f64

Helium-to-hydrogen ratio f_He = Y_p / (4(1-Y_p))

Source

pub fn n_e(&self, z: f64, x_e: f64) -> f64

Free electron density at z (1/m³), given ionization fraction X_e.

Source

pub fn t_compton(&self, z: f64, x_e: f64) -> f64

Thomson scattering time t_C = 1/(σ_T N_e c), in s.

Source

pub fn rho_gamma(&self, z: f64) -> f64

Photon energy density ρ_γ at z [J/m³]

Source

pub fn n_gamma(&self, z: f64) -> f64

Photon number density n_γ at z [1/m³]

Source

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)).

Source

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).

Source

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.

Source

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 Clone for Cosmology

Source§

fn clone(&self) -> Cosmology

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Cosmology

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Cosmology

Source§

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.