from IPython.display import Image
Image(filename =r'VSC_bi_9_fig_1.png', width=500)
# run this cell to view the circuit file.
%pycat VSC_bi_9_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_9_orig.in and produces a new circuit file VSC_bi_9.in, after replacing \$Vdc, \\$L, etc. with values of our choice.
import gseim_calc as calc
s_Vdc = "400"
s_L = "10e-3"
s_f_carrier = "10e3"
s_M = "0.75"
s_phi = "0.0"
s_dt_min = "0.01e-6"
s_dt_nrml = "1e-6"
l = [
('$Vdc', s_Vdc),
('$L', s_L),
('$f_carrier', s_f_carrier),
('$M', s_M),
('$phi', s_phi),
('$dt_min', s_dt_min),
('$dt_nrml', s_dt_nrml)
]
calc.replace_strings_1("VSC_bi_9_orig.in", "VSC_bi_9.in", l)
print('VSC_bi_9.in is ready for execution')
VSC_bi_9.in is ready for execution
Execute the following cell to run GSEIM on VSC_bi_9.in.
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("VSC_bi_9.in")
os.system('run_gseim VSC_bi_9.in')
Circuit: filename = VSC_bi_9.in main: i_solve = 0 SolveBlocks:assign_parm: delt_0: 1e-06 SolveBlocks:assign_parm: delt_0_min: 1e-08 main: calling solve_ssw mat_ssw_1_ex: n_statevar: 1 Transient simulation starts... i=0 i=10000 i=20000 i=30000 i=40000 solve_ssw_ex: ssw_iter_newton=0, ssw_period_1_compute=4.0000e-02, rhs_ssw_norm=3.2238e-03 Transient simulation starts... i=0 i=10000 i=20000 i=30000 i=40000 solve_ssw_ex: ssw_iter_newton=1, ssw_period_1_compute=4.0000e-02, rhs_ssw_norm=1.2434e-14 solve_ssw_ex: calling solve_ssw_1_ex for one more trns step Transient simulation starts... i=0 i=10000 i=20000 i=30000 i=40000 solve_ssw_ex over (after trns step for output) solve_ssw_ex ends, slv.ssw_iter_newton=1 GSEIM: Program completed.
0
The circuit file (VSC_bi_9.in) is created in the same directory as that used for launching Jupyter notebook. The last step (i.e., running GSEIM on VSC_bi_9.in) creates a data file called VSC_bi_9.datin the same directory. We can now use the python code below to compute/plot the various quantities of interest.
import numpy as np
import matplotlib.pyplot as plt
import gseim_calc as calc
from setsize import set_size
f_hz = 50.0
T = 1.0/f_hz
slv = calc.slv("VSC_bi_9.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]
v_VS3 = slv.get_array_double(i_slv,i_out,"v_VS3",u)
i_VS3 = slv.get_array_double(i_slv,i_out,"i_VS3",u)
i_VS1 = slv.get_array_double(i_slv,i_out,"i_VS1",u)
# 0.1e-3 is the clock period:
l1 = calc.avg_rms_1(t, i_VS3, 0.1e-3)
fig, ax = plt.subplots(3, sharex=False, gridspec_kw={'height_ratios': [1, 1, 1]})
plt.subplots_adjust(wspace=0, hspace=0.0)
set_size(6.5, 4.5, ax[0])
for i in range(3):
ax[i].set_xlim(left=0.0, right=2.0*T*1e3)
ax[i].grid(color='#CCCCCC', linestyle='solid', linewidth=0.5)
ax[0].set_ylabel(r'$v_{ac}$', fontsize=12)
ax[1].set_ylabel(r'$i_{ac}$', fontsize=12)
ax[2].set_ylabel(r'$i_{dc}$', fontsize=12)
ax[0].tick_params(labelbottom=False)
ax[1].tick_params(labelbottom=False)
color1 = "blue"
color2 = "green"
color3 = "crimson"
color4 = "red"
color5 = "palegreen"
color4 = "crimson"
ax[0].plot(t*1e3, v_VS3, color=color1, linewidth=1.0, label="$v_{ac}$")
ax[1].plot(t*1e3, i_VS3, color=color5, linewidth=1.0, label="$i_{ac}$")
ax[2].plot(t*1e3, i_VS1, color=color3, linewidth=1.0, label="$i_{dc}$")
ax[1].plot(np.array(l1[0])*1e3, l1[1], color=color2, linewidth=1.0, label="$i_{ac}^{avg}$")
ax[2].set_xlabel('time (msec)', fontsize=12)
ax[1].legend(loc = 'lower right',frameon = True, fontsize = 10, title = None,
markerfirst = True, markerscale = 1.0, labelspacing = 0.5, columnspacing = 2.0,
prop = {'size' : 12},)
#plt.tight_layout()
plt.show()
filename: VSC_bi_9.dat
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import (MultipleLocator, AutoMinorLocator)
import gseim_calc as calc
from setsize import set_size
f_hz = 50.0
T = 1.0/f_hz
slv = calc.slv("VSC_bi_9.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]
i_VS1 = slv.get_array_double(i_slv,i_out,"i_VS1",u)
# compute Fourier coeffs:
t_start = T
t_end = 2.0*T
n_fourier = 250
coeff_i_VS1, thd_i_VS1 = calc.fourier_coeff_1C(t, i_VS1,
t_start, t_end, 1.0e-8, n_fourier)
x = np.linspace(0, n_fourier, n_fourier+1)
y_i_VS1 = np.array(coeff_i_VS1)
fig, ax = plt.subplots()
plt.subplots_adjust(wspace=0, hspace=0.0)
set_size(5.5, 2.5, ax)
plt.grid(color='#CCCCCC', linestyle='solid', linewidth=0.5)
delta = 50.0
x_major_ticks = np.arange(0.0, (float(n_fourier+1)), delta)
x_minor_ticks = np.arange(0.0, (float(n_fourier+1)), delta/5)
ax.set_xlim(left=-10.0, right=float(n_fourier))
ax.set_xticks(x_major_ticks)
ax.set_xticks(x_minor_ticks, minor=True)
ax.grid(visible=True, which='major', axis='x', color='#CCCCCC', linestyle='-', zorder=0)
ax.set_ylabel('$i_{dc}$',fontsize=14)
ax.set_xlabel('N', fontsize=14)
bars1 = ax.bar(x, y_i_VS1, width=0.7, color='red', label="$i_{dc}$", zorder=3)
plt.tight_layout()
plt.show()
filename: VSC_bi_9.dat
This notebook was contributed by Prof. Nakul Narayanan K, Govt. Engineering College, Thrissur. He may be contacted at nakul@gectcr.ac.in.