Skip to content

Cosmology

Cosmology: the expansion of a homogeneous universe.

ScaleFactorElement(label, visual=None, *, a=1.0, a_d1=0.0, H0=1.0, omega_matter=0.3, omega_lambda=0.7)

Bases: Element

Homogeneous universe whose size is the scale factor a, a state of order 2 with the expansion rate a_d1.

Parameters:

Name Type Description Default
label str

The label of the universe.

required
visual VisualSpec | None

How the universe is drawn, or None for none.

None
a Annotated[float, StateSpec(domain=open(0, oo), order=2)]

The initial scale factor.

1.0
a_d1 float

The initial rate of change of the scale factor.

0.0
H0 Annotated[float, ParameterSpec(domain=open(0, oo))]

The Hubble constant.

1.0
omega_matter Annotated[float, ParameterSpec(domain=closed_open(0, oo))]

The density parameter of matter.

0.3
omega_lambda Annotated[float, ParameterSpec()]

The density parameter of dark energy.

0.7

Examples:

>>> from skcomplex.models.physics.cosmology import ScaleFactorElement
>>> ScaleFactorElement('universe', H0=2.0).H0
2.0
Source code in src/skcomplex/models/physics/cosmology/_expansion.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
def __init__(
    self,
    label: str,
    visual: VisualSpec | None = None,
    *,
    a: Annotated[float, StateSpec(domain=RealSet.open(0, oo), order=2)] = 1.0,
    a_d1: float = 0.0,
    H0: Annotated[float, ParameterSpec(domain=RealSet.open(0, oo))] = 1.0,
    omega_matter: Annotated[float, ParameterSpec(domain=RealSet.closed_open(0, oo))] = 0.3,
    omega_lambda: Annotated[float, ParameterSpec()] = 0.7,
) -> None:
    super().__init__(label, visual=visual)
    self.a = a
    self.a_d1 = a_d1
    self.H0 = H0
    self.omega_matter = omega_matter
    self.omega_lambda = omega_lambda

friedmann_expansion(a=1.0, *, H0=1.0, omega_matter=0.3, omega_lambda=0.7)

Return the scale factor of a homogeneous universe of matter and dark energy, after Friedmann and Lemaître.

The acceleration equation a² a'' = -4 pi G M / 3 + Lambda a³ / 3 is written with the density parameters of matter Ω_m = 8 pi G M / (3 H0²) and of the cosmological constant Ω_Λ = Lambda / (3 H0²) in units of the Hubble constant H0 at a = 1, so a² a'' = -Ω_m H0² / 2 + Ω_Λ H0² a³. The initial expansion rate follows from the Friedmann equation a'² = H0² (Ω_m / a + Ω_Λ a² + 1 - Ω_m - Ω_Λ), which stays a first integral of the motion. Matter decelerates the expansion and dark energy accelerates it once a exceeds (Ω_m / (2 Ω_Λ))^(1/3).

Parameters:

Name Type Description Default
a float

The initial scale factor.

1.0
H0 float

The Hubble constant, the expansion rate at a = 1.

1.0
omega_matter float

The density parameter of matter.

0.3
omega_lambda float

The density parameter of the cosmological constant.

0.7

Returns:

Name Type Description
system System

The model, with the scale factor universe.a of order 2 and its rate universe.a_d1.

Raises:

Type Description
ValidationError

The universe does not expand at the initial scale factor.

Examples:

>>> from skcomplex.models.physics.cosmology import friedmann_expansion
>>> friedmann_expansion(omega_matter=1.0, omega_lambda=0.0).elements[0].a_d1
1.0
Source code in src/skcomplex/models/physics/cosmology/_expansion.py
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
@register_model(
    field='physics/cosmology',
    tags=('cosmology', 'ode', 'second order', 'gravity', 'dark energy'),
    references=('Friedmann 1922', 'Lemaître 1927', 'Satz 2022'),
    defaults={'until': 2.0, 'dt': 0.02},
)
def friedmann_expansion(
    a: float = 1.0,
    *,
    H0: float = 1.0,
    omega_matter: float = 0.3,
    omega_lambda: float = 0.7,
) -> System:
    """Return the scale factor of a homogeneous universe of matter and dark energy, after Friedmann and Lemaître.

    The acceleration equation `a² a'' = -4 pi G M / 3 + Lambda a³ / 3` is written with the density parameters of
    matter `Ω_m = 8 pi G M / (3 H0²)` and of the cosmological constant `Ω_Λ = Lambda / (3 H0²)` in units of the Hubble
    constant `H0` at `a = 1`, so `a² a'' = -Ω_m H0² / 2 + Ω_Λ H0² a³`. The initial expansion rate follows from the
    Friedmann equation `a'² = H0² (Ω_m / a + Ω_Λ a² + 1 - Ω_m - Ω_Λ)`, which stays a first integral of the motion.
    Matter decelerates the expansion and dark energy accelerates it once `a` exceeds `(Ω_m / (2 Ω_Λ))^(1/3)`.

    Args:
        a:
            The initial scale factor.

        H0:
            The Hubble constant, the expansion rate at `a = 1`.

        omega_matter:
            The density parameter of matter.

        omega_lambda:
            The density parameter of the cosmological constant.

    Returns:
        system:
            The model, with the scale factor `universe.a` of order 2 and its rate `universe.a_d1`.

    Raises:
        ValidationError:
            The universe does not expand at the initial scale factor.

    Examples:
        >>> from skcomplex.models.physics.cosmology import friedmann_expansion
        >>> friedmann_expansion(omega_matter=1.0, omega_lambda=0.0).elements[0].a_d1
        1.0
    """
    square = H0**2 * (omega_matter / a + omega_lambda * a**2 + 1 - omega_matter - omega_lambda)
    if square < 0:
        error_msg = (
            f'The Friedmann equation gives a negative squared expansion rate {square} at a = {a}. Choose a, '
            'omega_matter, and omega_lambda for which it is positive.'
        )
        raise ValidationError(error_msg)
    universe = ScaleFactorElement(
        'universe',
        a=a,
        a_d1=math.sqrt(square),
        H0=H0,
        omega_matter=omega_matter,
        omega_lambda=omega_lambda,
    )
    acceleration = GradientInteraction(
        'acceleration',
        target='universe',
        states='a',
        potential=_get_expansion_potential,
    )
    return System(elements=[universe], interactions=[acceleration])