1-phase CSI
The single-phase current source inverter given below is operated such that the current through the RC load is a $1\,$kHz square wave. What is the peak magnitude of the voltage $V_{AB}$ across the load?In [1]:
from IPython.display import Image
Image(filename =r'CSI_1ph_1_fig_1.png', width=300)
Out[1]:
In [2]:
# run this cell to view the circuit file.
%pycat CSI_1ph_1_orig.in
We now replace the strings such as \$Idc, \$R, with the values of our choice by running the python script given below. It takes an existing circuit file CSI_1ph_1_orig.in and produces a new circuit file CSI_1ph_1.in, after replacing \$Idc, \$R, etc. with values of our choice.
In [3]:
import gseim_calc as calc
s_Idc = '10'
s_R = '100'
s_C = '10e-6'
s_f_hz = "1.0e3"
f_hz = float(s_f_hz)
T = 1/f_hz
s_Tby2 = "%11.4E"%(T/2)
l = [
('$Idc', s_Idc),
('$R', s_R),
('$C', s_C),
('$f_hz', s_f_hz),
('$Tby2', s_Tby2)
]
calc.replace_strings_1("CSI_1ph_1_orig.in", "CSI_1ph_1.in", l)
print('CSI_1ph_1.in is ready for execution')
CSI_1ph_1.in is ready for execution
Execute the following cell to run GSEIM on CSI_1ph_1.in.
In [4]:
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("CSI_1ph_1.in")
os.system('run_gseim CSI_1ph_1.in')
get_lib_elements: filename gseim_aux/xbe.aux get_lib_elements: filename gseim_aux/ebe.aux Circuit: filename = CSI_1ph_1.in main: i_solve = 0 main: calling solve_trns mat_ssw_1_ex: n_statevar: 2 Transient simulation starts... i=0 i=1000 solve_ssw_ex: ssw_iter_newton=0, rhs_ssw_norm=2.1195e-03 Transient simulation starts... i=0 i=1000 solve_ssw_ex: ssw_iter_newton=1, rhs_ssw_norm=2.4510e-10 Transient simulation starts... i=0 i=1000 solve_ssw_ex: ssw_iter_newton=2, rhs_ssw_norm=4.3368e-19 solve_ssw_ex: calling solve_ssw_1_ex for one more trns step Transient simulation starts... i=0 i=1000 solve_ssw_1_ex over (after trns step for output) solve_ssw_ex ends, slv.ssw_iter_newton=2 GSEIM: Program completed.
Out[4]:
0
The circuit file (CSI_1ph_1.in) is created in the same directory as that used for launching Jupyter notebook. The last step (i.e., running GSEIM on CSI_1ph_1.in) creates a data file called CSI_1ph_1.datin 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
slv = calc.slv("CSI_1ph_1.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_v_out = slv.get_index(i_slv,i_out,"v_out")
col_g1 = slv.get_index(i_slv,i_out,"g1")
col_g2 = slv.get_index(i_slv,i_out,"g2")
col_IS1 = slv.get_index(i_slv,i_out,"IS1")
col_IS2 = slv.get_index(i_slv,i_out,"IS2")
col_IS3 = slv.get_index(i_slv,i_out,"IS3")
col_IS4 = slv.get_index(i_slv,i_out,"IS4")
col_Iload = slv.get_index(i_slv,i_out,"Iload")
# get f_hz from the circuit file:
f_in = open("CSI_1ph_1.in", "r")
for line in f_in:
if 'name=clock1' in line:
for s in line.split():
if s.startswith('f_hz='):
f_hz = float(s.split('=')[1])
f_in.close()
T = 1/f_hz
l1 = calc.min_max_1(t, u[:,col_v_out], 0.0, 2.0*T)
print('max(V_AB):', "%11.4E"%l1[1])
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_{AB}$', fontsize=12)
ax[1].set_ylabel(r'$g_x$' , fontsize=12)
ax[0].tick_params(labelbottom=False)
color1 = "tomato"
color2 = "dodgerblue"
color3 = "olive"
ax[0].plot(t*1e3, u[:,col_v_out], color=color1, linewidth=1.0, label="$V_{AB}$")
ax[1].plot(t*1e3, (u[:,col_g1] ), color=color2, linewidth=1.0, label="$g_1$")
ax[1].plot(t*1e3, (u[:,col_g2] - 1.2), color=color3, linewidth=1.0, label="$g_2$")
ax[1].set_xlabel('time (msec)', fontsize=12)
ax[1].tick_params(left = False)
ax[1].set_yticks([])
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: CSI_1ph_1.dat max(V_AB): 2.4444E+02
This notebook was contributed by Prof. Nakul Narayanan K, Govt. Engineering College, Thrissur. He may be contacted at nakul@gectcr.ac.in.
In [ ]: