Skip to content

arhadnane/Expanding-Universe-Simulation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Expanding Universe Simulation (Friedmann-Lemaître Model)

This project implements a numerical simulation of an expanding universe based on the Friedmann-Lemaître equations. It allows exploring various cosmological parameters (Ω_m, Ω_Λ, etc.) and visualizing the evolution of the scale factor, energy densities, and other cosmological quantities.

Features

  • Numerical solutions to the Friedmann equations with customizable cosmological parameters
  • Visualization of scale factor evolution over time
  • Analysis of energy density components (matter, radiation, dark energy)
  • Calculation of observable cosmological quantities (distances, lookback time, etc.)
  • Interactive exploration via Jupyter notebooks
  • Analytical solutions for special cases (matter-dominated, radiation-dominated, etc.)
  • Phase space diagram for different cosmological parameters

Requirements

  • Python 3.8+
  • NumPy
  • SciPy
  • Matplotlib
  • SymPy
  • Jupyter (for interactive notebooks)

Project Structure

  • src/: Source code modules
    • friedmann_universe.py: Core implementation of the Friedmann equations
    • analytical_solutions.py: Analytical solutions for special cases
    • observables.py: Calculation of observable cosmological quantities
    • visualizations.py: Advanced visualization functions
  • data/: Data files (if any)
  • results/: Output files and generated plots
  • tests/: Test modules
  • notebooks/: Jupyter notebooks for interactive exploration

Installation

  1. Clone this repository:
git clone https://github.com/yourusername/expanding-universe-simulation.git
cd expanding-universe-simulation
  1. Create a virtual environment:
python -m venv venv
  1. Activate the virtual environment:
# On Windows:
.\venv\Scripts\activate
# On Unix or MacOS:
source venv/bin/activate
  1. Install dependencies:
pip install -r requirements.txt

Usage

Running the simulation

python main.py

This will run the simulation with default parameters and generate plots in the results/ directory.

Interactive exploration

Launch Jupyter Notebook:

jupyter notebook notebooks/interactive_exploration.ipynb

This notebook provides interactive sliders to explore different cosmological parameters and visualize their effects.

Examples

Creating a custom universe model

from src.friedmann_universe import FriedmannUniverse

# Create a universe model with custom parameters
my_universe = FriedmannUniverse(
    omega_m=0.3,      # Matter density parameter
    omega_lambda=0.7, # Dark energy density parameter
    omega_r=8.4e-5,   # Radiation density parameter
    omega_k=0.0,      # Curvature density parameter
    H0=70.0           # Hubble parameter (km/s/Mpc)
)

# Solve for the scale factor evolution
t, a, da_dt = my_universe.solve_evolution(t_span=(0, 20), t_points=500)

# Plot the results
my_universe.plot_scale_factor(t, a, save_path="results/my_universe_scale_factor.png")

Calculating cosmological observables

from src.friedmann_universe import FriedmannUniverse
from src.observables import CosmologicalObservables

# Create a standard ΛCDM model
universe = FriedmannUniverse(omega_m=0.3, omega_lambda=0.7)

# Create observables calculator
observables = CosmologicalObservables(universe)

# Calculate the age of the universe
age = observables.age()
print(f"Age of the universe: {age:.2f} Gyr")

# Calculate the luminosity distance to a redshift z=1
d_L = observables.luminosity_distance(1.0)
print(f"Luminosity distance to z=1: {d_L:.1f} Mpc")

Theory Background

The Friedmann equations describe how a universe expands or contracts with time under different cosmological parameters. The first Friedmann equation relates the expansion rate to the energy density:

$$ H(t)^2 = \left(\frac{\dot{a}}{a}\right)^2 = \frac{8\pi G}{3}\rho - \frac{kc^2}{a^2} + \frac{\Lambda c^2}{3} $$

Where:

  • $a(t)$ is the scale factor
  • $H(t)$ is the Hubble parameter
  • $\rho$ is the energy density
  • $k$ is the curvature parameter
  • $\Lambda$ is the cosmological constant
  • $G$ is the gravitational constant
  • $c$ is the speed of light

The second Friedmann equation describes the acceleration of the expansion:

$$ \frac{\ddot{a}}{a} = -\frac{4\pi G}{3}\left(\rho + \frac{3p}{c^2}\right) + \frac{\Lambda c^2}{3} $$

Where $p$ is the pressure.

License

MIT License

Acknowledgments

This project is created for educational purposes to study cosmology and numerical methods in astrophysics.

References

  • Friedmann, A. (1922). "Über die Krümmung des Raumes". Zeitschrift für Physik. 10 (1): 377–386.
  • Lemaître, G. (1927). "Un Univers homogène de masse constante et de rayon croissant rendant compte de la vitesse radiale des nébuleuses extra-galactiques". Annales de la Société Scientifique de Bruxelles. A47: 49–59.
  • Weinberg, S. (2008). "Cosmology". Oxford University Press.
  • Ryden, B. (2017). "Introduction to Cosmology". Cambridge University Press.

About

Numerical simulation of an expanding universe based on the Friedmann-Lemaître model

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published