Engee documentation
Notebook

Analysis of transients in linear electric circuits

** Objective:** To investigate a linear circuit containing several electrical energy storage devices in the Engee programme.

Content of work:

  • compose a system of equations for a given electric circuit;
  • develop a programme to calculate currents in the circuit branches and voltage drops on capacitive elements;
  • present the results of the programme calculation in the form of graphical dependencies;
  • create a model of an electric circuit in Engee;
  • compare the results of modelling with the results of calculation of the developed program.

Engee and DifferntialEquations.jl package are used as the software used to solve the system of equations, the calculation is performed using the ode45 method - one-step explicit Runge-Kutta method of the 4th (5th) order. Here is an example of calculation of a linear electrical circuit:

scheme_1.png

1. Application of the DifferentialEquations.jl package

The DifferentialEquations.jl package provides a large number of well-optimised differential equation solvers of various types:

  • ordinary differential equations
  • differential algebraic equations
  • stochastic differential equations
  • differential equations with a delayed argument
  • stochastic differential equations with delayed argument
  • differential equations with parametric uncertainty
  • etc.
In [ ]:
using .DifferentialEquations, .Plots

2. Solution of the differential equation

The general order of operations is as follows:

1. Define the function

f(u, p, t) 
f(du, u, p, t)

where u are the variables, p are the parameters of the equation, du are the derivatives $dy/dt$.

2. Define the problem

prob = ODEProblem(f, u0, tspan)
prob = ODEProblem(f, u0, tspan, p)

where u0 is the initial conditions, tspan is the estimated time interval ($t_0, T$)

3. Numerical solution

sol = solve(prob, alg; kwargs)

where alg is the numerical algorithm, kwargs is the additional arguments.

For example, for users familiar with MATLAB/Python/R, there are translations of standard library methods:

  • ode23 → BS3()
  • ode45/dopri5 → DP5(), although Tsit5() is more efficient in most cases
  • ode23s → Rosenbrock23(), although in most cases Rodas4() is more efficient

You can read more about solvers in documentation.

4. Analyse results

sol(t)
plot(sol)

where the function plot of the Plots.jl package is used. When using other graphical packages

plot(sol.t, sol')

3. Programme for calculating an electric circuit

System of differential equations describing an electric circuit:

system_3.png where Uc1, Uc2 - voltages on capacitances, which can be found from the solution of equations

equatio.png

In order for the system of equations to be solvable with respect to the unknown quantities under the sign of the differential, it is necessary to express the currents of the branches not containing inductance through the required parameters. For this purpose, using Kirchhoff's laws, let us make the coupling equations (1.2) and supplement (1.1):

system_2.png

In [ ]:
# Ввод параметров электрической цепи
R1 = 10.0
R2 = 15.0
R3 = 20.0
R4 = 10.0
f  = 50.0
C1 = 10e-6
C2 = 30e-6
L1 = 15e-3
L2 = 20e-3

# Определение дифференциальной системы
function circuit!(du, u, p, t)
    U, R1, R2, R3, R4, C1, C2, L1, L2 = p
    Uc1, Uc2, i1, i4 = u
    
    # Алгебраические уравнения связи
    i2 = (u[1] + u[2] + (u[3] - u[4]) * R4) / (R2 + R4)
    i3 = u[3] - i2
    i5 = i3 - u[4]
    
    # Дифференциальные уравнения
    du[1] = i3 / C1
    du[2] = i5 / C2
    du[3] = 1 / L1 * (U(t) - i2 * R2 - u[3] * R1)
    du[4] = 1 / L2 * (u[2] + i5 * R4 - u[4] * R3)

end

# Начальные условия для u
u0 = [0.0, 0.0 , 0.0, 0.0]  

# Диапазон времени для расчета, пусть будет два периода промышленной частоты 50 Гц
tspan = (0.0, 0.04) 

# Задание параметров
U(t) = 100 * sin(2 * π * f * t)
params = (U, R1, R2, R3, R4, C1, C2, L1, L2)

# Создание объекта ODEProblem с передачей параметров
prob = ODEProblem(circuit!, u0, tspan, params)

# Решение дифференциальных уравнений
sol = solve(prob, Tsit5());

# Построение графиков
plot(sol, label = ["Uc1(t)" "Uc2(t)" "i1(t)" "i4(t)"], layout = 4)
Out[0]:

4. Comparison of calculation results with modelling results

Let's load the model located in /user/start/examples/power_systems/lab_work/lab_work.engee.

image.png

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

Let's run a simulation:

In [ ]:
results = engee.run( modelName );

Give convenient names to the output variables of our model (those marked as logged signals):

In [ ]:
t = results["i1"].time;
i1 = results["i1"].value;
i4 = results["i4"].value;
Uc1 = results["Uc1"].value;
Uc2 = results["Uc2"].value;

Draw graphs based on the results of the modelling:

In [ ]:
plot(t, [Uc1 Uc2 i1 i4], label = ["Uc1_sim" "Uc2_sim" "i1_sim" "i4_sim"], layout = 4)
Out[0]:

Let's plot the simulation results and the calculation results on one graph:

In [ ]:
plot(t, [Uc1 Uc2 i1 i4], label = ["Uc1_sim" "Uc2_sim" "i1_sim" "i4_sim"], layout = 4)
plot!(sol, label = ["Uc1" "Uc2" "i1" "i4"], layout = 4)
Out[0]:

Work conclusions: in the course of work performance the system of algebraic-differential equations was compiled, the programme of calculation of currents in branches and voltage drops on capacitive elements of the circuit was developed, graphical dependences of laws of change of currents and voltages on time are given. The results of Engee modelling are compared with the results of the developed calculation program. In general, the laboratory work presents the analysis of an electric circuit containing several electric energy storage devices.