Bouncing Ball
What you'll learn
- Event handling in Modelica with
whenandreinit - How discrete events interact with continuous dynamics
- The effect of energy loss on repeated impacts
This example introduces event handling. A ball is dropped from height
h and bounces with a coefficient of restitution e. The Modelica
when clause detects the ground crossing and
reinit reverses the velocity, scaled by e
to model energy loss at each bounce.
How it works
Between bounces the ball follows simple free-fall: der(v) = -g.
The when h < 0 clause fires each time the height crosses
zero from above. At that instant, reinit(v, -e * pre(v))
replaces the current velocity with a reversed, smaller value. Each bounce loses a fraction of the kinetic
energy, so the ball eventually comes to rest.
Why the ball falls through the floor
Run the sim long enough and the ball drifts through the floor. This isn't a Rumoca bug — it's Zeno behavior: with , the model demands infinitely many bounces in finite time, and no integrator can resolve them all.
The first fall takes , hitting the ground at speed . After bounce the upward speed is , giving an air time of . Summing the geometric series for all bounces:
For the defaults (, ), that's about 8.1 seconds. Near the end of that window, inter-bounce times shrink below the integrator's minimum step and floating-point precision — an event is missed, the ball is left with a small negative and downward velocity, and gravity carries it through. Tightening tolerances delays the failure but cannot eliminate it: the model itself has no finite-time answer.
Production simulators patch this with a Zeno escape: when bounces fire too close together, switch to a "resting" mode that pins algebraically. These are pragmatic fixes, not physics — the rigid-contact idealization just doesn't have a clean answer here.
Things to try
- Set
e = 1.0for a perfectly elastic bounce — no Zeno problem, the ball returns to its original height every time. - Lower
eto0.3— Zeno hits sooner because is shorter. - Extend
tEndwell past and watch the ball drift through the floor as event detection fails. - Try
g = 1.62for lunar gravity — the same Zeno pattern appears, just stretched in time.