Simulation of the discharge and charge cycle of a battery
This example shows how to use the battery charge and discharge algorithm at constant current and constant voltage. The CC-CV unit charges and discharges the battery within 10 hours. The initial charge level is 0.3. During charging, the current remains constant until the battery voltage reaches its maximum value and the current decreases to 0. Direct current is used during discharge.
Model diagram:
Defining 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 of a variable simout:
In [ ]:
simout
Out[0]:
Recording voltage, current, and temperature signals from simout to variables:
In [ ]:
res = collect(simout)
V = collect(res[1])
I = collect(res[2])
T = collect(res[3])
Out[0]:
Visualization of 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]: