from IPython.display import Image
Image(filename =r'rectifier_1ph_4_fig_1.png', width=400)
# run this cell to view the circuit file.
%pycat rectifier_1ph_4_orig.in
We now replace the strings such as \\$R with the values of our choice by running the python script given below. It takes an existing circuit file rectifier_1ph_4_orig.in and produces a new circuit file rectifier_1ph_4.in, after replacing \\$R (etc) with values of our choice.
import gseim_calc as calc
import numpy as np
s_R = "50"
s_L = "10e-3" # to be changed by user
l = [
('$R', s_R),
('$L', s_L),
]
calc.replace_strings_1("rectifier_1ph_4_orig.in", "rectifier_1ph_4.in", l)
print('rectifier_1ph_4.in is ready for execution')
rectifier_1ph_4.in is ready for execution
Execute the following cell to run GSEIM on rectifier_1ph_4.in.
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("rectifier_1ph_4.in")
os.system('run_gseim rectifier_1ph_4.in')
Circuit: filename = rectifier_1ph_4.in main: i_solve = 0 main: calling solve_sss solve_sss starting: sss_n_st: 1 solve_sss_ex: sss_iter_newton=0, rhs_sss_norm=3.2831e+00, sss_period_1_compute=4.0000e-02 solve_sss_ex: sss_iter_newton=1, rhs_sss_norm=0.0000e+00, sss_period_1_compute=4.0000e-02 solve_sss_ex: calling sss_solve_trns_ex for one more trns step Transient simulation starts... i=0 i=1000 GSEIM: Program completed.
0
The circuit file (rectifier_1ph_4.in) is created in the same directory as that used for launching Jupyter notebook. The last step (i.e., running GSEIM on rectifier_1ph_4.in) creates a data file called rectifier_1ph_4.dat in 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("rectifier_1ph_4.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]
IL = slv.get_array_double(i_slv,i_out,"IL",u)
vs = slv.get_array_double(i_slv,i_out,"vs",u)
l_cross_1_IL, l_cross_2_IL = calc.cross_over_points_1(t, IL, 0.0, 2.0*T, 1.0e-10)
print('zero-crossing points of IL (positive slope):')
for t1 in l_cross_1_IL:
print(" ", "%11.4E"%t1)
print('zero-crossing points of IL (negative slope):')
for t1 in l_cross_2_IL:
print(" ", "%11.4E"%t1)
t_conduction_D = l_cross_2_IL[1]-l_cross_1_IL[0]
print("conduction duration for D (sec):", "%11.4E"%t_conduction_D)
print("conduction duration for D (deg):", "%11.4E"%((t_conduction_D/T)*360.0))
color1='blue'
color2='green'
fig, ax = plt.subplots(2, sharex=False)
plt.subplots_adjust(wspace=0, hspace=0.0)
set_size(5.5, 4, ax[0])
for i in range(2):
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_L$', fontsize=12)
ax[0].tick_params(labelbottom=False)
ax[0].plot(t*1e3, vs, color=color1, linewidth=1.0, label="$v_s$")
ax[1].plot(t*1e3, IL, color=color2, linewidth=1.0, label="$I_L$")
ax[1].set_xlabel('time (msec)', fontsize=11)
#plt.tight_layout()
plt.show()
filename: rectifier_1ph_4.dat
zero-crossing points of IL (positive slope):
1.5000E-02
3.5000E-02
zero-crossing points of IL (negative slope):
7.9599E-03
2.7960E-02
conduction duration for D (sec): 1.2960E-02
conduction duration for D (deg): 2.3328E+02
This notebook was contributed by Prof. Nakul Narayanan K, Govt. Engineering College, Thrissur. He may be contacted at nakul@gectcr.ac.in.