Engee documentation
Notebook

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:

battery_cccv_1735019739092.png

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]:
start_model_engee (generic function with 1 method)

Running the simulation

In [ ]:
try
    start_model_engee() # запуск симуляции с помощью специальной функции, реализованной выше
    catch err
    end;

Output variable simout:

In [ ]:
simout
Out[0]:
SimulationResult(
    "battery_cccv/Напряжение" => WorkspaceArray("battery_cccv/Напряжение"),
    "battery_cccv/Ток" => WorkspaceArray("battery_cccv/Ток"),
    "battery_cccv/Температура" => WorkspaceArray("battery_cccv/Температура")
)

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]:
36001×2 DataFrame
35976 rows omitted
Rowtimevalue
Float64Float64
10.0298.15
21.0298.139
32.0298.128
43.0298.118
54.0298.107
65.0298.096
76.0298.086
87.0298.075
98.0298.065
109.0298.054
1110.0298.044
1211.0298.034
1312.0298.024
3599035989.0296.816
3599135990.0296.816
3599235991.0296.817
3599335992.0296.817
3599435993.0296.817
3599535994.0296.818
3599635995.0296.818
3599735996.0296.818
3599835997.0296.819
3599935998.0296.819
3600035999.0296.819
3600136000.0296.82

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]:

Blocks used in example