Engee documentation
Notebook

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:

battery_cccv--1735019739092.png

Defining the function to load and run the model:

In [ ]:
function start_model_engee()
    try
        engee.close("battery_cccv", force=true) # closing the model
        catch err # if there is no model to close and engee.close() is not executed, it will be loaded after catch.
            m = engee.load("$(@__DIR__)/battery_cccv.engee") # loading the model
        end;

    try
        engee.run(m) # launching the model
        catch err # if the model is not loaded and engee.run() is not executed, the bottom two lines after catch will be executed.
            m = engee.load("$(@__DIR__)/battery_cccv.engee") # loading the model
            engee.run(m) # launching the model
        end
end
Out[0]:
start_model_engee (generic function with 1 method)

Running the simulation

In [ ]:
try
    start_model_engee() # running the simulation using the special function implemented above
    catch err
    end;

Output of a variable simout:

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

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

Visualization of simulation results

In [ ]:
using Plots
In [ ]:
plot(V[:,1], V[:,2], label="Voltage, V", linewidth=2, title="Battery voltage")
Out[0]:
In [ ]:
plot(I[:,1], I[:,2], label="Current, A", linewidth=2, title="Discharge/charge current")
Out[0]:
In [ ]:
plot(T[:,1], T[:,2], label="Battery temperature", linewidth=2, title="Battery temperature")
Out[0]: