Phasors
In the circuit given below, $V_S(t) = 100\,\cos \,(\omega \,t + 60^{\circ})$, $I_S(t) = 10\,\cos \,(\omega \,t + 30^{\circ})$, and the frequency is $50\,$Hz.- Find $R$ and $L$.
- Determine $P$ and $Q$ delivered to the load.
- Show that the instantaneous power $p(t)$ has a maximum $P + \sqrt{P^2+Q^2}$ and a minimum $P - \sqrt{P^2+Q^2}$. Verify with simulation results.
(Follow the convention that $\cos\,(\omega \,t)$ corresponds to the phasor $1\,\angle {0}$.)
from IPython.display import Image
Image(filename =r'phasor_11_fig_1.png', width=280)
# run this cell to view the circuit file.
%pycat phasor_11_orig.in
We now replace the strings \$R and \$L with the values of our choice by running the python script given below. It takes an existing circuit file phasor_11_orig.in and produces a new circuit file phasor_11.in, after replacing \$R and \$L with the values of our choice.
import gseim_calc as calc
s_R = '20' # to be changed by user
s_L = '40m' # to be changed by user
l = [
('$R', s_R),
('$L', s_L),
]
calc.replace_strings_1("phasor_11_orig.in", "phasor_11.in", l)
print('phasor_11.in is ready for execution')
phasor_11.in is ready for execution
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("phasor_11.in")
os.system('run_gseim phasor_11.in')
Circuit: filename = phasor_11.in main: i_solve = 0 main: i_solve = 1 main: calling solve_ssw mat_ssw_1_e: n_statevar: 1 Transient simulation starts... i=0 solve_ssw_e: ssw_iter_newton=0, rhs_ssw_norm=6.91652e-06, ssw_period_1_compute=0.04 Transient simulation starts... i=0 solve_ssw_e: ssw_iter_newton=1, rhs_ssw_norm=3.33955e-13, ssw_period_1_compute=0.04 solve_ssw_e: calling solve_ssw_1_e for one more trns step Transient simulation starts... i=0 solve_ssw_1_e over (after trns step for output) solve_ssw_e ends, slv.ssw_iter_newton=1 GSEIM: Program completed.
0
The circuit file (phasor_11.in) is created in the same directory as that used for launching Jupyter notebook. The last step (i.e., running GSEIM on phasor_11.in) creates the data files phasor_11_1.dat, etc. in the same directory. We can now use the python code below to compute and display the quantities of interest.
import numpy as np
import gseim_calc as calc
import matplotlib.pyplot as plt
from matplotlib.ticker import (MultipleLocator, AutoMinorLocator)
from setsize import set_size
rad_to_deg = 180.0/np.pi
slv = calc.slv("phasor_11.in")
i_slv = 0
i_out = 0
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)
IR = slv.get_scalar_complex_1(i_slv, i_out, "IR_ac", u)
IL = slv.get_scalar_complex_1(i_slv, i_out, "IL_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)
s_format = "%7.2f"
print('phasors in rectangular form:')
calc.print_complex_rect('IR', IR, s_format)
calc.print_complex_rect('IL', IL, s_format)
calc.print_complex_rect('Is', Is, s_format)
calc.print_complex_rect('Vs', Vs, s_format)
print('phasors in polar form:')
calc.print_complex_polar('IR', IR, s_format)
calc.print_complex_polar('IL', IL, s_format)
calc.print_complex_polar('Is', Is, s_format)
calc.print_complex_polar('Vs', Vs, s_format)
Vs1 = Vs/20.0
l_colors = ["blue", "red", "green", "grey", "dodgerblue", "tomato"]
l1 = []
l1_labels = []
color_IR = calc.phasor_append_1a(l1, l1_labels, IR, "$I_R$", l_colors)
color_IL = calc.phasor_append_1a(l1, l1_labels, IL, "$I_L$", l_colors)
color_Is = calc.phasor_append_1a(l1, l1_labels, Is, "$I_s$", l_colors)
color_Vs1 = calc.phasor_append_1a(l1, l1_labels, Vs1, "$V_s/20$", l_colors)
theta_deg = 20.0
length_arrow = calc.phasor_3(l1, 0.02)
l1_arrow = calc.phasor_2(l1, theta_deg, length_arrow, 0.2)
l2 = []
l2_colors = []
calc.phasor_append_2(l2, l2_colors, IL, (IR + IL), color_IR)
l2_arrow = calc.phasor_2(l2, theta_deg, length_arrow, 0.2)
fig, ax = plt.subplots()
ax.set_aspect('equal', adjustable='box')
ax.grid()
for i, l_dummy in enumerate(l1_arrow):
for k, t in enumerate(l_dummy):
if (k == 0):
ax.plot(t[0],t[1], color=l_colors[i], label=l1_labels[i])
else:
ax.plot(t[0],t[1], color=l_colors[i])
for i, l_dummy in enumerate(l2_arrow):
for k, t in enumerate(l_dummy):
ax.plot(t[0],t[1], color=l2_colors[i], linestyle='--', dashes=(4, 2))
calc.revise_axis_limits_1(ax, 3.0)
ax.legend(loc='center left', fontsize=11, bbox_to_anchor=(1.05, 0.5))
plt.xlabel('Re (I)', fontsize=11)
plt.ylabel('Im (I)', fontsize=11)
plt.show()
filename: phasor_11_1.dat phasors in rectangular form: IR: ( 2.50, 4.33) IL: ( 6.89, -3.98) Is: ( 9.39, 0.35) Vs: ( 50.00, 86.60) phasors in polar form: IR: magnitude: 5.00, angle: 60.00 deg IL: magnitude: 7.96, angle: -30.00 deg Is: magnitude: 9.40, angle: 2.14 deg Vs: magnitude: 100.00, angle: 60.00 deg
import numpy as np
import gseim_calc as calc
import matplotlib.pyplot as plt
from matplotlib.ticker import (MultipleLocator, AutoMinorLocator)
from setsize import set_size
rad_to_deg = 180.0/np.pi
slv = calc.slv("phasor_11.in")
i_slv = 0
i_out = 1
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)
SR = slv.get_scalar_complex_1(i_slv, i_out, "S_R", u)
SL = slv.get_scalar_complex_1(i_slv, i_out, "S_L", u)
SVs = slv.get_scalar_complex_1(i_slv, i_out, "S_Vs", u)
s_format = "%7.2f"
print('phasors in rectangular form:')
calc.print_complex_rect('SR', SR, s_format)
calc.print_complex_rect('SL', SL, s_format)
calc.print_complex_rect('SVs', SVs, s_format)
print('phasors in polar form:')
calc.print_complex_polar('SR', SR, s_format)
calc.print_complex_polar('SL', SL, s_format)
calc.print_complex_polar('SVs', SVs, s_format)
l_colors = ["blue", "red", "green", "grey", "dodgerblue", "tomato"]
l1 = []
l1_labels = []
color_SR = calc.phasor_append_1a(l1, l1_labels, SR, "$S_R$", l_colors)
color_SL = calc.phasor_append_1a(l1, l1_labels, SL, "$S_L$", l_colors)
color_SVs = calc.phasor_append_1a(l1, l1_labels, SVs, "$S_{Vs}$", l_colors)
theta_deg = 20.0
length_arrow = calc.phasor_3(l1, 0.02)
l1_arrow = calc.phasor_2(l1, theta_deg, length_arrow, 0.2)
l2 = []
l2_colors = []
calc.phasor_append_2(l2, l2_colors, SL, (SL + SR), color_SR)
l2_arrow = calc.phasor_2(l2, theta_deg, length_arrow, 0.2)
fig, ax = plt.subplots()
#ax.set_aspect('equal', adjustable='box')
ax.set_aspect('equal')
ax.grid()
for i, l_dummy in enumerate(l1_arrow):
for k, t in enumerate(l_dummy):
if (k == 0):
ax.plot(t[0],t[1], color=l_colors[i], label=l1_labels[i])
else:
ax.plot(t[0],t[1], color=l_colors[i])
for i, l_dummy in enumerate(l2_arrow):
for k, t in enumerate(l_dummy):
ax.plot(t[0],t[1], color=l2_colors[i], linestyle='--', dashes=(4, 2))
calc.revise_axis_limits_1(ax, 3.0)
ax.legend(loc='center left', fontsize=11, bbox_to_anchor=(1.05, 0.5))
plt.xlabel('Re (S)', fontsize=11)
plt.ylabel('Im (S)', fontsize=11)
plt.show()
filename: phasor_11_2.dat phasors in rectangular form: SR: ( 250.00, -0.00) SL: ( 0.00, 397.89) SVs: ( 250.00, 397.89) phasors in polar form: SR: magnitude: 250.00, angle: -0.00 deg SL: magnitude: 397.89, angle: 90.00 deg SVs: magnitude: 469.91, angle: 57.86 deg
import numpy as np
import matplotlib.pyplot as plt
import gseim_calc as calc
from setsize import set_size
slv = calc.slv("phasor_11.in")
i_slv = 1
i_out = 0
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)
t = u[:, 0]
t_end = t[-1]
i_Vs = slv.get_array_double(i_slv, i_out, 'i_Vs', u)
v_Vs = slv.get_array_double(i_slv, i_out, 'v_Vs', u)
P_Vs = slv.get_array_double(i_slv, i_out, 'P_Vs', u)
l1 = calc.min_max_1(t, P_Vs, 0.0, t_end)
print('min P_Vs:', "%7.2f"%l1[0])
print('max P_Vs:', "%7.2f"%l1[1])
color1='blue'
color2='green'
color3='red'
fig, ax = plt.subplots(3, sharex=False)
plt.subplots_adjust(wspace=0, hspace=0.0)
set_size(5.5, 6.0, ax[0])
for i in range(3):
ax[i].set_xlim(left=0.0, right=t_end*1e3)
ax[i].grid(color='#CCCCCC', linestyle='solid', linewidth=0.5)
ax[0].set_ylabel(r'$V_s$ (V)', fontsize=12)
ax[1].set_ylabel(r'$i_s$ (A)', fontsize=12)
ax[2].set_ylabel(r'$P_s$ (W)', fontsize=12)
for i in range(2):
ax[i].tick_params(labelbottom=False)
ax[0].plot(t*1e3, v_Vs, color=color1, linewidth=1.0, label="$V_s$")
ax[1].plot(t*1e3, i_Vs, color=color2, linewidth=1.0, label="$i_s$")
ax[2].plot(t*1e3, P_Vs, color=color3, linewidth=1.0, label="$P_s$")
ax[2].set_xlabel('time (msec)', fontsize=11)
#plt.tight_layout()
plt.show()
filename: phasor_11_3.dat min P_Vs: -218.72 max P_Vs: 723.72
This notebook was contributed by Prof. Nakul Narayanan K, Govt. Engineering College, Thrissur. He may be contacted at nakul@gectcr.ac.in.