Engee documentation
Notebook

Discharge-charging the battery

This example demonstrates the simulation of a battery model with a nominal voltage of 300 V and a capacity of 100 A∙h. This demo example serves as a starting point if you want to simulate:

  • an LESS storage subsystem
  • a battery cell charge management system (BMS)
  • the traction lithium-ion battery of an electric vehicle

The model uses a realistic DC link load profile, which is determined by the dynamic driving cycle of the electric vehicle. The total simulation time is 3600 seconds.

General view of the model

The model is based on the Battery library block (https://engee.com/helpcenter/stable/fmod-electricity-sources/battery.html). In addition to electrical ports, the Battery block has a thermal port for modelling thermal effects. These are important to consider when designing control systems, because a critical temperature increase can cause thermal runaway, spontaneous combustion or explosion. As you can see, the model consists of several networks in different physical domains - thermal and electrical.

hv_battery.png

The battery is connected to a realistic DC link load profile, which is simulated using the From Workspace block (https://engee.com/helpcenter/stable/base-lib-sources/from-workspace.html). This block transfers the load graph to the model as a signal i = f(t) to the controlled current source.

Realisation of the model run using software control:

Loading the required libraries for importing the time dependence of the current:

In [ ]:
Pkg.add(["MAT"])
In [ ]:
using DataFrames
using MAT
gr()
Out[0]:
Plots.GRBackend()

Reading the mat file and converting it to a WorkspaceArray for use in the From Workspace block:

In [ ]:
vars = matread("I_dc_discharge.mat");
data = vars["array"];
t = data[:,1];
current = data[:,2];
df = DataFrame(time=t, value=current);
I_dc = WorkspaceArray(string(rand()), df);
In [ ]:
vars = matread("I_dc_discharge.mat");
data = vars["array"];
t = data[:,1];
current = data[:,2];
df = DataFrame(time=t, value=current);
I_dc = WorkspaceArray(string(rand()), df);

Loading a model:

In [ ]:
model_name = "HV_battery"
model_name in [m.name for m in engee.get_all_models()] ? engee.open(model_name) : engee.load( "$(@__DIR__)/$(model_name).engee");

Running a loaded model:

In [ ]:
results = engee.run(model_name)
Out[0]:
Dict{String, DataFrame} with 4 entries:
  "Напряжение, В"          => 360001×2 DataFrame…
  "Температура батареи,°C" => 360001×2 DataFrame…
  "Ток, А"                 => 360001×2 DataFrame…
  "Заряд батареи, %"       => 360001×2 DataFrame

Modelling results

Import the results of the simulation:

In [ ]:
simulation_time = results["Напряжение, В"].time;
i = results["Ток, А"].value;
v = results["Напряжение, В"].value;
temperature = results["Температура батареи,°C"].value;
charge = results["Заряд батареи, %"].value;

Battery charge on time interval from 0 to 500 seconds:

In [ ]:
plot(simulation_time[1:50000], charge[1:50000])
plot!(title = "Заряд батареи, %", ylabel = "Заряд батареи, %", xlabel="Время, c")
Out[0]:

Load current on time interval 0 to 500 seconds:

In [ ]:
plot(simulation_time[1:50000], i[1:50000])
plot!(title = "Ток, А", ylabel = "Ток, А", xlabel="Время, c")
Out[0]:

During the simulation, the battery is not only discharged but also charged if the load current is reversed. This behaviour is encountered when the LESS is functioning to smooth out load fluctuations or when the electric vehicle is accelerating and decelerating.

Battery voltage at time intervals from 0 to 500 seconds:

In [ ]:
plot(simulation_time[1:50000], v[1:50000])
plot!(title = "Напряжение, В", ylabel = "Напряжение, В", xlabel="Время, c")
Out[0]:

Battery temperature at time interval 0 to 500 seconds:

In [ ]:
plot(simulation_time[1:50000], temperature[1:50000])
plot!(title = "Tемпература,°C", ylabel = "Tемпература,°C", xlabel="Время, c")
Out[0]:

Conclusions:

In this example, tools were used to command a battery model with a simulation duration of 1 hour. The battery load profile was imported into the Workspace from the mat file. The simulation results were imported into the script and visualised for a given time interval using interactive Plots library graphs.