Restricted three-body problem
A light body moving in the plane of two primaries on circular orbits.
- Class:
RestrictedThreeBodySystem - Import:
from skcomplex.systems.physics.celestial_mechanics import RestrictedThreeBodySystem - Field:
physics/celestial_mechanics - Topics:
mechanics,ode,gravity,chaos,rotating frame,hamiltonian - References:
- Dilão 2023
- Szebehely 1967
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 RestrictedThreeBodySystem
trajectory = RestrictedThreeBodySystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
x |
0.5 |
y |
0.0 |
vx |
0.0 |
vy |
1.15 |
mu |
0.01215 |
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 | none |
| Laws | rate |
| Randomness | deterministic |
| Domains | real |
| Structure | fixed |
Class
The source of the class shows how it builds its components from its model parameters.
class RestrictedThreeBodySystem(BaseSystem):
"""A light body moving in the plane of two primaries on circular orbits.
The body moves in the frame that rotates with the primaries.
The primaries of masses `1 - μ` and `μ` sit at `(-μ, 0)` and `(1 - μ, 0)`, and the light body moves under the
Hamiltonian `H = (px² + py²) / 2 + y px - x py - (1 - μ) / r1 - μ / r2` of the rotating frame, with the momenta
`px = x' - y` and `py = y' + x`. Its terms `y px - x py` couple the coordinates and the momenta, so the Hamiltonian
is not separable. It equals minus half the Jacobi constant `x² + y² + 2 (1 - μ) / r1 + 2 μ / r2 - x'² - y'²`, which
is conserved. The default `μ` is that of the Earth and the Moon.
The default start has the Jacobi constant 2.835, below that of the neck towards the Moon, and its orbit is chaotic:
it passes near the Moon after 3.5 time units and wanders between the two primaries, with a Lyapunov exponent near
0.2. Starts of a larger constant are confined around the Earth, such as `vy = 0.8` with the constant 3.52, which
traces a regular precessing rosette. The system has the coordinates `body.x` and `body.y` and the momenta `body.px`
and `body.py`.
Args:
x:
The initial first coordinate.
y:
The initial second coordinate.
vx:
The initial first velocity.
vy:
The initial second velocity.
mu:
The mass of the lighter primary, as a fraction of the total.
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.
Examples:
>>> from skcomplex.systems.physics.celestial_mechanics import RestrictedThreeBodySystem
>>> RestrictedThreeBodySystem(mu=0.1).prepare().system_.elements[0].mu
0.1
"""
field = 'physics/celestial_mechanics'
topics = ('mechanics', 'ode', 'gravity', 'chaos', 'rotating frame', 'hamiltonian')
references = ('Dilão 2023', 'Szebehely 1967')
until = 20.0
dt = 0.02
invariants: ClassVar[Mapping[str, float]] = {'body.energy': 1e-6}
observables = (Observable('energy', _get_rotating_frame_energy, element='body'),)
def __init__(
self,
x: float = 0.5,
y: float = 0.0,
vx: float = 0.0,
vy: float = 1.15,
*,
mu: float = 0.01215,
label: str = 'system',
solver: BaseSolver | str = 'auto',
backend: BaseBackend | str = 'auto',
) -> None:
super().__init__(label, solver=solver, backend=backend)
self.x = x
self.y = y
self.vx = vx
self.vy = vy
self.mu = mu
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of a light body in the frame that rotates with two primaries.
Args:
context:
The observables to compile with the problem, or `None` for none.
"""
super()._prepare(context)
body = RotatingFrameBodyElement(
'body',
x=self.x,
y=self.y,
px=self.vx - self.y,
py=self.vy + self.x,
mu=self.mu,
)
motion = RotatingFrameMotionInteraction('motion', target='body')
self.system_ = System(self.label, elements=[body], interactions=[motion], solver=RK4Solver())
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
RotatingFrameBodyElement, fromElement
Interactions:
RotatingFrameMotionInteraction, fromInteraction
class RotatingFrameBodyElement(Element):
"""Light body at `(x, y)` with canonical momenta `(px, py)` in a rotating frame.
The frame rotates with two primaries.
The momenta are `px = x' - y` and `py = y' + x` for the unit angular velocity of the frame. The primaries of masses
`1 - mu` and `mu` sit at `(-mu, 0)` and `(1 - mu, 0)`.
Args:
label:
The label of the body.
x:
The initial first coordinate.
y:
The initial second coordinate.
px:
The initial first momentum.
py:
The initial second momentum.
mu:
The mass of the lighter primary, as a fraction of the total.
Examples:
>>> from skcomplex.systems.physics.celestial_mechanics import RotatingFrameBodyElement
>>> RotatingFrameBodyElement('body', mu=0.1).mu
0.1
"""
visual = VisualSpec('bodies', {'positions': ('x', 'y'), 'trail': None, 'marks': _get_primaries})
def __init__(
self,
label: str,
*,
x: float = 0.5,
y: float = 0.0,
px: float = 0.0,
py: float = 0.5,
mu: Annotated[float, RealSet.open(0, oo)] = 0.01215,
) -> None:
super().__init__(label)
self.x = x
self.y = y
self.px = px
self.py = py
self.mu = mu
class RotatingFrameMotionInteraction(Interaction):
"""Motion of a light body in the frame that rotates with two primaries.
The coordinates `(x, y)` and the momenta `(px, py)` of the target follow Hamilton's equations `q' = dH/dp` and
`p' = -dH/dq` of `H = (px² + py²) / 2 + y px - x py - (1 - mu) / r1 - mu / r2`, with the distances `r1` and `r2` to
the primaries at `(-mu, 0)` and `(1 - mu, 0)` and the mass fraction `mu` of the target.
Args:
label:
The label of the interaction.
target:
The path of the light body.
Examples:
>>> from skcomplex.systems.physics.celestial_mechanics import RotatingFrameMotionInteraction
>>> RotatingFrameMotionInteraction('motion', target='body').target
'body'
"""
law_classes = (RateLaw,)
def __init__(self, label: str, *, target: Role) -> None:
super().__init__(label)
self.target = target
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the rates of the coordinates and the momenta of the light body.
Args:
context:
The namespace of the light body and the time `t`.
"""
super()._prepare(context)
body = context.target
t = context.t
names = ('x', 'y', 'px', 'py')
values = [getattr(body, name) for name in names]
symbols = [SR.symbol(f'_{name}') for name in names]
x, y, px, py = symbols
hamiltonian = _get_rotating_frame_energy(SimpleNamespace(x=x, y=y, px=px, py=py, mu=body.mu))
back = dict(zip(symbols, values, strict=True))
rates = [hamiltonian.diff(px), hamiltonian.diff(py), -hamiltonian.diff(x), -hamiltonian.diff(y)]
self.laws_ = [RateLaw(value.diff(t), rate.subs(back)) for value, rate in zip(values, rates, strict=True)]
Equations
The equations are those that symbolic returns for the system with its default parameters.
body.x: diff(x_body(t), t) == px_body(t) + y_body(t)
body.y: diff(y_body(t), t) == py_body(t) - x_body(t)
body.px: diff(px_body(t), t) == (mu_body + x_body(t))*(mu_body - 1)/((mu_body + x_body(t))^2 + y_body(t)^2)^(3/2) - (mu_body + x_body(t) - 1)*mu_body/((mu_body + x_body(t) - 1)^2 + y_body(t)^2)^(3/2) + py_body(t)
body.py: diff(py_body(t), t) == (mu_body - 1)*y_body(t)/((mu_body + x_body(t))^2 + y_body(t)^2)^(3/2) - mu_body*y_body(t)/((mu_body + x_body(t) - 1)^2 + y_body(t)^2)^(3/2) - px_body(t)