Battery discharge and charge cycle modelling
This example shows how to use the algorithm to charge and discharge a battery at constant current and constant voltage. The CC-CV unit charges and discharges the battery for 10 hours. The initial charge level is 0.3. During charging, the current remains constant until the battery voltage reaches the maximum value and the current decreases to 0. During discharging, constant current is used.
Schematic diagram of the model:

Define the function to load and run the model:
In [ ]:
function start_model_engee()
try
engee.close("battery_cccv", force=true) # закрытие модели
catch err # в случае, если нет модели, которую нужно закрыть и engee.close() не выполняется, то будет выполнена её загрузка после catch
m = engee.load("$(@__DIR__)/battery_cccv.engee") # загрузка модели
end;
try
engee.run(m) # запуск модели
catch err # в случае, если модель не загружена и engee.run() не выполняется, то будут выполнены две нижние строки после catch
m = engee.load("$(@__DIR__)/battery_cccv.engee") # загрузка модели
engee.run(m) # запуск модели
end
end
Out[0]:
Running the simulation
In [ ]:
try
start_model_engee() # запуск симуляции с помощью специальной функции, реализованной выше
catch err
end;
Output variable simout
:
In [ ]:
simout
Out[0]:
Writing from simout to variables of voltage, current and temperature signals:
In [ ]:
res = collect(simout)
V = collect(res[1])
I = collect(res[2])
T = collect(res[3])
Out[0]:
Visualising simulation results
In [ ]:
using Plots
In [ ]:
plot(V[:,1], V[:,2], label="Напряжение, В", linewidth=2, title="Напряжение батареи")
Out[0]:
In [ ]:
plot(I[:,1], I[:,2], label="Ток, А", linewidth=2, title="Ток разряда/заряда")
Out[0]:
In [ ]:
plot(T[:,1], T[:,2], label="Температура батареи", linewidth=2, title="Температура батареи")
Out[0]: