Engee documentation
Notebook

Charge and discharge of a supercapacitor

In this example, a supercapacitor is modelled to take voltage readings when it is charged and then discharged. A current of 100 mA is applied from the mains to charge the supercapacitor for 100 seconds. The supercapacitor is then not used for one minute. For the next hour, a 50 mA load is applied every 50 seconds for one second to discharge the supercapacitor.

Schematic diagram of the model:

supercapacitor_charging_and_discharging_behavior_1743426433042.png

Define the function to load and run the model:

In [ ]:
function start_model_engee()
    try
        engee.close("supercapacitor_charging_and_discharging_behavior", force=true) # закрытие модели 
        catch err # в случае, если нет модели, которую нужно закрыть и engee.close() не выполняется, то будет выполнена её загрузка после catch
            m = engee.load("$(@__DIR__)/supercapacitor_charging_and_discharging_behavior.engee") # загрузка модели
        end;

    try
        engee.run(m, verbose=true) # запуск модели
        catch err # в случае, если модель не загружена и engee.run() не выполняется, то будут выполнены две нижние строки после catch
            m = engee.load("$(@__DIR__)/supercapacitor_charging_and_discharging_behavior.engee") # загрузка модели
            engee.run(m, verbose=true) # запуск модели
        end
end
Out[0]:
start_model_engee (generic function with 1 method)

Running the simulation

In [ ]:
start_model_engee();
Building...
Progress 0%
Progress 5%
Progress 10%
Progress 15%
Progress 21%
Progress 26%
Progress 31%
Progress 36%
Progress 41%
Progress 47%
Progress 52%
Progress 57%
Progress 62%
Progress 68%
Progress 73%
Progress 78%
Progress 83%
Progress 88%
Progress 93%
Progress 98%
Progress 100%

Write simulation data to variables:

In [ ]:
t = simout["supercapacitor_charging_and_discharging_behavior/SysOutput_1"].time[:]
load_current = simout["supercapacitor_charging_and_discharging_behavior/SysOutput_1"].value[:]
supercapacitor_voltage = simout["supercapacitor_charging_and_discharging_behavior/SysOutput_2"].value[:]
Out[0]:
WorkspaceArray{Float64}("supercapacitor_charging_and_discharging_behavior/SysOutput_2").value

Data visualisation

In [ ]:
using Plots
In [ ]:
p1 = plot(t, load_current, linewidth=2, label="Нагрузка, мА", ylabel="Ток, мА", lc=2)
p2 = plot(t, supercapacitor_voltage, linewidth=2, label="Напряжение суперконденсатора", xlabel="Время, с", ylabel="Напражение, В")
plot(p1, p2, layout=(2,1))
Out[0]: