Engee documentation
Notebook

Mathematical models of bodies

In this example we will consider two models of bodies. In the first case it will be a pendulum and in the second case it will be a body on a spring. We will analyse the behaviour of these bodies.

Mathematical pendulum

Let's analyse the process of describing oscillating systems using integral calculations in the Engee development environment. The figure shows a model of an oscillating system:

engee_maiatnik_4.png

The model includes several basic concepts:

  1. A material point of mass m.
  2. A weightless inextensible thread of length l.
  3. A homogeneous field of gravitational forces g.

In this case, the formula for calculating the momentum of gravity $M$ is equal to the negative of the mass $m$, multiplied by $g$ and $l$ and by the sine of the angle of deflection of the pendulum.

$$M = - mg l sin \theta$$

Let's move on to implementation. The first step is to declare the system parameters.

In [ ]:
Pkg.add(["CSV"])
In [ ]:
m = 1;
g = 9.8;
l = 1;

theta_init = 40*(pi/180); # перевод начального значения градуса отклонения в радианы

mgl=(-m*g*l);
invI = 1/(m * l^2);

Now let us run the system of integral equations constructed in Engee models. The figure below shows this model:

image.png

Note: the AB3 solver was used in the modelling.

AB3 is a three-step method of the third order, initialisation of Ralston methods of the second order.

In [ ]:
# Запуск модели
model = engee.load("/user/start/examples/base_simulation/mathematical_models_of_bodies/Math_pendulum.engee"; force = true);
engee.run(model, verbose=true);
engee.close(model, force=true);
Building...
Progress 0%
Progress 0%
Progress 5%
Progress 10%
Progress 15%
Progress 20%
Progress 25%
Progress 30%
Progress 35%
Progress 40%
Progress 45%
Progress 50%
Progress 55%
Progress 60%
Progress 65%
Progress 70%
Progress 75%
Progress 80%
Progress 85%
Progress 90%
Progress 95%
Progress 100%

For processing and visualisation of simulation results we need to connect several libraries.

In [ ]:
using CSV
using DataFrames
using Plots
plotlyjs()
Out[0]:
Plots.PlotlyJSBackend()

Now we can read the data recorded during the modelling process. The data in the CSV file contains two columns:

  1. the timestamps of the simulation;
  2. output data, in this case the values of the degree of pendulum deflection.
In [ ]:
# Чтение CSV
Data = Matrix(CSV.read("/user/start/examples/base_simulation/mathematical_models_of_bodies/out.csv",DataFrame));
Data_time = Data[:,1];
Data = Data[:,2];

Now let us analyse the results of the oscillation, presenting them graphically.

In [ ]:
# Построение графиков
plot(Data_time , Data, legend = false)
plot!(title = "Результаты моделирования в Engee", ylabel = "Данные", xlabel="Время, c")
Out[0]:

As we can see, the model displays non-damped oscillations of the mathematical pendulum with constancy of the oscillation process.

Mathematical model of mass-spring-damper model

In this example we will demonstrate the possibilities of calculating the behaviour of a body on a spring in order to demonstrate the capabilities of Engee in solving integral equations. The figure below shows a general view of the body for which the calculations will be performed.

xxmass_spring_damper.png

The mass-spring damper shown in the figure is modelled by a second order differential equation.

$$m \ddot x + c \dot x + kx = F$$

where $F$ is the force applied to the mass and $х$ is the horizontal position of the mass.

Let's move on to implementation. First, let's declare the system parameters.

In [ ]:
m = 2;
c = 50;
k = 0.2;

invM = 1/m;

Now let's run the system of integral equations constructed in Engee models. The figure below shows this model:

image_2.png

Note: the AB3 solver was used in the modelling.

AB3 is a three-step method of the third order, initialisation of Ralston methods of the second order.

In [ ]:
# Запуск модели
model = engee.load("/user/start/examples/base_simulation/mathematical_models_of_bodies/Body_on_spring.engee", force=true);
engee.run(model, verbose=true);
engee.close(model, force=true);
Building...
Progress 0%
Progress 0%
Progress 5%
Progress 10%
Progress 15%
Progress 20%
Progress 25%
Progress 30%
Progress 35%
Progress 40%
Progress 45%
Progress 50%
Progress 55%
Progress 60%
Progress 65%
Progress 70%
Progress 75%
Progress 80%
Progress 85%
Progress 90%
Progress 95%
Progress 100%

For processing and visualisation of simulation results we need to connect several libraries.

In [ ]:
using CSV
using DataFrames
using Plots
plotlyjs()
Out[0]:
Plots.PlotlyJSBackend()

Now we can read the data recorded during the modelling process. The data in the CSV file contains two columns:

  1. modelling timestamps;
  2. output data.
In [ ]:
# Чтение CSV
Data1 = Matrix(CSV.read("/user/start/examples/base_simulation/mathematical_models_of_bodies/out1.csv",DataFrame));
Data2 = Matrix(CSV.read("/user/start/examples/base_simulation/mathematical_models_of_bodies/out2.csv",DataFrame));

Data_time = Data1[:,1];
Data1 = Data1[:,2];
Data2 = Data2[:,2];

Now let us analyse the results of the oscillation and present them graphically.

In [ ]:
# Построение графиков
plot(Data_time , Data1, legend = false)
plot!(Data_time , Data2, legend = false)
plot!(title = "Результаты моделирования в Engee", ylabel = "Данные", xlabel="Время, c")
Out[0]:

As we can see, the model displays oscillations with gradual damping of the oscillation process, which is identical to the behaviour of a physical body on a spring.

Conclusion

As a result of this example we have shown you the capabilities of Engee in modelling the behaviour of physical objects by building a mathematical model of the object. This example allows you to demonstrate the behaviour of an object based on its parameters, which can be applied to more complex algorithms and systems.