1-phase rectifier
For the rectifier circuit given below, determine the RMS values of the diode currents and the voltage source current. The source voltage is 220 V, 50 Hz.In [1]:
from IPython.display import Image
Image(filename =r'rectifier_1ph_7_fig_1.png', width=400)
Out[1]:
In [2]:
# run this cell to view the circuit file.
%pycat rectifier_1ph_7_orig.in
We now replace the strings such as \$Idc with the values of our choice by running the python script given below. It takes an existing circuit file rectifier_1ph_7_orig.in and produces a new circuit file rectifier_1ph_7.in, after replacing \$Idc (etc) with values of our choice.
In [3]:
import gseim_calc as calc
import numpy as np
import sys
s_Idc = "10"
if float(s_Idc) < 0.0:
print('Idc < 0 is not allowed. Halting...')
sys.exit()
l = [
('$Idc', s_Idc),
]
calc.replace_strings_1("rectifier_1ph_7_orig.in", "rectifier_1ph_7.in", l)
print('rectifier_1ph_7.in is ready for execution')
rectifier_1ph_7.in is ready for execution
Execute the following cell to run GSEIM on rectifier_1ph_7.in.
In [4]:
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("rectifier_1ph_7.in")
os.system('run_gseim rectifier_1ph_7.in')
get_lib_elements: filename gseim_aux/xbe.aux get_lib_elements: filename gseim_aux/ebe.aux Circuit: filename = rectifier_1ph_7.in Circuit: n_xbeu_vr = 0 Circuit: n_ebeu_nd = 4 main: i_solve = 0 main: calling solve_trns Transient simulation starts... i=0 i=1000 i=2000 GSEIM: Program completed.
Out[4]:
0
The circuit file (rectifier_1ph_2.in) is created in the same directory as that used for launching Jupyter notebook. The last step (i.e., running GSEIM on rectifier_1ph_2.in) creates a data file called rectifier_1ph_2.dat in the same directory. We can now use the python code below to compute/plot the various quantities of interest.
In [5]:
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("rectifier_1ph_7.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]
col_ID1 = slv.get_index(i_slv,i_out,"ID1")
col_ID2 = slv.get_index(i_slv,i_out,"ID2")
col_V_VS = slv.get_index(i_slv,i_out,"V_VS")
col_I_VS = slv.get_index(i_slv,i_out,"I_VS")
l_ID1 = calc.avg_rms_2(t, u[:,col_ID1] , 0.0, 2.0*T, 1.0e-5*T)
l_ID2 = calc.avg_rms_2(t, u[:,col_ID2] , 0.0, 2.0*T, 1.0e-5*T)
l_I_VS = calc.avg_rms_2(t, u[:,col_I_VS], 0.0, 2.0*T, 1.0e-5*T)
t_ID1 = np.array(l_ID1[0])
t_ID2 = np.array(l_ID2[0])
t_I_VS = np.array(l_I_VS[0])
print('average value of ID1:' , "%11.4E"%l_ID1[1][0])
print('average value of ID2:' , "%11.4E"%l_ID2[1][0])
print('average value of I_VS:', "%11.4E"%l_I_VS[1][0])
print('rms value of ID1:' , "%11.4E"%l_ID1[2][0])
print('rms value of ID2:' , "%11.4E"%l_ID2[2][0])
print('rms value of I_VS:', "%11.4E"%l_I_VS[2][0])
color1 = 'blue'
color2 = 'green'
color3 = 'red'
color4 = 'dodgerblue'
fig, ax = plt.subplots(4, sharex=False)
plt.subplots_adjust(wspace=0, hspace=0.0)
set_size(5.5, 8, ax[0])
for i in range(4):
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_s$' , fontsize=12)
ax[1].set_ylabel(r'$i_{Vs}$', fontsize=12)
ax[2].set_ylabel(r'$I_{D1}$', fontsize=12)
ax[3].set_ylabel(r'$I_{D2}$', fontsize=12)
for i in range(3):
ax[i].tick_params(labelbottom=False)
ax[0].plot(t*1e3, u[:,col_V_VS], color=color1, linewidth=1.0, label="$V_s$")
ax[1].plot(t*1e3, u[:,col_I_VS], color=color2, linewidth=1.0, label="$i_{Vs}$")
ax[2].plot(t*1e3, u[:,col_ID1] , color=color3, linewidth=1.0, label="$I_{D1}$")
ax[3].plot(t*1e3, u[:,col_ID2] , color=color4, linewidth=1.0, label="$I_{D2}$")
ax[1].plot(t_I_VS*1e3, l_I_VS[2], color=color2, linewidth=1.0, label="$I_{Vs}^{rms}$", linestyle='--', dashes=(5,3))
ax[2].plot(t_ID1*1e3 , l_ID1[2] , color=color3, linewidth=1.0, label="$I_{D1}^{rms}$", linestyle='--', dashes=(5,3))
ax[3].plot(t_ID2*1e3 , l_ID2[2] , color=color4, linewidth=1.0, label="$I_{D2}^{rms}$", linestyle='--', dashes=(5,3))
ax[3].set_xlabel('time (msec)', fontsize=11)
for k in range(1, 4):
ax[k].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: rectifier_1ph_7.dat average value of ID1: 5.0000E+00 average value of ID2: 5.0000E+00 average value of I_VS: -3.3888E-11 rms value of ID1: 7.0677E+00 rms value of ID2: 7.0677E+00 rms value of I_VS: 9.9904E+00
This notebook was contributed by Prof. Nakul Narayanan K, Govt. Engineering College, Thrissur. He may be contacted at nakul@gectcr.ac.in.