from IPython.display import Image
Image(filename =r'Animation_boost_fig_1.png', width=350)
# run this cell to view the circuit file.
%pycat Animation_boost_1_orig.in
import numpy as np
import gseim_calc as calc
import os
import dos_unix
import math
import sys
#NL1 = 17
NL1 = 41
L_arr = np.linspace(0.5e-3, 0.1e-3, NL1)
IL = []
Vo = []
slv = calc.slv("Animation_boost_1_orig.in")
i_slv = 0
i_out = 0
filename = slv.l_filename_all[i_slv][i_out]
col_IL = slv.get_index(i_slv,i_out,"IL")
col_Vo = slv.get_index(i_slv,i_out,"v_out")
ymin_IL = 1.0e10
ymax_IL = -1.0e10
ymin_Vo = 1.0e10
ymax_Vo = -1.0e10
flag_cross = False
k_cross = -1
for k, L in enumerate(L_arr):
s_L = "%11.4E"%L
l = [
('$L', s_L),
]
print('k:', k, 'L:', "%10.3E"%L)
calc.replace_strings_1("Animation_boost_1_orig.in", "Animation_boost_1.in", l)
# uncomment for windows:
#dos_unix.d2u("Animation_boost_1.in")
os.system('run_gseim Animation_boost_1.in')
u = np.loadtxt(filename)
t = u[:, 0]
T = t[-1]/2
IL1 = u[:, col_IL]
Vo1 = u[:, col_Vo]
ymin_IL1 = min(IL1)
ymax_IL1 = max(IL1)
ymin_Vo1 = min(Vo1)
ymax_Vo1 = max(Vo1)
ymin_IL = min(ymin_IL, ymin_IL1)
ymax_IL = max(ymax_IL, ymax_IL1)
ymin_Vo = min(ymin_Vo, ymin_Vo1)
ymax_Vo = max(ymax_Vo, ymax_Vo1)
IL.append(IL1)
Vo.append(Vo1)
if not flag_cross:
if ymin_IL1 < 1e-3:
flag_cross = True
k_cross = k
xmin = 0.0
xmax = 2.0*T*1e3 # xmax is in msec
del_IL = 0.1*(ymax_IL - ymin_IL)
ymin_IL = ymin_IL - del_IL
ymax_IL = ymax_IL + del_IL
del_Vo = 0.1*(ymax_Vo - ymin_Vo)
ymin_Vo = ymin_Vo - del_Vo
ymax_Vo = ymax_Vo + del_Vo
if k_cross == -1:
print('k_cross is -1? Halting...')
sys.exit()
print('k_cross:', k_cross)
N_repeat = 10 # pause for a longer interval at cross-over
IL2 = []
Vo2 = []
L_arr2 = []
for k, IL0 in enumerate(IL):
IL2 += ([IL0]*(N_repeat if k == k_cross else 1))
for k, Vo0 in enumerate(Vo):
Vo2 += ([Vo0]*(N_repeat if k == k_cross else 1))
for k, L0 in enumerate(L_arr):
L_arr2 += ([L0]*(N_repeat if k == k_cross else 1))
k: 0 L: 5.000E-04 k: 1 L: 4.900E-04 k: 2 L: 4.800E-04 k: 3 L: 4.700E-04 k: 4 L: 4.600E-04 k: 5 L: 4.500E-04 k: 6 L: 4.400E-04 k: 7 L: 4.300E-04 k: 8 L: 4.200E-04 k: 9 L: 4.100E-04 k: 10 L: 4.000E-04 k: 11 L: 3.900E-04 k: 12 L: 3.800E-04 k: 13 L: 3.700E-04 k: 14 L: 3.600E-04 k: 15 L: 3.500E-04 k: 16 L: 3.400E-04 k: 17 L: 3.300E-04 k: 18 L: 3.200E-04 k: 19 L: 3.100E-04 k: 20 L: 3.000E-04 k: 21 L: 2.900E-04 k: 22 L: 2.800E-04 k: 23 L: 2.700E-04 k: 24 L: 2.600E-04 k: 25 L: 2.500E-04 k: 26 L: 2.400E-04 k: 27 L: 2.300E-04 k: 28 L: 2.200E-04 k: 29 L: 2.100E-04 k: 30 L: 2.000E-04 k: 31 L: 1.900E-04 k: 32 L: 1.800E-04 k: 33 L: 1.700E-04 k: 34 L: 1.600E-04 k: 35 L: 1.500E-04 k: 36 L: 1.400E-04 k: 37 L: 1.300E-04 k: 38 L: 1.200E-04 k: 39 L: 1.100E-04 k: 40 L: 1.000E-04 k_cross: 19
import matplotlib.pyplot as plt
import sys
from matplotlib.ticker import (MultipleLocator, AutoMinorLocator)
from matplotlib import animation
from IPython.display import HTML
import gseim_calc as calc
from matplotlib import ticker
from setsize import set_size
fig, ax = plt.subplots(2, sharex=False)
plt.subplots_adjust(wspace=0, hspace=0.0)
set_size(5.0, 4, ax[0])
ax[0].set(xlim=[xmin, xmax], ylim=[ymin_IL, ymax_IL])
ax[1].set(xlim=[xmin, xmax], ylim=[ymin_Vo, ymax_Vo])
ax[0].tick_params(labelbottom=False)
ax[1].set_xlabel(r'time (msec)', fontsize=12)
ax[0].set_ylabel(r'$i_L$ (A)', fontsize=12)
ax[1].set_ylabel(r'$V_o$ (V)', fontsize=12)
ax[1].xaxis.set_major_formatter(ticker.StrMethodFormatter("{x:.1f}"))
ax[0].grid(color='#CCCCCC', linestyle='solid', linewidth=0.5)
ax[1].grid(color='#CCCCCC', linestyle='solid', linewidth=0.5)
line_IL = ax[0].plot([], [], color='blue', linestyle = '-', linewidth=1.0)[0]
line_Vo = ax[1].plot([], [], color='red', linestyle = '-', linewidth=1.0)[0]
line_IL.set_xdata(t*1e3)
line_Vo.set_xdata(t*1e3)
props1 = dict(boxstyle='round', facecolor='grey', alpha=0.15) # bbox features
text1 = ax[0].text(0.77, 0.95, '', transform=ax[0].transAxes, fontsize=10, verticalalignment='top', bbox=props1)
props2 = dict(boxstyle='round', facecolor='lightcyan', alpha=0.15) # bbox features
text2= ax[0].text(0.05, 0.9, '', transform=ax[0].transAxes, fontsize=14, verticalalignment='top', bbox=props2)
def update(frame):
line_IL.set_ydata(IL2[frame])
line_Vo.set_ydata(Vo2[frame])
s1 = 'CCM' if (frame < k_cross) else 'DCM'
text1.set_text('L = %6.3f'%(1e3*L_arr2[frame]) + ' mH')
text2.set_text(s1)
return
anim = animation.FuncAnimation(
fig=fig,
func=update,
frames=(NL1+N_repeat-1),
interval=200,
repeat=False)
#plt.tight_layout()
plt.close()
HTML(anim.to_jshtml())
This notebook was contributed by Prof. Nakul Narayanan K, Govt. Engineering College, Thrissur. He may be contacted at nakul@gectcr.ac.in.