(Follow the convention that $\cos\,(\omega \,t)$ corresponds to the phasor $1\,\angle {0}$.)
from IPython.display import Image
Image(filename =r'Animation_phasor_3A_fig_1.png', width=320)
# run this cell to view the circuit file.
%pycat Animation_phasor_3B_orig.in
import numpy as np
import gseim_calc as calc
import os
import dos_unix
import math
import cmath
I_b = 5.0
V_b = 100.0
P_b = I_b*V_b
NC1 = 60
C_arr = np.linspace(1.0e-6, 60.0e-6, NC1)
slv = calc.slv("Animation_phasor_3B_orig.in")
i_slv = 0
IR1 = []
IC1 = []
Is1 = []
Vs1 = []
SR1 = []
SC1 = []
SL1 = []
SV1 = []
for C in C_arr:
s_C = "%11.4E"%C
l = [
('$C', s_C),
]
print('C:', "%5.1E"%C)
calc.replace_strings_1("Animation_phasor_3B_orig.in", "Animation_phasor_3B.in", l)
# uncomment for windows:
#dos_unix.d2u("Animation_phasor_3B.in")
os.system('run_gseim Animation_phasor_3B.in')
i_out = 0
filename = slv.l_filename_all[i_slv][i_out]
u = np.loadtxt(filename)
IR = slv.get_scalar_complex_1(i_slv, i_out, "IR_ac", u)
IC = slv.get_scalar_complex_1(i_slv, i_out, "IC_ac", u)
Is = slv.get_scalar_complex_1(i_slv, i_out, "Is_ac", u)
Vs = slv.get_scalar_complex_1(i_slv, i_out, "Vs_ac", u)
IR1.append(IR)
IC1.append(IC)
Is1.append(Is)
Vs1.append(Vs)
i_out = 1
filename = slv.l_filename_all[i_slv][i_out]
u = np.loadtxt(filename)
SR = slv.get_scalar_complex_1(i_slv, i_out, "S_R", u)
SC = slv.get_scalar_complex_1(i_slv, i_out, "S_C", u)
SV = slv.get_scalar_complex_1(i_slv, i_out, "S_Vs", u)
SL = slv.get_scalar_complex_1(i_slv, i_out, "S_L", u)
SR1.append(SR)
SC1.append(SC)
SL1.append(SL)
SV1.append(SV)
np_Vs = (np.array(Vs1))/V_b
np_IR = (np.array(IR1))/I_b
np_IC = (np.array(IC1))/I_b
np_Is = (np.array(Is1))/I_b
Vs1 = list(np_Vs)
IR1 = list(np_IR)
IC1 = list(np_IC)
Is1 = list(np_Is)
real_IR = list(np_IR.real)
real_IC = list(np_IC.real)
real_Is = list(np_Is.real)
real_Vs = list(np_Vs.real)
imag_IR = list(np_IR.imag)
imag_IC = list(np_IC.imag)
imag_Is = list(np_Is.imag)
imag_Vs = list(np_Vs.imag)
np_SR = (np.array(SR1))/P_b
np_SC = (np.array(SC1))/P_b
np_SL = (np.array(SL1))/P_b
np_SV = (np.array(SV1))/P_b
SR1 = list(np_SR)
SC1 = list(np_SC)
SL1 = list(np_SL)
SV1 = list(np_SV)
real_SR = list(np_SR.real)
real_SC = list(np_SC.real)
real_SL = list(np_SL.real)
real_SV = list(np_SV.real)
imag_SR = list(np_SR.imag)
imag_SC = list(np_SC.imag)
imag_SL = list(np_SL.imag)
imag_SV = list(np_SV.imag)
C: 1.0E-06 C: 2.0E-06 C: 3.0E-06 C: 4.0E-06 C: 5.0E-06 C: 6.0E-06 C: 7.0E-06 C: 8.0E-06 C: 9.0E-06 C: 1.0E-05 C: 1.1E-05 C: 1.2E-05 C: 1.3E-05 C: 1.4E-05 C: 1.5E-05 C: 1.6E-05 C: 1.7E-05 C: 1.8E-05 C: 1.9E-05 C: 2.0E-05 C: 2.1E-05 C: 2.2E-05 C: 2.3E-05 C: 2.4E-05 C: 2.5E-05 C: 2.6E-05 C: 2.7E-05 C: 2.8E-05 C: 2.9E-05 C: 3.0E-05 C: 3.1E-05 C: 3.2E-05 C: 3.3E-05 C: 3.4E-05 C: 3.5E-05 C: 3.6E-05 C: 3.7E-05 C: 3.8E-05 C: 3.9E-05 C: 4.0E-05 C: 4.1E-05 C: 4.2E-05 C: 4.3E-05 C: 4.4E-05 C: 4.5E-05 C: 4.6E-05 C: 4.7E-05 C: 4.8E-05 C: 4.9E-05 C: 5.0E-05 C: 5.1E-05 C: 5.2E-05 C: 5.3E-05 C: 5.4E-05 C: 5.5E-05 C: 5.6E-05 C: 5.7E-05 C: 5.8E-05 C: 5.9E-05 C: 6.0E-05
import matplotlib.pyplot as plt
from matplotlib.ticker import (MultipleLocator, AutoMinorLocator)
from setsize import set_size
from matplotlib import animation
from IPython.display import HTML
import matplotlib.image as img
im = img.imread('Animation_phasor_3B_fig_2.png')
fig, ax = plt.subplots()
fig.set_size_inches(8, 5)
plt.subplots_adjust(left=0.0, right=0.7, top=0.9, bottom=0.1)
xmin = min(real_IR + real_IC + real_Is + real_Vs) - 0.2
xmax = max(real_IR + real_IC + real_Is + real_Vs) + 0.2
ymin = min(imag_IR + imag_IC + imag_Is + imag_Vs) - 0.2
ymax = max(imag_IR + imag_IC + imag_Is + imag_Vs) + 0.2
ax.set_aspect('equal', adjustable='box')
ax.set(xlim=[xmin, xmax], ylim=[ymin, ymax])
plt.grid(color='#CCCCCC', linestyle='solid', linewidth=0.5)
plt.xlabel('$Re$',fontsize=12)
plt.ylabel('$Im$',fontsize=12)
fig.suptitle('Note: I and V in p.u.', fontsize=12)
inset2 = fig.add_axes([0.50, 0.3, 0.5, 0.55])
inset2.imshow(im)
inset2.axis('off')
plt.setp(inset2, xticks=[], yticks=[])
c_Is = 'blue'
c_IR = 'red'
c_IC = 'green'
c_Vs = 'grey'
line_Is = ax.plot([], [], color=c_Is, linestyle='--', linewidth=0.8, dashes=(3,3))[0]
line2_Is = []
line2_IR = []
line2_IC = []
line2_Vs = []
for i in range(3):
if i == 0:
line1_Is = ax.plot([], [], color=c_Is, linewidth=1.0, label='$I_s$')[0]
line1_IR = ax.plot([], [], color=c_IR, linewidth=1.0, label='$I_R$')[0]
line1_IC = ax.plot([], [], color=c_IC, linewidth=1.0, label='$I_C$')[0]
line1_Vs = ax.plot([], [], color=c_Vs, linewidth=1.0, label='$V_s$')[0]
else:
line1_Is = ax.plot([], [], color=c_Is, linewidth=1.0)[0]
line1_IR = ax.plot([], [], color=c_IR, linewidth=1.0)[0]
line1_IC = ax.plot([], [], color=c_IC, linewidth=1.0)[0]
line1_Vs = ax.plot([], [], color=c_Vs, linewidth=1.0)[0]
line2_Is .append(line1_Is)
line2_IR .append(line1_IR)
line2_IC .append(line1_IC)
line2_Vs .append(line1_Vs)
ax.legend(loc='lower left', fontsize=11, bbox_to_anchor=(1.05, 0.0))
l3_Is = []
l3_IR = []
l3_IC = []
l3_Vs = []
l_labels_Is = []
l_labels_IR = []
l_labels_IC = []
l_labels_Vs = []
props = dict(boxstyle='round', facecolor='grey', alpha=0.15) # bbox features
text1 = ax.text(1.03, 0.98, '', transform=ax.transAxes, fontsize=11, verticalalignment='top', bbox=props)
theta_deg = 20.0
length_arrow = 0.04*(xmax-xmin)
def update(frame):
line_Is.set_xdata(real_Is[:frame+1])
line_Is.set_ydata(imag_Is[:frame+1])
l3_Is.clear()
l_labels_Is.clear()
calc.phasor_append_1(l3_Is, l_labels_Is, Is1[frame], "$I_s$")
l4_Is = calc.phasor_2(l3_Is , theta_deg, length_arrow, 0.4)
for k, t in enumerate(l4_Is[0]):
line2_Is[k].set_xdata(t[0])
line2_Is[k].set_ydata(t[1])
l3_IR.clear()
l_labels_IR.clear()
calc.phasor_append_1(l3_IR, l_labels_IR, IR1[frame], "$I_R$")
l4_IR = calc.phasor_2(l3_IR , theta_deg, length_arrow, 0.4)
for k, t in enumerate(l4_IR[0]):
line2_IR[k].set_xdata(t[0])
line2_IR[k].set_ydata(t[1])
l3_IC.clear()
l_labels_IC.clear()
calc.phasor_append_1(l3_IC, l_labels_IC, IC1[frame], "$I_C$")
l4_IC = calc.phasor_2(l3_IC , theta_deg, length_arrow, 0.4)
for k, t in enumerate(l4_IC[0]):
line2_IC[k].set_xdata(t[0])
line2_IC[k].set_ydata(t[1])
l3_Vs.clear()
l_labels_Vs.clear()
calc.phasor_append_1(l3_Vs, l_labels_Vs, Vs1[frame], "$V_s$")
l4_Vs = calc.phasor_2(l3_Vs , theta_deg, length_arrow, 0.4)
for k, t in enumerate(l4_Vs[0]):
line2_Vs[k].set_xdata(t[0])
line2_Vs[k].set_ydata(t[1])
text1.set_text(
r'$C$' + ' = %4.0f' % (C_arr[frame]*1e6) + r' $\mu$F'
)
return
anim = animation.FuncAnimation(
fig=fig,
func=update,
frames=NC1,
interval=500,
repeat=False)
#plt.tight_layout()
plt.close()
HTML(anim.to_jshtml())
import matplotlib.pyplot as plt
from matplotlib.ticker import (MultipleLocator, AutoMinorLocator)
from setsize import set_size
from matplotlib import animation
from IPython.display import HTML
fig, ax = plt.subplots()
fig.set_size_inches(8, 5)
xmin = min(real_SR + real_SC + real_SL + real_SV) - 0.05
xmax = max(real_SR + real_SC + real_SL + real_SV) + 0.05
ymin = min(imag_SR + imag_SC + imag_SL + imag_SV) - 0.05
ymax = max(imag_SR + imag_SC + imag_SL + imag_SV) + 0.05
ax.set_aspect('equal', adjustable='box')
ax.set(xlim=[xmin, xmax], ylim=[ymin, ymax])
plt.grid(color='#CCCCCC', linestyle='solid', linewidth=0.5)
plt.xlabel('$Re (S)$',fontsize=12)
plt.ylabel('$Im (S)$',fontsize=12)
fig.suptitle('Note: S in p.u.', fontsize=12)
c_SV = 'blue'
c_SR = 'red'
c_SC = 'green'
c_SL = 'goldenrod'
line_SV = ax.plot([], [], color=c_SV, linestyle='--', linewidth=0.8, dashes=(3,3))[0]
line2_SV = []
line2_SR = []
line2_SC = []
line2_SL = []
for i in range(3):
if i == 0:
line1_SV = ax.plot([], [], color=c_SV, linewidth=1.0, label='$S_{Vs}$')[0]
line1_SR = ax.plot([], [], color=c_SR, linewidth=1.0, label='$S_R$')[0]
line1_SC = ax.plot([], [], color=c_SC, linewidth=1.0, label='$S_C$')[0]
line1_SL = ax.plot([], [], color=c_SL, linewidth=1.0, label='$S_L$')[0]
else:
line1_SV = ax.plot([], [], color=c_SV, linewidth=1.0)[0]
line1_SR = ax.plot([], [], color=c_SR, linewidth=1.0)[0]
line1_SC = ax.plot([], [], color=c_SC, linewidth=1.0)[0]
line1_SL = ax.plot([], [], color=c_SL, linewidth=1.0)[0]
line2_SV .append(line1_SV)
line2_SR .append(line1_SR)
line2_SC .append(line1_SC)
line2_SL .append(line1_SL)
ax.legend(loc='lower left', fontsize=11, bbox_to_anchor=(1.05, 0.0))
l3_SV = []
l3_SR = []
l3_SC = []
l3_SL = []
l_labels_SV = []
l_labels_SR = []
l_labels_SC = []
l_labels_SL = []
props = dict(boxstyle='round', facecolor='grey', alpha=0.15) # bbox features
text1 = ax.text(1.03, 0.98, '', transform=ax.transAxes, fontsize=11, verticalalignment='top', bbox=props)
theta_deg = 20.0
length_arrow = 0.06*(xmax-xmin)
def update(frame):
line_SV.set_xdata(real_SV[:frame+1])
line_SV.set_ydata(imag_SV[:frame+1])
l3_SV.clear()
l_labels_SV.clear()
calc.phasor_append_1(l3_SV, l_labels_SV, SV1[frame], "$S_{Vs}$")
l4_SV = calc.phasor_2(l3_SV , theta_deg, length_arrow, 0.4)
for k, t in enumerate(l4_SV[0]):
line2_SV[k].set_xdata(t[0])
line2_SV[k].set_ydata(t[1])
l3_SR.clear()
l_labels_SR.clear()
calc.phasor_append_1(l3_SR, l_labels_SR, SR1[frame], "$S_R$")
l4_SR = calc.phasor_2(l3_SR , theta_deg, length_arrow, 0.4)
for k, t in enumerate(l4_SR[0]):
line2_SR[k].set_xdata(t[0])
line2_SR[k].set_ydata(t[1])
l3_SC.clear()
l_labels_SC.clear()
calc.phasor_append_1(l3_SC, l_labels_SC, SC1[frame], "$S_C$")
l4_SC = calc.phasor_2(l3_SC , theta_deg, length_arrow, 0.4)
for k, t in enumerate(l4_SC[0]):
line2_SC[k].set_xdata(t[0])
line2_SC[k].set_ydata(t[1])
l3_SL.clear()
l_labels_SL.clear()
calc.phasor_append_1(l3_SL, l_labels_SL, SL1[frame], "$S_L$")
l4_SL = calc.phasor_2(l3_SL , theta_deg, length_arrow, 0.4)
for k, t in enumerate(l4_SL[0]):
line2_SL[k].set_xdata(t[0])
line2_SL[k].set_ydata(t[1])
text1.set_text(
r'$C$' + ' = %4.0f' % (C_arr[frame]*1e6) + r' $\mu$F'
)
return
anim = animation.FuncAnimation(
fig=fig,
func=update,
frames=NC1,
interval=500,
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.