Circular billiard
A particle moving freely inside a circle and reflecting specularly off its wall.
- Class:
CircularBilliardSystem - Import:
from skcomplex.systems.physics.mechanics import CircularBilliardSystem - Field:
physics/mechanics - Topics:
mechanics,events,billiard,integrable - References:
- Tabachnikov 2005
- Datseris and Parlitz 2022
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.mechanics import CircularBilliardSystem
trajectory = CircularBilliardSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
x |
0.3 |
y |
0.0 |
vx |
0.4 |
vy |
1.0 |
radius |
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 | none |
| Laws | rate, update |
| Randomness | deterministic |
| Domains | real |
| Structure | fixed |
Class
The source of the class shows how it builds its components from its model parameters.
class CircularBilliardSystem(systems.BaseSystem):
"""A particle moving freely inside a circle and reflecting specularly off its wall.
The angle of incidence is the same at every bounce, so the circular billiard is integrable. The system has the
position `particle.x`, `particle.y` and the velocity `particle.vx`, `particle.vy`.
Args:
x:
The initial horizontal position.
y:
The initial vertical position.
vx:
The initial horizontal velocity.
vy:
The initial vertical velocity.
radius:
The radius of the table.
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.mechanics import CircularBilliardSystem
>>> CircularBilliardSystem(radius=2.0).prepare().system_.elements[0].radius
2.0
"""
field = 'physics/mechanics'
topics = ('mechanics', 'events', 'billiard', 'integrable')
references = ('Tabachnikov 2005', 'Datseris and Parlitz 2022')
until = 20.0
dt = 0.05
def __init__(
self,
x: float = 0.3,
y: float = 0.0,
vx: float = 0.4,
vy: float = 1.0,
*,
radius: float = 1.0,
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.radius = radius
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of a particle moving freely inside a circle and reflecting off its wall.
Args:
context:
The observables to compile with the problem, or `None` for none.
"""
super()._prepare(context)
particle = DiscBilliardElement('particle', x=self.x, y=self.y, vx=self.vx, vy=self.vy, radius=self.radius)
self.system_ = systems.System(
self.label,
elements=[particle],
interactions=[
FreeFlightInteraction('flight', target='particle'),
DiscWallInteraction('bounce', target='particle'),
],
)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
DiscBilliardElement, fromElement
Interactions:
FreeFlightInteraction, fromInteractionDiscWallInteraction, fromInteraction
class DiscBilliardElement(Element):
"""Particle moving freely in the plane inside a disc.
The particle has the position `(x, y)` and the velocity `(vx, vy)`, and the disc the radius `radius`.
Args:
label:
The label of the particle.
x:
The initial horizontal position.
y:
The initial vertical position.
vx:
The initial horizontal velocity.
vy:
The initial vertical velocity.
radius:
The radius of the disc.
Examples:
>>> from skcomplex.systems.physics.mechanics import DiscBilliardElement
>>> DiscBilliardElement('particle', radius=2.0).radius
2.0
"""
visual = VisualSpec('bodies', {'positions': ('x', 'y'), 'trail': None, 'outline': _get_disc_wall})
def __init__(
self,
label: str,
*,
x: float = 0.3,
y: float = 0.0,
vx: float = 0.4,
vy: float = 1.0,
radius: Annotated[float, RealSet.open(0, oo)] = 1.0,
) -> None:
super().__init__(label)
self.x = x
self.y = y
self.vx = vx
self.vy = vy
self.radius = radius
class FreeFlightInteraction(Interaction):
"""Free flight of a particle in the plane, `x' = vx` and `y' = vy`.
The velocity `(vx, vy)` changes only at the walls, so the particle moves along straight lines between them.
Args:
label:
The label of the interaction.
target:
The path of the particle.
Examples:
>>> from skcomplex.systems.physics.mechanics import FreeFlightInteraction
>>> FreeFlightInteraction('flight', target='particle').target
'particle'
"""
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 position of the particle.
Args:
context:
The namespace of the particle and the time `t`.
"""
super()._prepare(context)
p, t = context.target, context.t
self.laws_ = [RateLaw(p.x.diff(t), p.vx), RateLaw(p.y.diff(t), p.vy)]
class DiscWallInteraction(Interaction):
"""Specular reflection of a particle off the wall of a disc of radius `radius`.
When the particle reaches the wall `x² + y² = radius²` from inside, its velocity `v = (vx, vy)` becomes
`v - 2 (v . n) n / |n|²` with the normal `n = (2 x, 2 y)`, so the angle of incidence equals the angle of
reflection. It is a circular billiard table, a gas in a round container, or light in a circular mirror.
Args:
label:
The label of the interaction.
target:
The path of the particle, whose values are `x`, `y`, `vx`, `vy`, and `radius`.
Examples:
>>> from skcomplex.systems.physics.mechanics import DiscWallInteraction
>>> DiscWallInteraction('bounce', target='particle').target
'particle'
"""
law_classes = (EventLaw,)
def __init__(self, label: str, *, target: Role) -> None:
super().__init__(label)
self.target = target
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the event that reflects the velocity about the normal of the wall.
Args:
context:
The namespace of the particle and the time `t`.
"""
super()._prepare(context)
p = context.target
guard = p.x**2 + p.y**2 - p.radius**2
normal = [2 * p.x, 2 * p.y]
velocities = [p.vx, p.vy]
speed = sum((v * n for v, n in zip(velocities, normal, strict=True)), SR(0))
scale = 2 * speed / sum((n**2 for n in normal), SR(0))
reset = {v: v - scale * n for v, n in zip(velocities, normal, strict=True)}
self.laws_ = [EventLaw(guard, reset, direction=1, label=self.label)]
Equations
The equations are those that symbolic returns for the system with its default parameters.
particle.x: diff(x_particle(t), t) == vx_particle(t)
particle.y: diff(y_particle(t), t) == vy_particle(t)
particle.vx: diff(vx_particle(t), t) == 0
particle.vy: diff(vy_particle(t), t) == 0