Charge and discharge of the supercapacitor
In this example, a supercapacitor is modeled, from which voltage readings are taken during its charging and subsequent discharge. To charge the supercapacitor for 100 seconds, a current of 100 mA is supplied to it from the mains. Then the supercapacitor is not used for one minute. During the next hour, a 50 mA load is connected for one second every 50 seconds to discharge the supercapacitor.
Model diagram:
Defining the function to load and run the model:
In [ ]:
function start_model_engee()
try
engee.close("supercapacitor_charging_and_discharging_behavior", 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__)/supercapacitor_charging_and_discharging_behavior.engee") # loading the model
end;
try
engee.run(m, verbose=true) # 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__)/supercapacitor_charging_and_discharging_behavior.engee") # loading the model
engee.run(m, verbose=true) # launching the model
end
end
Out[0]:
Running the simulation
In [ ]:
start_model_engee();
Writing 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]:
Data visualization
In [ ]:
using Plots
In [ ]:
p1 = plot(t, load_current, linewidth=2, label="Load, mA", ylabel="Current, mA", lc=2)
p2 = plot(t, supercapacitor_voltage, linewidth=2, label="Supercapacitor voltage", xlabel="Time, from", ylabel="For example, In")
plot(p1, p2, layout=(2,1))
Out[0]: