Bending of light by a mass
A light ray that passes a static mass and is deflected towards it.
- Class:
LightBendingSystem - Import:
from skcomplex.systems.physics.celestial_mechanics import LightBendingSystem - Field:
physics/celestial_mechanics - Topics:
general relativity,ode,second order,gravity,geodesics,light - References:
- Schwichtenberg 2020
- Satz 2022
- Einstein 1915
- Dyson, Eddington, and Davidson 1920
Use this system
The block imports the class and simulates the system with its default parameters and its tuned run settings.
from skcomplex.systems.physics.celestial_mechanics import LightBendingSystem
trajectory = LightBendingSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
impact_parameter |
20.0 |
distance |
2000.0 |
mass |
1.0 |
solver |
'auto' |
backend |
'auto' |
Tags
The system with its default parameters has these capability tags, which solvers and analyses check.
| Tag | Values |
|---|---|
| Time | continuous |
| Space | curved spacetime |
| Laws | rate |
| Randomness | deterministic |
| Domains | vector |
| Structure | fixed |
Class
The source of the class shows how it builds its components from its model parameters.
class LightBendingSystem(BaseSystem):
"""A light ray that passes a static mass and is deflected towards it.
The ray follows a null geodesic of the Schwarzschild spacetime `SchwarzschildSpace`, in units with `G = c = 1`, with
the affine parameter as the time of the system. It starts at the distance `D` along the axis behind the mass, offset
by the impact parameter `b`, aimed parallel to the axis, with the energy `E = 1` and the angular momentum `L = b`.
Far from the mass the ray bends by `4 M / b`, twice the Newtonian deflection of a particle at the speed of light, as
the eclipse of 1919 measured for starlight that grazes the Sun. The system has the position `photon.x = (t, r,
theta, phi)` and the tangent `photon.x'`.
Args:
impact_parameter:
The impact parameter `b`, the distance of the unbent ray from the mass.
distance:
The distance `D` along the axis from which the ray starts.
mass:
The mass `M` of the central body.
label:
The label of the system, which names it when it is nested in another one.
solver:
The solver of the problem, or `'auto'` for the one the system chooses.
backend:
The backend that evaluates the compiled functions, or `'auto'` for the one the system chooses.
Raises:
ValidationError:
The ray would be captured by the mass, its impact parameter being at most `3 √3 M`, or it starts closer
than its impact parameter.
Examples:
>>> from skcomplex.systems.physics.celestial_mechanics import LightBendingSystem
>>> round(LightBendingSystem().prepare().system_.elements[0].values["x'"][0], 4)
1.001
"""
field = 'physics/celestial_mechanics'
topics = ('general relativity', 'ode', 'second order', 'gravity', 'geodesics', 'light')
references = ('Schwichtenberg 2020', 'Satz 2022', 'Einstein 1915', 'Dyson, Eddington, and Davidson 1920')
until = 4000.0
dt = 4.0
def __init__(
self,
impact_parameter: float = 20.0,
distance: float = 2000.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.impact_parameter = impact_parameter
self.distance = distance
self.mass = mass
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of a light ray that passes a static mass and is deflected towards it.
Args:
context:
The observables to compile with the problem, or `None` for none.
"""
super()._prepare(context)
if self.impact_parameter <= 3 * math.sqrt(3) * self.mass:
error_msg = (
f'The impact parameter {self.impact_parameter} is at most 3 √3 M = {3 * math.sqrt(3) * self.mass}, so '
'the mass captures the ray. Give a larger impact parameter.'
)
raise ValidationError(error_msg)
if self.distance <= self.impact_parameter:
error_msg = f'The distance {self.distance} is not larger than the impact parameter {self.impact_parameter}.'
raise ValidationError(error_msg)
radius = math.hypot(self.distance, self.impact_parameter)
lapse = 1 - 2 * self.mass / radius
radial = -math.sqrt(1 - lapse * self.impact_parameter**2 / radius**2)
photon = GeodesicParticleElement(
'photon',
x=[0.0, radius, EQUATOR, math.atan2(self.impact_parameter, -self.distance)],
values={"x'": [1 / lapse, radial, 0.0, -self.impact_parameter / radius**2]},
)
space = SchwarzschildSpace(mass=self.mass)
geodesic = GeodesicInteraction('geodesic', target='photon', space=space)
self.system_ = System(
self.label,
elements=[photon],
interactions=[geodesic],
space=space,
solver=GEODESIC_SOLVER,
)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
GeodesicParticleElement, fromElement
Interactions:
GeodesicInteraction, fromInteraction
class GeodesicParticleElement(Element):
"""Test particle at the spacetime position `x = (t, r, theta, phi)` near a mass.
The mass is central, and the particle has its four-velocity.
The position is a vector in the Schwarzschild or Boyer-Lindquist coordinates of the space, and its derivative `x'`
is the four-velocity, the derivative of the position by the proper time of a massive particle or by the affine
parameter of a light ray. The particle is drawn in the equatorial plane, at `(r cos phi, r sin phi)`.
Args:
label:
The label of the particle.
x:
The initial position `(t, r, theta, phi)`.
values:
Further values by name, such as the initial four-velocity `x'`, or `None`.
Examples:
>>> from skcomplex.systems.physics.celestial_mechanics import GeodesicParticleElement
>>> GeodesicParticleElement('particle', x=[0.0, 10.0, 1.5708, 0.0]).x
[0.0, 10.0, 1.5708, 0.0]
"""
visual = VisualSpec(
'bodies',
{
'positions': _get_equatorial_position,
'trail': None,
'marks': _get_central_mass,
},
)
def __init__(
self,
label: str,
x: npt.ArrayLike = (0.0, 0.0, 0.0, 0.0),
*,
values: Mapping[str, object] | None = None,
) -> None:
super().__init__(label, values=values)
self.x = x
class GeodesicInteraction(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.
Args:
label:
The label of the interaction, unique among the components of its system.
target:
The path of the element or group whose state is the position.
state:
The name of the vector state that is the position.
space:
The pseudo-Riemannian space whose geodesics the point follows, usually the space of the system too.
Attributes:
space_:
The prepared space, whose Christoffel symbols the rate reads.
Raises:
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]
"""
law_classes: ClassVar[tuple[type[BaseLaw], ...]] = (RateLaw,)
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
def _check_arguments(self) -> None:
"""Raise an error for an argument the interaction cannot take.
Raises:
SpaceError:
The space is not a pseudo-Riemannian space.
ValidationError:
The type declares states, the state is not a name, or the position has not one component per
coordinate of the space.
"""
super()._check_arguments()
if not isinstance(self.state, str) or not self.state.isidentifier():
error_msg = (
f'{type(self).__name__} {self.label!r} moves the state {self.state!r}. Give the name of a state.'
)
raise ValidationError(error_msg)
if not isinstance(self.space, SpacetimeSpace):
error_msg = (
f'{type(self).__name__} {self.label!r} moves a point along the geodesics of {self.space!r}. Give a '
'`SpacetimeSpace`.'
)
raise SpaceError(error_msg)
self.space_ = self.space.prepare()
def _prepare(self, context: SimpleNamespace) -> None:
"""Set `space_`, the prepared pseudo-Riemannian space, and the law of a binding.
It first raises an error for a state that is not a name.
Args:
context:
The namespace of the target and the time `t`.
"""
super()._prepare(context)
self.laws_ = self._get_geodesic_laws(context)
def _get_geodesic_laws(self, context: SimpleNamespace) -> list[BaseLaw]:
"""Return the rate law of the second derivative of the position.
It is minus the connection on the tangent.
Args:
context:
The namespace of the target and the time `t`.
Returns:
laws:
The rate law of the position.
Raises:
ValidationError:
The position has not one component per coordinate of the space.
"""
t = context.t
position = getattr(context.target, self.state)
components = list(position) if isinstance(position, FreeModuleElement) else [position]
coordinates = self.space_.coordinates_
if len(components) != len(coordinates):
error_msg = (
f'The position {self.state!r} of {self.label!r} has {len(components)} components for the '
f'{len(coordinates)} coordinates of the space. Give a vector state of the dimension of the space.'
)
raise ValidationError(error_msg)
at = dict(zip(coordinates, components, strict=True))
tangent = [SR(component).diff(t) for component in components]
indices = range(len(components))
rate = [
-sum(
(
SR(self.space_.christoffel_[mu][alpha][beta]).subs(at) * tangent[alpha] * tangent[beta]
for alpha in indices
for beta in indices
if not SR(self.space_.christoffel_[mu][alpha][beta]).is_zero()
),
SR(0),
)
for mu in indices
]
if isinstance(position, FreeModuleElement):
return [RateLaw(position.diff(t, 2), vector(SR, rate))]
return [RateLaw(SR(position).diff(t, 2), rate[0])]