spectroxide/
lib.rs

1//! # spectroxide
2//!
3//! An open-source solver for the cosmological thermalization problem:
4//! computing spectral distortions of the CMB from energy release in the
5//! early Universe.
6//!
7//! ## Overview
8//!
9//! The code evolves the photon occupation number `n(x, z)` (where
10//! `x = hν/(kT_z)` is the dimensionless frequency) through the
11//! coupled photon-electron Boltzmann equation in an expanding universe.
12//!
13//! Physical processes included:
14//! - **Compton scattering** (Kompaneets equation): frequency redistribution
15//! - **Double Compton emission**: photon-number changing, γe → γγe
16//! - **Bremsstrahlung**: photon-number changing, e+ion → e+ion+γ
17//! - **Hubble expansion**: cosmological redshifting
18//!
19//! ## Usage
20//!
21//! ```rust,no_run
22//! use spectroxide::prelude::*;
23//!
24//! // Create solver with default cosmology
25//! let cosmo = Cosmology::default();
26//! let mut solver = ThermalizationSolver::new(cosmo, GridConfig::fast());
27//!
28//! // Set energy injection (e.g., delta-function burst at z=2×10⁵)
29//! solver.set_injection(InjectionScenario::SingleBurst {
30//!     z_h: 2e5,
31//!     delta_rho_over_rho: 1e-5,
32//!     sigma_z: 100.0,
33//! }).unwrap();
34//!
35//! // Run the solver, collecting 50 evenly log-spaced snapshots
36//! let snapshots = solver.run(50);
37//! let mu = snapshots.last().unwrap().mu;
38//! ```
39//!
40//! ## Green's Function Mode
41//!
42//! For fast approximate calculations of small distortions:
43//!
44//! ```rust
45//! use spectroxide::greens::*;
46//!
47//! // Distortion from delta-function injection at z_h = 2×10⁵
48//! let x = 3.0; // dimensionless frequency
49//! let g = greens_function(x, 2e5);
50//! ```
51
52/// Content hash of the physics-relevant Rust source files at compile time.
53///
54/// Used to invalidate cached Green's function tables when the underlying
55/// physics code changes. See `build.rs` for the curated file list and the
56/// `physics-hash` CLI subcommand for runtime access.
57pub const PHYSICS_HASH: &str = env!("PHYSICS_HASH");
58
59pub mod bremsstrahlung;
60pub mod cli;
61pub mod constants;
62pub mod cosmology;
63pub mod dark_photon;
64pub mod distortion;
65pub mod double_compton;
66pub mod electron_temp;
67pub mod energy_injection;
68pub mod greens;
69pub mod grid;
70pub mod kompaneets;
71pub mod output;
72pub mod recombination;
73pub mod solver;
74pub mod spectrum;
75/// Convenient imports for common usage.
76pub mod prelude {
77    pub use crate::constants;
78    pub use crate::cosmology::Cosmology;
79    pub use crate::dark_photon;
80    pub use crate::distortion;
81    pub use crate::energy_injection::InjectionScenario;
82    pub use crate::greens;
83    pub use crate::grid::{FrequencyGrid, GridConfig, RefinementZone};
84    pub use crate::output::{
85        GreensResult, OutputFormat, PhotonSweepBatchResult, PhotonSweepResult, PhotonSweepRow,
86        SolverResult, SweepResult, SweepRow,
87    };
88    pub use crate::solver::{SolverBuilder, SolverConfig, SolverDiagnostics, ThermalizationSolver};
89    pub use crate::spectrum;
90}