Bi-directional voltage source converter
A single-phase bi-directional voltage source converter is connected to an AC voltage source through an inductor $L = 10\,$mH as given below. All the switches are ideal and are operated using the sinusoidal pulse width modulation (SPWM) technique. The dc link voltage is $500\,$V. The AC source voltage is $230\,\angle{0}\,$V. The PWM carrier signal is a triangle wave between $-1$ and $1$ with a frequency of $10\,$kHz, and the modulating signal is $v_{ref}(t) = M\,\sin\,(\omega \,t + \phi)$. The inverter injects 5 kW of power at unity power factor to the AC source. Determine $M$ and $\phi$ (in degrees). Draw the phasor diagram showing the relationship between inverter voltage, grid voltage, and the voltage across the inductor. (Follow the convention that $\sin\,\omega\,t$ corresponds to the phasor $1\angle{0}$.)In [1]:
from IPython.display import Image
Image(filename =r'VSC_bi_5_fig_1.png', width=300)
Out[1]:
In [2]:
# run this cell to view the circuit file.
%pycat VSC_bi_5_orig.in
We now replace the strings such as \$Vdc, \$L, with the values of our choice by running the python script given below. It takes an existing circuit file VSC_bi_5_orig.in and produces a new circuit file VSC_bi_5.in, after replacing \$Vdc, \$L, etc. with values of our choice.
In [3]:
import gseim_calc as calc
import numpy as np
s_Vdc = "500"
s_L = "10e-3"
s_f_carrier = "10e3"
s_M = "0.6" # to be changed by user
s_phi = "14" # to be changed by user
s_dt_min = "0.01e-6"
s_dt_nrml = "1e-6"
A_sin = 230.0*np.sqrt(2.0)
s_A_sin = ("%11.4E"%A_sin).strip()
s_f_sin = "50"
f_sin = float(s_f_sin)
T = 1/f_sin
s_2T = ("%11.4E"%(2.0*T)).strip()
s_3T = ("%11.4E"%(3.0*T)).strip()
s_5T = ("%11.4E"%(5.0*T)).strip()
l = [
('$Vdc', s_Vdc),
('$L', s_L),
('$f_carrier', s_f_carrier),
('$f_sin', s_f_sin),
('$A_sin', s_A_sin),
('$2T', s_2T),
('$3T', s_3T),
('$5T', s_5T),
('$M', s_M),
('$phi', s_phi),
('$dt_min', s_dt_min),
('$dt_nrml', s_dt_nrml)
]
calc.replace_strings_1("VSC_bi_5_orig.in", "VSC_bi_5.in", l)
print('VSC_bi_5.in is ready for execution')
VSC_bi_5.in is ready for execution
Execute the following cell to run GSEIM on VSC_bi_5.in.
In [4]:
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("VSC_bi_5.in")
os.system('run_gseim VSC_bi_5.in')
Circuit: filename = VSC_bi_5.in main: calling solve_trns Transient simulation starts... i=0 i=50000 i=100000 GSEIM: Program completed.
Out[4]:
0
The circuit file (VSC_bi_5.in) is created in the same directory as that used for launching Jupyter notebook. The last step (i.e., running GSEIM on VSC_bi_5.in) creates a data file called VSC_bi_5.datin the same directory. We can now use the python code below to compute/plot the various quantities of interest.
In [5]:
import gseim_calc as calc
n_plots = 4
l_n_curves = [2, 1, 1, 1]
plot_multi = calc.gseim_plot_multi(n_plots, l_n_curves)
for i in range(4):
for j in range(l_n_curves[i]):
plot_multi.plot_all[i].l_plots[j].i_slv = 0
plot_multi.plot_all[i].l_plots[j].i_out = 0
plot_multi.plot_all[i].l_plots[j].plot_type = "X-time"
plot_multi.plot_all[0].l_plots[0].var_name = "t"
plot_multi.plot_all[0].l_plots[0].label = "t"
plot_multi.plot_all[0].l_plots[0].color = "powderblue"
plot_multi.plot_all[0].l_plots[1].var_name = "s"
plot_multi.plot_all[0].l_plots[1].label = "s"
plot_multi.plot_all[0].l_plots[1].color = "blue"
plot_multi.plot_all[1].l_plots[0].var_name = "v_ac"
plot_multi.plot_all[1].l_plots[0].color = "green"
plot_multi.plot_all[2].l_plots[0].var_name = "IL"
plot_multi.plot_all[2].l_plots[0].color = "goldenrod"
plot_multi.plot_all[3].l_plots[0].var_name = "Idc"
plot_multi.plot_all[3].l_plots[0].color = "powderblue"
plot_multi.plot_all[0].y_label = ""
plot_multi.plot_all[0].legend_flag = True
plot_multi.plot_all[1].y_label = "$V_{ac}$"
plot_multi.plot_all[1].legend_flag = False
plot_multi.plot_all[2].y_label = "$i_L$"
plot_multi.plot_all[2].legend_flag = False
plot_multi.plot_all[3].y_label = "$-i_{dc}$"
plot_multi.plot_all[3].legend_flag = False
plot_multi.plot_all[3].y_lmt = -1.0
calc.plot_multi_time(
infile='VSC_bi_5.in',
t_mult=1e3,
x_size=7.0,
y_size=7.0,
x_label='time (msec)',
label_font_size=14,
legend_fontsize=10,
t_start=60e-3,
t_end=100e-3,
t_offset=-60e-3,
plot_multi=plot_multi)
filename: VSI_bi_5.dat
In [6]:
coeff_Idc, thd_Idc = calc.get_fourier_coeff(infile='VSC_bi_5.in', i_slv=0, i_out=0,
var_name='Idc', n_fourier=250, t_start=60e-3, t_end=80e-3)
print("i_dc 100-Hz component: amplitude:", "%11.4E"%(coeff_Idc[2]))
calc.plot_single_fourier(infile='VSC_bi_5.in',
i_slv=0, i_out=0, var_name='Idc', color='red', bar_width=0.7,
n_fourier=250, compute_thd=False, x_size=5.5, y_size=2.5,
x_div_minor=10,x_div_major=50,
y_label=r'$I_{dc}$',label_font_size=12,
t_start=60e-3, t_end=80e-3)
filename: VSI_bi_5.dat i_dc 100-Hz component: amplitude: 7.6563E+00 filename: VSI_bi_5.dat Idc fundamental (RMS value): 9.9623E-03
In [7]:
import numpy as np
import gseim_calc as calc
import os
import dos_unix
import cmath
import matplotlib.pyplot as plt
from matplotlib.ticker import (MultipleLocator, AutoMinorLocator)
from setsize import set_size
slv = calc.slv("VSC_bi_5.in")
i_slv = 0
i_out = 0
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)
t = u[:, 0]
t0 = t[0]
t = t - t0
v_ac = slv.get_array_double(i_slv,i_out,"v_ac",u)
v_BD = slv.get_array_double(i_slv,i_out,"v_BD",u)
VL = slv.get_array_double(i_slv,i_out,"VL", u)
T = t[-1]/2
coeff_v_ac, thd_v_ac, coeff_a_v_ac, coeff_b_v_ac = calc.fourier_coeff_2A(t, v_ac, 0.0, T, 1.0e-8*T, 1)
coeff_v_BD, thd_v_BD, coeff_a_v_BD, coeff_b_v_BD = calc.fourier_coeff_2A(t, v_BD, 0.0, T, 1.0e-8*T, 1)
coeff_VL , thd_VL , coeff_a_VL , coeff_b_VL = calc.fourier_coeff_2A(t, VL , 0.0, T, 1.0e-8*T, 1)
k_fourier = 1
A_v_ac, theta_rad_v_ac, theta_deg_v_ac = calc.get_mag_angle_1(k_fourier, coeff_a_v_ac, coeff_b_v_ac)
A_v_BD, theta_rad_v_BD, theta_deg_v_BD = calc.get_mag_angle_1(k_fourier, coeff_a_v_BD, coeff_b_v_BD)
A_VL , theta_rad_VL , theta_deg_VL = calc.get_mag_angle_1(k_fourier, coeff_a_VL , coeff_b_VL )
z_v_ac = cmath.rect(A_v_ac, (theta_rad_v_ac + np.pi/2))
z_v_BD = cmath.rect(A_v_BD, (theta_rad_v_BD + np.pi/2))
z_VL = cmath.rect(A_VL , (theta_rad_VL + np.pi/2))
print('phasors in polar form:')
s_format = "%7.2f"
calc.print_complex_polar('v_ac', z_v_ac, s_format)
calc.print_complex_polar('v_BD', z_v_BD, s_format)
calc.print_complex_polar('VL ', z_VL , s_format)
l_colors = ["blue", "red", "green", "grey", "dodgerblue", "tomato"]
l1 = []
l1_labels = []
color_v_ac = calc.phasor_append_1a(l1, l1_labels, z_v_ac, "$V_{ac}$", l_colors)
color_v_BD = calc.phasor_append_1a(l1, l1_labels, z_v_BD, "$V_{BD}$", l_colors)
color_VL = calc.phasor_append_1a(l1, l1_labels, z_VL , "$V_L$" , l_colors)
theta_deg = 20.0
length_arrow = calc.phasor_3(l1, 0.02)
l1_arrow = calc.phasor_2(l1, theta_deg, length_arrow, 0.2)
l2 = []
l2_colors = []
calc.phasor_append_2(l2, l2_colors, z_VL, (z_VL + z_v_ac), color_v_ac)
l2_arrow = calc.phasor_2(l2, theta_deg, length_arrow, 0.2)
fig, ax = plt.subplots()
ax.set_aspect('equal', adjustable='box')
ax.grid()
for i, l_dummy in enumerate(l1_arrow):
for k, t in enumerate(l_dummy):
if (k == 0):
ax.plot(t[0],t[1], color=l_colors[i], label=l1_labels[i])
else:
ax.plot(t[0],t[1], color=l_colors[i])
for i, l_dummy in enumerate(l2_arrow):
for k, t in enumerate(l_dummy):
ax.plot(t[0],t[1], color=l2_colors[i], linestyle='--', dashes=(4, 2))
calc.revise_axis_limits_1(ax, 3.0)
ax.legend(loc='center left', fontsize=11, bbox_to_anchor=(1.05, 0.5))
plt.xlabel('Re (V)', fontsize=11)
plt.ylabel('Im (V)', fontsize=11)
plt.show()
filename: VSI_bi_5.dat phasors in polar form: v_ac: magnitude: 325.27, angle: -0.00 deg v_BD: magnitude: 299.95, angle: 14.00 deg VL : magnitude: 80.22, angle: 115.27 deg
This notebook was contributed by Prof. Nakul Narayanan K, Govt. Engineering College, Thrissur. He may be contacted at nakul@gectcr.ac.in.
In [ ]: