Skip to content

Relativity

Relativity shared by the physics packages.

Spacetimes derive their geometry from a metric with EinsteinPy, and free bodies follow their geodesics.

GeodesicInteraction(label, *, target, state='x', space=None)

Bases: Interaction

Geodesic equation x''^mu = -Γ^mu_(alpha beta)(x) x'^alpha x'^beta of a point.

The point is a point of a pseudo-Riemannian space. The state is a vector with one component per coordinate of the space, the position x^mu of a test particle, whose derivative x'^mu is the tangent. The time of the system is the affine parameter of the geodesic, the proper time of a timelike geodesic when the tangent starts with g_(mu nu) x'^mu x'^nu = -1. A tangent that starts null, with g_(mu nu) x'^mu x'^nu = 0, follows a light ray. Either norm is conserved along the geodesic, so it measures the error of a run. The Christoffel symbols are those the space derives from its metric.

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 group whose state is the position.

required
state str

The name of the vector state that is the position.

'x'
space SpacetimeSpace | None

The pseudo-Riemannian space whose geodesics the point follows, usually the space of the system too.

None

Attributes:

Name Type Description
space_

The prepared space, whose Christoffel symbols the rate reads.

Raises:

Type Description
ValidationError

The state is not a name.

SpaceError

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

Examples:

>>> from sage.all__sagemath_symbolics import SR, matrix
>>> from skcomplex.core.components.elements import Element
>>> from skcomplex.core.systems import System
>>> from skcomplex.systems.physics.common.relativity import GeodesicInteraction
>>> from skcomplex.systems.physics.common.relativity import SpacetimeSpace
>>> r, phi = SR.var('r phi')
>>> plane = SpacetimeSpace(matrix(SR, [[1, 0], [0, r**2]]), (r, phi))
>>> line = GeodesicInteraction('line', target='particle', space=plane)
>>> particle = Element('particle', values={'x': [1.0, 0.0], "x'": [0.0, 1.0]})
>>> system = System(elements=[particle], interactions=[line], space=plane).prepare()
>>> trajectory = system.simulate(until=1.0, dt=0.001)
>>> [round(float(value), 3) for value in trajectory.get_values('particle.x')[-1]]
[1.414, 0.785]
Source code in src/skcomplex/systems/physics/common/relativity/_spacetime.py
351
352
353
354
355
356
357
358
359
360
361
362
def __init__(
    self,
    label: str,
    *,
    target: Role,
    state: str = 'x',
    space: SpacetimeSpace | None = None,
) -> None:
    super().__init__(label)
    self.target = target
    self.state = state
    self.space = space

SpacetimeSpace(metric=None, coordinates=(), *, curvature=True, label='space')

Bases: ContinuousSpace

Chart of coordinates with a symbolic metric g_(mu nu).

The connection and the curvature follow from the metric. The metric is a symmetric, nondegenerate Sage matrix whose entries are expressions of the coordinates, numbers, and symbolic functions of the coordinates. A function stands for an unknown of an ansatz, such as the scale factor a(t) of a homogeneous universe, which a field equation of the metric solves for. The space is an unbounded continuous space with one dimension per coordinate, so a point on it has one component per coordinate, as a test particle of GeodesicInteraction does.

prepare derives, through EinsteinPy, the Christoffel symbols Γ^mu_(alpha beta) = g^(mu lambda) (∂_alpha g_(lambda beta) + ∂_beta g_(lambda alpha) - ∂_lambda g_(alpha beta))/2 and, with curvature, the Riemann tensor R^rho_(sigma mu nu), its contraction the Ricci tensor R_(mu nu) = R^rho_(mu rho nu), the Ricci scalar R = g^(mu nu) R_(mu nu), and the Einstein tensor G_(mu nu) = R_(mu nu) - R g_(mu nu) / 2. The curvature of a metric with many entries, such as Kerr's, takes long to simplify, so it can be left out when only the connection is needed.

Parameters:

Name Type Description Default
metric Matrix | Sequence[Sequence[object]] | None

The metric, a square matrix of expressions, or None for the metric a subclass derives.

None
coordinates Sequence[Expression | str]

The coordinates, Sage variables or their names, in the order of the rows of the metric.

()
curvature bool

Whether prepare derives the curvature tensors besides the Christoffel symbols.

True
label str

The label of the space in its system.

'space'

Attributes:

Name Type Description
coordinates_

The coordinates, as Sage variables.

metric_

The metric g_(mu nu).

inverse_metric_

The inverse metric g^(mu nu).

christoffel_

The Christoffel symbols, with christoffel_[mu][alpha][beta] the symbol Γ^mu_(alpha beta).

riemann_

The Riemann tensor, with riemann_[rho][sigma][mu][nu] the component R^rho_(sigma mu nu), or None without curvature.

ricci_

The Ricci tensor R_(mu nu), or None without curvature.

ricci_scalar_

The Ricci scalar, or None without curvature.

einstein_

The Einstein tensor G_(mu nu), or None without curvature.

derived_from_

The metric, the coordinates, and the curvature flag the tensors were derived from, which a later prepare compares by value to skip the derivation when they have not changed.

Raises:

Type Description
ValidationError

The metric is not a symmetric square matrix of one row per coordinate, a coordinate is not a variable, two coordinates coincide, or the metric is degenerate.

Examples:

>>> from sage.all__sagemath_symbolics import SR, matrix, sin
>>> from skcomplex.systems.physics.common.relativity import SpacetimeSpace
>>> theta, phi = SR.var('theta phi')
>>> sphere = SpacetimeSpace(matrix(SR, [[1, 0], [0, sin(theta) ** 2]]), (theta, phi)).prepare()
>>> sphere.christoffel_[0][1][1]
-cos(theta)*sin(theta)
>>> sphere.ricci_scalar_
2
Source code in src/skcomplex/systems/physics/common/relativity/_spacetime.py
110
111
112
113
114
115
116
117
118
119
120
121
def __init__(
    self,
    metric: Matrix | Sequence[Sequence[object]] | None = None,
    coordinates: Sequence[Expression | str] = (),
    *,
    curvature: bool = True,
    label: str = 'space',
) -> None:
    super().__init__(label=label)
    self.metric = metric
    self.coordinates = coordinates
    self.curvature = curvature