HyRex.hydrogen module
- class HyRex.hydrogen.hydrogen_model(xe_4He, lna_4He, lna_end, last_4He_lna, twog_redshift, integration_spacing=0.0005, Nsteps=800, swift=Array([[1.775000e+03, -3.631352e-02, 3.584254e-02, -7.258989e-01, 1.320773e-04], ..., [4.415000e+03, -5.489227e-02, 6.942021e-02, -4.241939e+00, 6.363997e-04]], dtype=float64))[source]
Bases:
ModuleHydrogen recombination model implementation.
Computes hydrogen ionization fraction evolution through multiple phases: Saha equilibrium, post-Saha expansion, HYREC-2 EMLA with two-photon processes, and late-time EMLA-only evolution.
Attributes:
integration_spacingfloatStep size in log scale factor for integration
swiftarrayTabulated SWIFT correction function for recombination rates
concrete_axis_sizearrayPre-allocated array for post-Saha phase integration
xe_4HearrayHelium ionization fraction from previous calculation
lna_4HearrayLog scale factor grid from helium recombination
last_4He_lnafloatFinal log scale factor from helium phase
twog_redshiftfloatRedshift at which two-photon processes become negligible
lna_endfloatFinal log scale factor for hydrogen evolution
Methods:
get_hydrogen_history:Compute full hydrogen recombination history (units: dimensionless)
Saha_equilibrium:Compute Saha equilibrium phase (units: dimensionless)
post_Saha_expansion:Compute post-Saha expansion phase (units: dimensionless)
solve_emla_twophoton:Solve EMLA with two-photon processes (units: dimensionless)
solve_emla:Solve EMLA-only evolution (units: dimensionless)
xe_derivative_twophoton:Compute ionization fraction derivative with two-photon (units: dimensionless)
xe_tm_derivative:Compute coupled xe and Tm derivatives (units: dimensionless, eV)
dxe_dlna_twophoton:Compute two-photon recombination rate (units: dimensionless)
get_current_correction_func:Interpolate SWIFT correction function (units: dimensionless)
steady_state_equations:Set up steady-state level population equations (units: dimensionless)
Lyn_esc_rate:Compute Lyman escape rate (units: s^{-1})
- Lyn_esc_rate(n, H, nH, x1s)[source]
Computes the Lyman-n escape rate, rate at which photons redshift past the Lyman-n line without being absorbed. We use the convention that n=2 is Ly-alpha, n=3 is Ly-beta…
Parameters:
nfloatRequested Lyman transition level, should be greater than 2.
HfloatHubble parameter in s^-1.
nHfloatHydrogen number density in cm^-3.
x1sfloatFraction of 1s bound hydrogen.
Returns:
RLynfloatRate of escape of Lyman-n level.
- TLA_xe_deriv(lna, state, args)[source]
Compute coupled derivatives for ionization fraction and matter temperature using Peebles three-level atom.
Parameters:
lnafloatLog scale factor
statearrayCurrent state [xe, Tm]
argstupleh, omega_b, omega_cdm, Neff, YHe; the Hubble parameter, the baryon denisty Omega_b h^2, the CDM density Omega_cdm h^2, the effecgive number of neutrinos, and the helium fraction
Returns:
- array
Time derivatives [dxe/dlna, dTm/dlna] (units: dimensionless, eV)
- dxe_dlna_twophoton(xe, TCMB, Tm, H, nH, Delta)[source]
Compute two-photon recombination rate.
Calculates ionization fraction evolution rate including two-photon transitions using effective multilevel atom approximation.
Parameters:
xefloatCurrent ionization fraction
TCMBfloatCMB temperature (units: eV)
TmfloatMatter temperature (units: eV)
HfloatHubble parameter (units: s^{-1})
nHfloatHydrogen number density (units: cm^{-3})
DeltafloatCorrection function value
Returns:
- float
Recombination rate dxe/dlna (units: dimensionless)
- get_current_correction_func(TCMB, omega_b, omega_cdm, YHe, Neff)[source]
Interpolate correction function for current cosmology.
Interpolates correction function and applies cosmological parameter derivatives at current CMB temperature for accurate recombination rates.
Parameters:
TCMBfloatCMB temperature (units: eV)
hfloatHubble parameter
omega_bfloatThe baryon density Omega_b h^2
omega_cdmfloatThe density of Cold Dark Matter Omega_cdm h^2
NefffloatEffective number of neutrinos
YHefloatHelium fraction
Returns:
- float
Correction function value (units: dimensionless)
- get_hydrogen_history(h, omega_b, omega_cdm, Neff, YHe, rtol=1e-06, atol=1e-09, solver=Kvaerno3(), max_steps=1024)[source]
Compute complete hydrogen recombination history through all phases.
Sequentially computes hydrogen ionization fraction through post-Saha expansion, HYREC-2 EMLA with two-photon processes, and late-time EMLA-only evolution phases.
Parameters:
hfloatHubble parameter
omega_bfloatThe baryon density Omega_b h^2
omega_cdmfloatThe density of Cold Dark Matter Omega_cdm h^2
NefffloatEffective number of neutrinos
YHefloatHelium fraction
rtolfloat, optionalRelative tolerance for ODE solver (default: 1e-6)
atolfloat, optionalAbsolute tolerance for ODE solver (default: 1e-9)
solverdiffrax.Solver, optionalODE solver instance (default: Kvaerno3())
max_stepsint, optionalMaximum solver steps (default: 1024)
Returns:
- tuple
(xe_full, lna_full, Tm, lna_Tm) containing ionization fraction evolution, log scale factor grid, matter temperature, and temperature grid
- post_Saha_expansion(starting_lna, h, omega_b, omega_cdm, Neff, YHe, threshold=1e-05)[source]
Compute post-Saha expansion phase with two-photon corrections.
Calculates ionization fraction including two-photon processes as perturbative corrections to Saha equilibrium until deviations exceed threshold.
Parameters:
starting_lnafloatInitial log scale factor
hfloatHubble parameter
omega_bfloatThe baryon density Omega_b h^2
omega_cdmfloatThe density of Cold Dark Matter Omega_cdm h^2
NefffloatEffective number of neutrinos
YHefloatHelium fraction
thresholdfloat, optionalThreshold for deviation from Saha (default: 1e-5)
Returns:
- tuple
(xe_output, lna_output) - ionization fraction and log scale factor arrays
- solve_TLA(lna0, xe0, Tm0, h, omega_b, omega_cdm, Neff, YHe, rtol=1e-07, atol=1e-09, solver=Kvaerno3(), max_steps=4096)[source]
Solve late-time TLA evolution.
Integrates hydrogen recombination using Peebles TLA in the region beyond where SWIFT corrections are tabulated.
Parameters:
lna0floatStarting log scale factor
xe0floatInitial ionization fraction
Tm0floatStarting matter temperature
hfloatHubble parameter
omega_bfloatThe baryon density Omega_b h^2
omega_cdmfloatThe density of Cold Dark Matter Omega_cdm h^2
NefffloatEffective number of neutrinos
YHefloatHelium fraction
rtolfloat, optionalRelative tolerance (default: 1e-7)
atolfloat, optionalAbsolute tolerance (default: 1e-9)
solverdiffrax.Solver, optionalODE solver (default: Tsit5())
max_stepsint, optionalMaximum steps (default: 4096)
Returns:
- tuple
(xe_output, Tm_output, lna_output) - ionization fraction, matter temperature, and log scale factor arrays
- solve_emla(lna0, xe0, h, omega_b, omega_cdm, Neff, YHe, rtol=1e-07, atol=1e-09, solver=Tsit5(), max_steps=4096)[source]
Solve late-time EMLA evolution without two-photon processes.
Integrates hydrogen recombination using effective multilevel atom approximation for late times when two-photon processes are negligible.
Parameters:
lna0floatLog scale factor at which initial xe is given
xe0floatInitial ionization fraction
hfloatHubble parameter
omega_bfloatThe baryon density Omega_b h^2
omega_cdmfloatThe density of Cold Dark Matter Omega_cdm h^2
NefffloatEffective number of neutrinos
YHefloatHelium fraction
rtolfloat, optionalRelative tolerance (default: 1e-7)
atolfloat, optionalAbsolute tolerance (default: 1e-9)
solverdiffrax.Solver, optionalODE solver (default: Tsit5())
max_stepsint, optionalMaximum steps (default: 4096)
Returns:
- tuple
(xe_output, Tm_output, lna_output) - ionization fraction, matter temperature, and lna arrays
- solve_emla_twophoton(lna_axis_init, lna_axis_final, xe0, h, omega_b, omega_cdm, Neff, YHe, rtol=1e-06, atol=1e-09, solver=Kvaerno3(), max_steps=1024)[source]
Solve HYREC-2 EMLA evolution with two-photon processes.
Integrates hydrogen recombination including effective multilevel atom approximation with two-photon transitions and correction functions.
Parameters:
lna_axis_initfloatInitial log scale factor
lna_axis_finalfloatFinal log scale factor
xe0floatInitial ionization fraction
hfloatHubble parameter
omega_bfloatThe baryon density Omega_b h^2
omega_cdmfloatThe density of Cold Dark Matter Omega_cdm h^2
NefffloatEffective number of neutrinos
YHefloatHelium fraction
rtolfloat, optionalRelative tolerance (default: 1e-6)
atolfloat, optionalAbsolute tolerance (default: 1e-9)
solverdiffrax.Solver, optionalODE solver (default: Kvaerno3())
max_stepsint, optionalMaximum steps (default: 1024)
Returns:
- tuple
(xe_output, lna_output) - ionization fraction and log scale factor arrays
- steady_state_equations(xe, H, nH, TCMB, A2s, A2p, B2s, B2p, R2p2s, R2s2p, Delta)[source]
Set up steady-state level population equations.
Constructs matrix equation for hydrogen level populations in steady-state approximation for 2s and 2p levels.
Parameters:
xefloatCurrent ionization fraction
HfloatHubble parameter (units: s^{-1})
nHfloatHydrogen number density (units: cm^{-3})
TCMBfloatCMB temperature (units: eV)
A2sfloat2s recombination coefficient (units: cm^3 s^{-1})
A2pfloat2p recombination coefficient (units: cm^3 s^{-1})
B2sfloat2s photoionization coefficient (units: s^{-1})
B2pfloat2p photoionization coefficient (units: s^{-1})
R2p2sfloat2p→2s transition rate (units: s^{-1})
R2s2pfloat2s→2p transition rate (units: s^{-1})
DeltafloatCorrection function value
Returns:
- tuple
(T, S) - transition matrix and source vector for level populations
- xe_derivative_twophoton(lna, xe, args)[source]
Compute ionization fraction derivative including two-photon processes.
Derivative function for hydrogen ionization fraction evolution including two-photon transitions and correction functions.
Parameters:
lnafloatLog scale factor
xefloatCurrent ionization fraction
argstupleh, omega_b, omega_cdm, Neff, YHe; the Hubble parameter, the baryon denisty Omega_b h^2, the CDM density Omega_cdm h^2, the effecgive number of neutrinos, and the helium fraction
Returns:
- float
Time derivative dxe/dlna (units: dimensionless)
- xe_tm_derivative(lna, state, args)[source]
Compute coupled derivatives for ionization fraction and matter temperature.
Derivative function for simultaneous evolution of hydrogen ionization fraction and matter temperature including Compton heating/cooling.
Parameters:
lnafloatLog scale factor
statearrayCurrent state [xe, Tm]
argstupleh, omega_b, omega_cdm, Neff, YHe; the Hubble parameter, the baryon denisty Omega_b h^2, the CDM density Omega_cdm h^2, the effecgive number of neutrinos, and the helium fraction
Returns:
- array
Time derivatives [dxe/dlna, dTm/dlna] (units: dimensionless, eV)