Interactive visualization of the Friedmann equation for introductory astrophysics.
expansion_universe.py solves the Friedmann equation and displays two animated panels:
| Left panel | Right panel |
|---|---|
| Scale factor a(t) vs cosmic time | Comoving galaxy grid expanding in physical coordinates |
A red dot sweeps along the a(t) curve while galaxies (arranged in concentric rings around a gold central observer) expand or contract in real time.
The script solves the Friedmann equation as a second-order ODE in units where H_0 = 1:
(adot)^2 = Omega_r / a^2 + Omega_m / a + Omega_k + Omega_Lambda * a^2
addot = -Omega_r / a^3 - Omega_m / (2 a^2) + Omega_Lambda * a
where Omega_k = 1 - Omega_m - Omega_r - Omega_Lambda determines the spatial curvature.
- Three sliders: Omega_m (matter), Omega_r (radiation), Omega_Lambda (dark energy)
- Four preset buttons: LCDM, Einstein-de Sitter, Open, Closed
- Click on either panel to pause/resume the animation
- Info box displays Omega_k, universe classification (Open/Flat/Closed), and age in units of H_0^{-1}
| Preset | Omega_m | Omega_r | Omega_Lambda | Behavior |
|---|---|---|---|---|
| LCDM | 0.31 | 0.00 | 0.69 | Accelerating expansion (our universe) |
| Einstein-de Sitter | 1.00 | 0.00 | 0.00 | Decelerating, flat, matter-only |
| Open | 0.30 | 0.00 | 0.00 | Expands forever, negatively curved |
| Closed | 4.00 | 0.00 | 0.00 | Expands then recollapses (Big Crunch) |
- Python 3.9+
- numpy, scipy, matplotlib
pip install numpy scipy matplotlibpython expansion_universe.pypip install pytest pytest-cov
pytest test_friedmann_physics.py test_visualization.py -v50 tests validate physics correctness (analytic cosmological solutions, Friedmann constraint, power-law exponents) and visualization integrity (figure structure, sliders, buttons, galaxy grid geometry, animation scaling).
CI runs automatically via GitHub Actions on push and pull request.
R. T. Fisher