Strongly nonlinear oscillator under periodic impulses
An oscillator kicked by a periodic train of impulses of alternating sign.
- Class:
ImpulsiveOscillatorSystem - Import:
from skcomplex.systems.physics.nonlinear_oscillators import ImpulsiveOscillatorSystem - Field:
physics/nonlinear_oscillators - Topics:
ode,second order,impulses,events,forcing - References:
- Pilipchuk 2010
- Trzaska 2023
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.nonlinear_oscillators import ImpulsiveOscillatorSystem
trajectory = ImpulsiveOscillatorSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
x |
0.0 |
v |
2.572 |
H |
2.0 |
a |
0.4165 |
gamma |
0.0 |
spring |
'tangent' |
omega0 |
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 ImpulsiveOscillatorSystem(BaseSystem):
"""An oscillator kicked by a periodic train of impulses of alternating sign.
The stiff spring gives `x'' + tan(x) / cos²(x) = 2 H Σ_k (-1)^k δ(t - (2 k - 1) a)`, a strongly nonlinear
oscillator whose free motion `sin x = sin A sin(t / cos A)` of amplitude `A < π / 2` is known exactly. Between the
impulses the oscillator rings freely, and every impulse is an event that kicks its velocity, by `-2 H` at the times
`(4 k + 1) a` and by `2 H` at the times `(4 k + 3) a`. A motion of amplitude `A` is periodic with the period `4 a`
of the impulses when an impulse reverses its velocity, which gives
`a = q arccos(H q² / sqrt((1 - q²) (1 - q² H²)))` with `q = cos A`, for `arctan H < A < π / 2`. The defaults start
the orbit of amplitude `A = 1.2` for `H = 2`, from `x = 0` with the speed `tan A`.
The temporal dipole shift `gamma` in `(-1, 1)` replaces the rectangular wave whose derivative gives the impulses
with the derivative of an asymmetric saw-tooth wave: the negative impulses move to `(4 k + 1 - gamma) a`, the
positive ones to `(4 k + 3 + gamma) a`, and both grow to `2 H / (1 - gamma²)`. The linear spring gives the harmonic
oscillator `x'' + omega0² x` under the same impulses. The system has the displacement `oscillator.x` and its
velocity `oscillator.x'`, kicked by the impulses `pull` and `push`.
Args:
x:
The initial displacement.
v:
The initial velocity.
H:
The amplitude of the impulses.
a:
A quarter of the period of the impulses.
gamma:
The temporal dipole shift of the impulses, in `(-1, 1)`.
spring:
The restoring force, `'tangent'` for `tan(x) / cos²(x)` or `'linear'` for `omega0² x`.
omega0:
The natural frequency of the linear spring.
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:
ParameterError:
The spring is unknown, the quarter period is not positive, or the shift is outside `(-1, 1)`.
Examples:
>>> from skcomplex.systems.physics.nonlinear_oscillators import ImpulsiveOscillatorSystem
>>> ImpulsiveOscillatorSystem(a=0.5, gamma=0.5).prepare().system_.interactions[1].start
0.25
"""
field = 'physics/nonlinear_oscillators'
topics = ('ode', 'second order', 'impulses', 'events', 'forcing')
references = ('Pilipchuk 2010', 'Trzaska 2023')
until = 10.0
dt = 0.01
def __init__(
self,
x: float = 0.0,
v: float = 2.572,
*,
H: float = 2.0,
a: float = 0.4165,
gamma: float = 0.0,
spring: str = 'tangent',
omega0: 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.v = v
self.H = H
self.a = a
self.gamma = gamma
self.spring = spring
self.omega0 = omega0
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of an oscillator kicked by a periodic train of impulses of alternating sign.
Args:
context:
The observables to compile with the problem, or `None` for none.
Raises:
ParameterError:
The spring is unknown, the quarter period is not positive, or the shift is outside `(-1, 1)`.
"""
super()._prepare(context)
if self.spring not in SPRINGS:
error_msg = f'Unknown spring {self.spring!r}. Use one of {", ".join(SPRINGS)}.'
raise ParameterError(error_msg)
if not self.a > 0 or not -1 < self.gamma < 1:
error_msg = (
f'The impulses need a positive quarter period and a shift in (-1, 1), but got {self.a!r} and '
f'{self.gamma!r}.'
)
raise ParameterError(error_msg)
kick = 2 / (1 - self.gamma**2) * self.H
oscillator = ImpulsiveOscillatorElement('oscillator', x=self.x, H=self.H, values={"x'": self.v})
restoring = ImpulsiveSpringInteraction('spring', target='oscillator', spring=self.spring, omega0=self.omega0)
pull = KickInteraction(
'pull',
target='oscillator',
kick=-kick,
period=4 * self.a,
start=(1 - self.gamma) * self.a,
)
push = KickInteraction(
'push',
target='oscillator',
kick=kick,
period=4 * self.a,
start=(3 + self.gamma) * self.a,
)
solver = ScipyODESolver(method='DOP853', rtol=1e-10, atol=1e-12)
self.system_ = System(
self.label,
elements=[oscillator],
interactions=[restoring, pull, push],
solver=solver,
)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
ImpulsiveOscillatorElement, fromElement
Interactions:
ImpulsiveSpringInteraction, fromInteractionKickInteraction, fromInteraction
class ImpulsiveOscillatorElement(Element):
"""Displacement of an oscillator that rings freely between periodic impulses.
The impulses kick its velocity.
A spring interaction gives the restoring force, and kick interactions change the velocity `x'` by multiples of the
amplitude `H` at their times.
Args:
label:
The label of the oscillator.
x:
The initial displacement.
H:
The amplitude of the impulses, half the jump of the velocity that one impulse of the symmetric train
causes.
values:
Further values by name, such as the initial velocity `x'`, or `None`.
Examples:
>>> from skcomplex.systems.physics.nonlinear_oscillators import ImpulsiveOscillatorElement
>>> ImpulsiveOscillatorElement('oscillator').H
2.0
"""
def __init__(
self,
label: str,
*,
x: float = 0.0,
H: Annotated[float, RealSet.closed_open(0, oo)] = 2.0,
values: Mapping[str, object] | None = None,
) -> None:
super().__init__(label, values=values)
self.x = x
self.H = H
class ImpulsiveSpringInteraction(Interaction):
"""Restoring force of an impulsive oscillator, the stiff tangent spring or a linear one.
The tangent spring gives `x'' = -tan(x) / cos²(x)` and the linear spring `x'' = -omega0² x`.
Args:
label:
The label of the interaction.
target:
The path of the oscillator.
spring:
The restoring force, `'tangent'` for `tan(x) / cos²(x)` or `'linear'` for `omega0² x`.
omega0:
The natural frequency of the linear spring.
Raises:
ParameterError:
The spring is unknown.
Examples:
>>> from skcomplex.systems.physics.nonlinear_oscillators import ImpulsiveSpringInteraction
>>> ImpulsiveSpringInteraction('spring', target='oscillator', spring='linear').spring
'linear'
"""
law_classes = (RateLaw,)
def __init__(
self,
label: str,
*,
target: Role,
spring: str = 'tangent',
omega0: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
) -> None:
super().__init__(label)
self.target = target
self.spring = spring
self.omega0 = omega0
def _check_arguments(self) -> None:
"""Raise an error for an argument the interaction cannot take.
Raises:
ParameterError:
The spring is unknown.
"""
super()._check_arguments()
if self.spring not in SPRINGS:
error_msg = f'Unknown spring {self.spring!r}. Use one of {", ".join(SPRINGS)}.'
raise ParameterError(error_msg)
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the acceleration of the oscillator.
Args:
context:
The namespace of the oscillator, the time `t`, and the parameters.
"""
super()._prepare(context)
x = context.target.x
rate = -tan(x) / cos(x) ** 2 if self.spring == 'tangent' else -(context.omega0**2) * x
self.laws_ = [RateLaw(x.diff(context.t, 2), rate)]
class KickInteraction(Interaction):
"""Periodic kicks that change the velocity of an oscillator by a fixed amount.
Physics names them kicks, instantaneous changes of momentum at `start + j * period` for `j` from 0. Every kick adds
`kick` to the velocity `x'` of the state `x` of the target. A kick at the initial time of a run does not fire.
Args:
label:
The label of the interaction, unique among the components of its system.
target:
The path of the oscillator whose velocity the kicks change.
state:
The name of the state whose velocity the kicks change.
kick:
The change of the velocity at every kick.
period:
The period of the kicks.
start:
The time of the first kick.
Examples:
>>> from skcomplex.systems.physics.nonlinear_oscillators import KickInteraction
>>> KickInteraction('kick', target='oscillator', kick=-1.0, period=2.0).start
0.0
"""
law_classes = (EventLaw,)
def __init__(
self,
label: str,
*,
target: Role,
state: str = 'x',
kick: float = 1.0,
period: float = 1.0,
start: float = 0.0,
) -> None:
super().__init__(label)
self.target = target
self.state = state
self.kick = kick
self.period = period
self.start = start
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the event that kicks the velocity whenever the periodic guard crosses zero.
Args:
context:
The namespace of the oscillator, the time `t`, and the parameters.
"""
super()._prepare(context)
velocity = getattr(context.target, self.state).diff(context.t)
guard = periodic_guard(context.t, self.period, self.start)
self.laws_ = [EventLaw(guard, {velocity: velocity + context.kick}, label=self.label)]
Equations
The equations are those that symbolic returns for the system with its default parameters.
oscillator.x: diff(x_oscillator(t), t, t) == -tan(x_oscillator(t))/cos(x_oscillator(t))^2