Skip to content

Rotating balls on rods

Two balls on rods that turn about a vertical axis.

  • Class: RotatingBallsOnRodsSystem
  • Import: from skcomplex.systems.physics.mechanics import RotatingBallsOnRodsSystem
  • Field: physics/mechanics
  • Topics: mechanics, ode, rotation, angular momentum
  • References:
    • Ryzhov et al. 2021

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 RotatingBallsOnRodsSystem

trajectory = RotatingBallsOnRodsSystem().prepare().simulate()

Parameters

The model parameters take these defaults, and set_params changes them.

Parameter Default
omega 1.0
r 1.0
beta 1.5707963267948966
m 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
Randomness deterministic
Domains real
Structure fixed

Class

The source of the class shows how it builds its components from its model parameters.

class RotatingBallsOnRodsSystem(BaseSystem):
    """Two balls on rods that turn about a vertical axis.

    The balls conserve their angular momentum.

    Each ball sits at the distance `r` along a rod fixed at the angle `β` to the axis, so its distance from the axis is
    `r sin β`. Its angular momentum `H = m ω r² sin² β` is fixed by the initial angular velocity, and the balls turn at
    `θ' = H / (m r² sin² β)`, so changing `r` during a run changes the angular velocity by `1 / r²`. The system has the
    angles `right.theta` and `left.theta` of the two balls.

    Args:
        omega:
            The initial angular velocity.

        r:
            The distance of the balls from the joint of the rods.

        beta:
            The angle of the rods to the vertical axis, in radians.

        m:
            The mass of every ball.

        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 RotatingBallsOnRodsSystem
        >>> RotatingBallsOnRodsSystem(omega=2.0).prepare().system_.elements[0].H
        2.0
    """

    field = 'physics/mechanics'
    topics = ('mechanics', 'ode', 'rotation', 'angular momentum')
    references = ('Ryzhov et al. 2021',)
    until = 10.0
    dt = 0.02

    def __init__(
        self,
        omega: float = 1.0,
        *,
        r: float = 1.0,
        beta: float = math.pi / 2,
        m: float = 1.0,
        label: str = 'system',
        solver: BaseSolver | str = 'auto',
        backend: BaseBackend | str = 'auto',
    ) -> None:
        super().__init__(label, solver=solver, backend=backend)
        self.omega = omega
        self.r = r
        self.beta = beta
        self.m = m

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set the system of two balls on rods that turn about a vertical axis.

        Args:
            context:
                The observables to compile with the problem, or `None` for none.
        """
        super()._prepare(context)
        momentum = self.m * self.omega * self.r**2 * math.sin(self.beta) ** 2
        self.system_ = System(
            self.label,
            elements=[
                RotatingBallElement('right', theta=0.0, m=self.m, r=self.r, beta=self.beta, H=momentum),
                RotatingBallElement('left', theta=math.pi, m=self.m, r=self.r, beta=self.beta, H=momentum),
            ],
            interactions=[RotationInteraction(f'{ball}_turn', target=ball) for ball in ('right', 'left')],
        )

Components

The system uses these element and interaction classes, each with its nearest class of the core.

Elements:

  • RotatingBallElement, from Element

Interactions:

  • RotationInteraction, from Interaction
class RotatingBallElement(Element):
    """Ball of mass `m` on a rod at the distance `r` from the joint.

    The rod turns about a vertical axis by the angle `theta`.

    The rod is fixed at the angle `beta` to the axis, so the ball is at the distance `r sin β` from it, and `H` is its
    angular momentum about the axis.

    Args:
        label:
            The label of the ball.

        theta:
            The initial angle about the axis.

        m:
            The mass of the ball.

        r:
            The distance of the ball from the joint of the rod.

        beta:
            The angle of the rod to the axis, in radians.

        H:
            The angular momentum of the ball about the axis.

    Examples:
        >>> from skcomplex.systems.physics.mechanics import RotatingBallElement
        >>> RotatingBallElement('ball', H=2.0).H
        2.0
    """

    def __init__(
        self,
        label: str,
        *,
        theta: Annotated[float, Period(2 * math.pi)] = 0.0,
        m: Annotated[float, RealSet.open(0, oo)] = 1.0,
        r: Annotated[float, RealSet.open(0, oo)] = 1.0,
        beta: Annotated[float, RealSet.open(0, oo)] = math.pi / 2,
        H: float = 1.0,
    ) -> None:
        super().__init__(label)
        self.theta = theta
        self.m = m
        self.r = r
        self.beta = beta
        self.H = H

class RotationInteraction(Interaction):
    """Rotation of a ball about an axis at the rate fixed by its angular momentum.

    The angle `theta` of the target follows `theta' = H / (m r² sin² β)`, with the angular momentum `H`, the mass `m`,
    the distance `r` from the joint, and the angle `β` of the rod, all values of the target.

    Args:
        label:
            The label of the interaction.

        target:
            The path of the ball.

    Examples:
        >>> from skcomplex.systems.physics.mechanics import RotationInteraction
        >>> RotationInteraction('turn', target='ball').target
        'ball'
    """

    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 rate of the angle of the ball.

        Args:
            context:
                The namespace of the ball and the time `t`.
        """
        super()._prepare(context)
        ball = context.target
        self.laws_ = [RateLaw(ball.theta.diff(context.t), ball.H / (ball.m * ball.r**2 * sin(ball.beta) ** 2))]

Equations

The equations are those that symbolic returns for the system with its default parameters.

right.theta: diff(theta_right(t), t) == H_right/(m_right*r_right^2*sin(beta_right)^2)
left.theta: diff(theta_left(t), t) == H_left/(m_left*r_left^2*sin(beta_left)^2)