Engee documentation
Notebook

Bouncing ball simulation

This example shows how to simulate a bouncing ball in Engee.

First, let's declare a function to run the model and the libraries we will need when working with data from the model.

In [ ]:
 using Plots

 function run_model(name_model)
    Path = (@__DIR__) * "/" * name_model * ".engee"

    if name_model in [m.name for m in engee.get_all_models()] # Проверка условия загрузки модели в ядро
        model = engee.open( name_model ) # Открыть модель
        model_output = engee.run( model, verbose=true ); # Запустить модель
    else
        model = engee.load( Path, force=true ) # Загрузить модель
        model_output = engee.run( model, verbose=true ); # Запустить модель
        engee.close( name_model, force=true ); # Закрыть модель
    end

    return model_output
end
Out[0]:
run_model (generic function with 2 methods)

Let's move on to the theoretical component of this demonstration. The figure below shows the basic principle behind the demonstration. Conditions: a ball is thrown with a velocity of 15 m/s from a height of 10 m.

image.png

The bouncing ball model is a classic example of a hybrid dynamical system. A hybrid dynamical system is a system that includes continuous dynamics as well as discrete transitions where system dynamics can change and state values can transition.

The continuous dynamics of a bouncing ball is described in simple terms as follows:

image.png

image_2.png

where: $g$ acceleration is due to gravity, $x(t)$ is the position of the ball and $v(t)$ is the velocity. Therefore, the system has two continuous states: position $x$ and velocity $v$.

The hybrid system aspect of the model comes from modelling the collision of the ball with the ground. If you assume a partially elastic collision with the ground, the velocity before the collision $v^-$ and the velocity after the collision $v^+$ can be related to the ball recovery factor $\kappa$ as follows:

image_3.png

The bouncing ball therefore displays a jump in the continuous state (velocity) given the transition $x=0$.

Let's move on to running the model and analysing the data. The model itself is shown in the figure below.

image.png

In [ ]:
h_start = 10; # Высота
v_start = 15; # Скорость
run_model("bouncing_ball")
sleep(5)
collect(simout)
Building...
Progress 100%
Out[0]:
2-element Vector{WorkspaceArray}:
 WorkspaceArray("bouncing_ball/P")
 WorkspaceArray("bouncing_ball/V")
In [ ]:
h_start = 10; # Высота
v_start = 15; # Скорость
run_model("bouncing_ball")
sleep(5)
collect(simout)

We plot the graphs based on the logged data, and for visual convenience, we plot the graph with a zero Y-axis.

In [ ]:
# Скорость
v = simout["bouncing_ball/V"];
v = collect(v);
plot(v.time, v.value)

# Положение
p = simout["bouncing_ball/P"];
p = collect(p);
plot!(p.time, p.value) 

plot!(p.time, zeros(size(p.time)))
Out[0]:

Conclusion

In this example we have built a simulation of a bouncing ball and also looked at the possibilities of interacting with the modelling environment from Engee scripts. The bouncing ball is one of the simplest models that shows the Zeno phenomenon. Zeno behaviour is informally characterised by an infinite number of events occurring within a finite time interval for certain hybrid systems. When the ball loses energy in the bouncing ball model, a large number of collisions with the ground begin to occur in successively smaller time intervals. Consequently, the model experiences Zeno behaviour. Models with Zeno behaviour are not easy to simulate on a computer, but it is necessary to do so because they are found in many common and important engineering applications.