Skip to content

Cosmology

Cosmology systems.

The package covers the expansion of a homogeneous universe and the gravitational collapse of matter.

DustShellElement(label, *, R=1.0, energy=0.0, space=None)

Bases: Element

Shell of a spherical ball of dust.

The shell has the areal radius R and the energy per unit mass energy, and the rate of the radius is the derivative R'. On a space, the element holds one shell per site.

Parameters:

Name Type Description Default
label str

The label of the shell.

required
R Annotated[float | ArrayLike, open(0, oo)]

The initial areal radius, or one radius per site.

1.0
energy Annotated[float | ArrayLike, open(-0.5, oo)]

The energy per unit mass, negative for a bound shell, or one energy per site.

0.0
space BaseSpace | None

The space whose sites hold the shells, or None for a single shell.

None

Examples:

>>> from skcomplex.systems.physics.cosmology import DustShellElement
>>> DustShellElement('shell', R=2.0).R
2.0
Source code in src/skcomplex/systems/physics/cosmology/_metric_cosmologies.py
580
581
582
583
584
585
586
587
588
589
590
def __init__(
    self,
    label: str,
    *,
    R: Annotated[float | npt.ArrayLike, RealSet.open(0, oo)] = 1.0,
    energy: Annotated[float | npt.ArrayLike, RealSet.open(-0.5, oo)] = 0.0,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, space=space)
    self.R = R
    self.energy = energy

EinsteinFieldEquationsInteraction(label, *, target, states='x', space=None, components=(), source=None, coupling=8 * math.pi, cosmological_constant=0.0, time=0, axes=None)

Bases: Interaction

Einstein equations G^mu_nu + Λ δ^mu_nu = κ T^mu_nu of a metric ansatz.

The equations are reduced to rate laws of the unknowns of the ansatz. The metric of the space is an ansatz: a symmetric matrix whose unknowns are symbolic functions of the coordinates, each named after a state or a parameter of the target, such as the scale factor a(t) of a homogeneous universe or the areal radius R(t, r) of the shells of a spherical dust ball. The interaction takes the mixed Einstein tensor G^mu_nu = g^(mu lambda) G_(lambda nu) the space derives, keeps one component (mu, nu) per state, and solves these equations, linear in the second time derivatives, for them, which gives one rate law per state of order 2.

The time coordinate becomes the time of the system, a derivative of an unknown along it the time derivative of its state, and a derivative along a coordinate that axes maps to an axis of the lattice of a field the derivative partial of the field along that axis, so a spherical ansatz reduces to a field in 1 + 1 dimensions. An equation that keeps another coordinate, a mixed derivative in time and space, or a derivative above the second does not reduce to such laws and raises an error, as does a set of components that does not fix the second derivatives: the remaining components are constraints, such as the Friedmann equation, which the initial values satisfy and the laws keep.

The source function takes the namespace of the interaction, with the namespace target, and returns the mixed energy-momentum tensor T^mu_nu, such as diag(-rho, p, p, p) of a perfect fluid at rest, in terms of the states and parameters of the target.

Parameters:

Name Type Description Default
label str

The label of the interaction, unique among the components of its system.

required
target Role

The path of the element or field whose states and parameters are the unknowns of the ansatz.

required
states str | Sequence[str]

The name of the state of order 2 that an equation determines, or the names of several states.

'x'
space SpacetimeSpace | None

The pseudo-Riemannian space of the ansatz, with the curvature.

None
components Sequence[tuple[int, int]]

The index pair (mu, nu) of the mixed equation of every state, in the order of the states.

()
source Callable[[SimpleNamespace], object] | None

A function of the namespace that returns the mixed energy-momentum tensor, or None for vacuum.

None
coupling float

The coupling κ = 8 π G / c⁴ of the source.

8 * pi
cosmological_constant float

The cosmological constant Λ.

0.0
time int

The index of the time coordinate.

0
axes Mapping[int, int] | None

The axis of the lattice of the target along every spatial coordinate the unknowns depend on, by the index of the coordinate.

None

Attributes:

Name Type Description
space_

The prepared space.

equations_

The mixed Einstein tensor G^mu_nu of the space, whose kept components the laws simplify.

Raises:

Type Description
ValidationError

A state is not a name, the components do not give one index pair per state, the source is not callable, or an equation does not reduce to rate laws of the states.

SpaceError

The space is not a pseudo-Riemannian space with curvature, raised by prepare.

Examples:

>>> from sage.all__sagemath_symbolics import SR, diagonal_matrix, function, sin
>>> from skcomplex.core.components.elements import Element
>>> from skcomplex.core.systems import System
>>> from skcomplex.systems.physics.cosmology import EinsteinFieldEquationsInteraction
>>> from skcomplex.systems.physics.common.relativity import SpacetimeSpace
>>> t, r, theta, phi = SR.var('t r theta phi')
>>> a = function('a')(t)
>>> metric = diagonal_matrix(SR, [-1, a**2, a**2 * r**2, a**2 * r**2 * sin(theta) ** 2])
>>> flat = SpacetimeSpace(metric, (t, r, theta, phi))
>>> vacuum = EinsteinFieldEquationsInteraction(
...     'vacuum', target='universe', states='a', space=flat, components=[(1, 1)], cosmological_constant=3.0
... )
>>> universe = Element('universe', values={'a': 1.0, "a'": 1.0})
>>> system = System(elements=[universe], interactions=[vacuum]).prepare()
>>> trajectory = system.simulate(until=1.0, dt=0.001)
>>> round(float(trajectory.get_values('universe.a')[-1]), 4)
2.7183
Source code in src/skcomplex/systems/physics/cosmology/_metric_cosmologies.py
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
def __init__(
    self,
    label: str,
    *,
    target: Role,
    states: str | Sequence[str] = 'x',
    space: SpacetimeSpace | None = None,
    components: Sequence[tuple[int, int]] = (),
    source: Callable[[SimpleNamespace], object] | None = None,
    coupling: float = 8 * math.pi,
    cosmological_constant: float = 0.0,
    time: int = 0,
    axes: Mapping[int, int] | None = None,
) -> None:
    super().__init__(label)
    self.target = target
    self.states = states
    self.space = space
    self.components = components
    self.source = source
    self.coupling = coupling
    self.cosmological_constant = cosmological_constant
    self.time = time
    self.axes = axes

FLRWCosmologySystem(a=0.3, *, H0=1.0, omega_matter=0.3, omega_radiation=0.0, omega_lambda=0.7, label='system', solver='auto', backend='auto')

Bases: BaseSystem

A homogeneous universe whose expansion follows from the Einstein equations.

The equations are those of the Robertson-Walker metric.

The metric of RobertsonWalkerSpace gives, through its Einstein tensor, the two Friedmann equations of a perfect fluid of density rho and pressure p. The space-space component G^r_r = -(2 a a'' + a'² + k) / a² = κ p is the law of the scale factor, and the time-time component G^t_t = -3 (a'² + k) / a² = -κ rho is the constraint (a'/a)² = κ rho / 3 - k / a², which sets the initial rate and which the evolution keeps. The fluid holds matter of pressure 0, radiation of pressure rho / 3, and the vacuum energy of a cosmological constant of pressure -rho, with the density parameters today, at a = 1, and the curvature k = -Ω_k H0² of the remainder Ω_k = 1 - Ω_m - Ω_r - Ω_Λ. Units have G = c = 1. The system has the scale factor universe.a and its rate universe.a'.

Parameters:

Name Type Description Default
a float

The initial scale factor.

0.3
H0 float

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

1.0
omega_matter float

The density parameter of matter.

0.3
omega_radiation float

The density parameter of radiation.

0.0
omega_lambda float

The density parameter of the cosmological constant.

0.7
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Raises:

Type Description
ValidationError

The universe does not expand at the initial scale factor.

Examples:

>>> from skcomplex.systems.physics.cosmology import FLRWCosmologySystem
>>> system = FLRWCosmologySystem(1.0, omega_matter=1.0, omega_lambda=0.0).prepare()
>>> float(system.simulate(until=0.1).get_values("universe.a'")[0])
1.0
Source code in src/skcomplex/systems/physics/cosmology/_metric_cosmologies.py
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
def __init__(
    self,
    a: float = 0.3,
    *,
    H0: float = 1.0,
    omega_matter: float = 0.3,
    omega_radiation: float = 0.0,
    omega_lambda: float = 0.7,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.a = a
    self.H0 = H0
    self.omega_matter = omega_matter
    self.omega_radiation = omega_radiation
    self.omega_lambda = omega_lambda

FriedmannAccelerationInteraction(label, *, target, H0=1.0, omega_matter=0.3, omega_lambda=0.7)

Bases: Interaction

Acceleration of the scale factor of a universe of matter and dark energy.

The scale factor a of the target follows a'' = -Ω_m H0² / (2 a²) + Ω_Λ H0² a, the force of the potential -Ω_m H0² / (2 a) - Ω_Λ H0² a² / 2.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the universe.

required
H0 Annotated[float, open(0, oo)]

The Hubble constant.

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

The density parameter of matter.

0.3
omega_lambda float

The density parameter of dark energy.

0.7

Examples:

>>> from skcomplex.systems.physics.cosmology import FriedmannAccelerationInteraction
>>> FriedmannAccelerationInteraction('acceleration', target='universe', H0=2.0).H0
2.0
Source code in src/skcomplex/systems/physics/cosmology/_expansion.py
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
def __init__(
    self,
    label: str,
    *,
    target: Role,
    H0: Annotated[float, RealSet.open(0, oo)] = 1.0,
    omega_matter: Annotated[float, RealSet.closed_open(0, oo)] = 0.3,
    omega_lambda: float = 0.7,
) -> None:
    super().__init__(label)
    self.target = target
    self.H0 = H0
    self.omega_matter = omega_matter
    self.omega_lambda = omega_lambda

FriedmannExpansionSystem(a=1.0, *, H0=1.0, omega_matter=0.3, omega_lambda=0.7, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The scale factor of a homogeneous universe of matter and dark energy.

The system follows 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). The system has the scale factor universe.a and its rate universe.a'.

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
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Raises:

Type Description
ValidationError

The universe does not expand at the initial scale factor.

Examples:

>>> from skcomplex.systems.physics.cosmology import FriedmannExpansionSystem
>>> system = FriedmannExpansionSystem(omega_matter=1.0, omega_lambda=0.0).prepare()
>>> float(system.simulate(until=1.0).get_values("universe.a'")[0])
1.0
Source code in src/skcomplex/systems/physics/cosmology/_expansion.py
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
def __init__(
    self,
    a: float = 1.0,
    *,
    H0: float = 1.0,
    omega_matter: float = 0.3,
    omega_lambda: float = 0.7,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.a = a
    self.H0 = H0
    self.omega_matter = omega_matter
    self.omega_lambda = omega_lambda

HomogeneousUniverseElement(label, *, a=1.0, H0=1.0, omega_matter=0.3, omega_radiation=0.0, omega_lambda=0.7, values=None)

Bases: Element

Homogeneous universe of matter, radiation, and vacuum energy.

The universe has the scale factor a, and its rate is the derivative a'.

The densities are measured by their parameters Ω today, at a = 1, relative to the critical density 3 H0² / κ: matter dilutes as a⁻³, radiation as a⁻⁴, and the vacuum energy of a cosmological constant stays.

Parameters:

Name Type Description Default
label str

The label of the universe.

required
a Annotated[float, open(0, oo)]

The initial scale factor.

1.0
H0 Annotated[float, open(0, oo)]

The Hubble constant today.

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

The density parameter of matter.

0.3
omega_radiation Annotated[float, closed_open(0, oo)]

The density parameter of radiation.

0.0
omega_lambda float

The density parameter of the cosmological constant.

0.7
values Mapping[str, object] | None

Further values by name, such as the initial rate a' of the scale factor, or None.

None

Examples:

>>> from skcomplex.systems.physics.cosmology import HomogeneousUniverseElement
>>> HomogeneousUniverseElement('universe', omega_radiation=1e-4).omega_radiation
0.0001
Source code in src/skcomplex/systems/physics/cosmology/_metric_cosmologies.py
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
def __init__(
    self,
    label: str,
    *,
    a: Annotated[float, RealSet.open(0, oo)] = 1.0,
    H0: Annotated[float, RealSet.open(0, oo)] = 1.0,
    omega_matter: Annotated[float, RealSet.closed_open(0, oo)] = 0.3,
    omega_radiation: Annotated[float, RealSet.closed_open(0, oo)] = 0.0,
    omega_lambda: float = 0.7,
    values: Mapping[str, object] | None = None,
) -> None:
    super().__init__(label, values=values)
    self.a = a
    self.H0 = H0
    self.omega_matter = omega_matter
    self.omega_radiation = omega_radiation
    self.omega_lambda = omega_lambda

LemaitreTolmanBondiSpace(*, label='space')

Bases: SpacetimeSpace

Spherical spacetime of dust in comoving coordinates.

This is the Lemaître-Tolman-Bondi ansatz.

The line element in (t, r, theta, phi) is ds² = -dt² + (∂R/∂r)² dr² / (1 + 2 E(r)) + R(t, r)² (dθ² + sin²θ dφ²), where the areal radius R(t, r) of the shell of comoving radius r is the unknown and E(r) is the energy of the shell per unit mass. They are the functions R and energy, a state and a parameter of the target of EinsteinFieldEquationsInteraction.

Parameters:

Name Type Description Default
label str

The label of the space in its system.

'space'

Examples:

>>> from skcomplex.systems.physics.cosmology import LemaitreTolmanBondiSpace
>>> space = LemaitreTolmanBondiSpace().prepare()
>>> space.metric_[2, 2]
R(t, r)^2
Source code in src/skcomplex/systems/physics/cosmology/_metric_cosmologies.py
479
480
def __init__(self, *, label: str = 'space') -> None:
    super().__init__(curvature=True, label=label)

OppenheimerSnyderCollapseSystem(n_shells=32, *, radius=10.0, mass=1.0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

A ball of dust at rest that collapses under its own gravity into a black hole.

The collapse follows Oppenheimer and Snyder.

The ball is a field of comoving shells on a radial lattice, the Lemaître-Tolman-Bondi ansatz of LemaitreTolmanBondiSpace in units with G = c = 1. Dust has no pressure, so the radial component of the Einstein equations, G^r_r = -(R'² + 2 R R'' - 2 E) / R² = 0 with ' the derivative by proper time, is the law of the areal radius R of every shell, and its first integral R'² = 2 M(r) / R + 2 E(r), from G^t_t, holds the mass M(r) inside the shell. A uniform ball of mass M and radius R₀ at rest has M(r) = M (r / R₀)³ and E(r) = -M(r) / r, so every shell follows the same cycloid R = r (1 + cos η) / 2 with t = (η + sin η) / (2 √k) and k = 2 M / R₀³, as the interior of Oppenheimer and Snyder. The surface crosses its Schwarzschild radius 2 M and the ball reaches zero size at the proper time π / (2 √k). The system has the areal radius ball.R of every shell and its rate ball.R'.

Parameters:

Name Type Description Default
n_shells int

The number of shells, which split the comoving radius R₀ evenly, the outermost at the surface.

32
radius float

The initial radius R₀ of the ball.

10.0
mass float

The mass M of the ball.

1.0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Raises:

Type Description
ValidationError

The ball starts inside its Schwarzschild radius.

Examples:

>>> from skcomplex.systems.physics.cosmology import OppenheimerSnyderCollapseSystem
>>> round(float(OppenheimerSnyderCollapseSystem(4).prepare().system_.elements[0].energy[-1]), 3)
-0.1
Source code in src/skcomplex/systems/physics/cosmology/_metric_cosmologies.py
770
771
772
773
774
775
776
777
778
779
780
781
782
783
def __init__(
    self,
    n_shells: int = 32,
    *,
    radius: float = 10.0,
    mass: float = 1.0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.n_shells = n_shells
    self.radius = radius
    self.mass = mass

RobertsonWalkerSpace(k=0.0, *, label='space')

Bases: SpacetimeSpace

Homogeneous and isotropic spacetime of the Robertson-Walker ansatz.

The scale factor a(t) is unknown.

The line element in the comoving coordinates (t, r, theta, phi) is ds² = -dt² + a(t)² (dr² / (1 - k r²) + r² (dθ² + sin²θ dφ²)), with the spatial curvature k. The scale factor is the function a that EinsteinFieldEquationsInteraction solves for, the state a of its target.

Parameters:

Name Type Description Default
k float

The spatial curvature, negative for an open, zero for a flat, and positive for a closed universe.

0.0
label str

The label of the space in its system.

'space'

Examples:

>>> from skcomplex.systems.physics.cosmology import RobertsonWalkerSpace
>>> space = RobertsonWalkerSpace(k=0.0).prepare()
>>> (space.inverse_metric_ * space.einstein_)[0, 0]
-3*diff(a(t), t)^2/a(t)^2
Source code in src/skcomplex/systems/physics/cosmology/_metric_cosmologies.py
443
444
445
def __init__(self, k: float = 0.0, *, label: str = 'space') -> None:
    super().__init__(curvature=True, label=label)
    self.k = k

ScaleFactorElement(label, *, a=1.0, values=None)

Bases: Element

Homogeneous universe whose size is the scale factor a.

The expansion rate is the derivative a'.

Parameters:

Name Type Description Default
label str

The label of the universe.

required
a Annotated[float, open(0, oo)]

The initial scale factor.

1.0
values Mapping[str, object] | None

Further values by name, such as the initial expansion rate a', or None.

None

Examples:

>>> from skcomplex.systems.physics.cosmology import ScaleFactorElement
>>> ScaleFactorElement('universe', a=2.0).a
2.0
Source code in src/skcomplex/systems/physics/cosmology/_expansion.py
49
50
51
52
53
54
55
56
57
def __init__(
    self,
    label: str,
    *,
    a: Annotated[float, RealSet.open(0, oo)] = 1.0,
    values: Mapping[str, object] | None = None,
) -> None:
    super().__init__(label, values=values)
    self.a = a