Phasors

In the circuit given below, the active power delivered by the source is $5\,$kW, and the apparent power absorbed by the load ($R_2$ and $L$ in parallel) is $(2.5 + j\,2.5)\,$kVAR. The source frequency is $1000\,$rad/s. Find $R_2$, $L$, and $C$.
In [1]:
from IPython.display import Image
Image(filename =r'phasor_9_fig_1.png', width=400)
Out[1]:
No description has been provided for this image
In [2]:
# run this cell to view the circuit file.
%pycat phasor_9_orig.in

We now replace strings such as \$C with the values of our choice by running the python script given below. It takes an existing circuit file phasor_9_orig.in and produces a new circuit file phasor_9.in, after replacing \$C, etc with the values of our choice.

In [3]:
import gseim_calc as calc
s_R2 = '2' # to be changed by user
s_L = '0.5m' # to be changed by user
s_C = '3m' # to be changed by user
l = [
  ('$R2', s_R2),
  ('$L', s_L),
  ('$C', s_C),
]
calc.replace_strings_1("phasor_9_orig.in", "phasor_9.in", l)
print('phasor_9.in is ready for execution')
phasor_9.in is ready for execution
Execute the following cell to run GSEIM on phasor_9.in.
In [4]:
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("phasor_9.in")
os.system('run_gseim phasor_9.in')
Circuit: filename = phasor_9.in
main: i_solve = 0
GSEIM: Program completed.
Out[4]:
0

The circuit file (phasor_9.in) is created in the same directory as that used for launching Jupyter notebook. The last step (i.e., running GSEIM on phasor_9.in) creates data files phasor_9_1.dat, phasor_9_2.dat, and phasor_9_3.dat in the same directory. We can now use the python code below to compute and display the quantities of interest.

In [5]:
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_9.in")

i_slv = 0
i_out = 1
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)

IR1 = slv.get_scalar_complex_1(i_slv, i_out, "IR1_ac", u)
IR2 = slv.get_scalar_complex_1(i_slv, i_out, "IR2_ac", u)
IL  = slv.get_scalar_complex_1(i_slv, i_out, "IL_ac", u)

s_format = "%7.2f"

print('phasors in rectangular form:')

calc.print_complex_rect('IR1', IR1, s_format)
calc.print_complex_rect('IR2', IR2, s_format)
calc.print_complex_rect('IL' , IL,  s_format)

print('phasors in polar form:')

calc.print_complex_polar('IR1', IR1, s_format)
calc.print_complex_polar('IR2', IR2, s_format)
calc.print_complex_polar('IL' , IL,  s_format)

l_colors = ["blue", "red", "green", "grey", "dodgerblue", "tomato"]

l1 = []
l1_labels = []

color_IR1 = calc.phasor_append_1a(l1, l1_labels, IR1, "$I_{R1}$", l_colors)
color_IR2 = calc.phasor_append_1a(l1, l1_labels, IR2, "$I_{R2}$", l_colors)
color_IL  = calc.phasor_append_1a(l1, l1_labels, IL,  "$I_L$",    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, (IR2 + IL), color_IR2)

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_9_2.dat
phasors in rectangular form:
IR1: ( 154.29,  -34.28)
IR2: (  17.14,   34.29)
IL: ( 137.15,  -68.57)
phasors in polar form:
IR1: magnitude:  158.05, angle:  -12.53 deg
IR2: magnitude:   38.33, angle:   63.44 deg
IL: magnitude:  153.33, angle:  -26.56 deg
No description has been provided for this image
In [6]:
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_9.in")

i_slv = 0
i_out = 0
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)

VR1 = slv.get_scalar_complex_1(i_slv, i_out, "VR1_ac", u)
VC  = slv.get_scalar_complex_1(i_slv, i_out, "VC_ac",  u)
VL  = slv.get_scalar_complex_1(i_slv, i_out, "VL_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('VR1', VR1, s_format)
calc.print_complex_rect('VC' , VC,  s_format)
calc.print_complex_rect('VL' , VL,  s_format)
calc.print_complex_rect('Vs' , Vs,  s_format)

print('phasors in polar form:')

calc.print_complex_polar('VR1', VR1, s_format)
calc.print_complex_polar('VC' , VC,  s_format)
calc.print_complex_polar('VL' , VL,  s_format)
calc.print_complex_polar('Vs' , Vs,  s_format)

l_colors = ["blue", "red", "green", "grey", "dodgerblue", "tomato"]

l1 = []
l1_labels = []

color_VR1 = calc.phasor_append_1a(l1, l1_labels, VR1, "$V_{R1}$", l_colors)
color_VC  = calc.phasor_append_1a(l1, l1_labels, VC,  "$V_C$",    l_colors)
color_VL  = calc.phasor_append_1a(l1, l1_labels, VL,  "$V_L$",    l_colors)
color_Vs  = calc.phasor_append_1a(l1, l1_labels, Vs,  "$V_s$",    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, VL, (VC + VL), color_VC)
calc.phasor_append_2(l2, l2_colors, (VC + VL), (VC + VL + VR1), color_VR1)

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 (V)', fontsize=11)
plt.ylabel('Im (V)', fontsize=11)
plt.show()
filename: phasor_9_1.dat
phasors in rectangular form:
VR1: (  77.14,  -17.14)
VC: ( -11.43,  -51.43)
VL: (  34.28,   68.57)
Vs: ( 100.00,    0.00)
phasors in polar form:
VR1: magnitude:   79.03, angle:  -12.53 deg
VC: magnitude:   52.69, angle: -102.53 deg
VL: magnitude:   76.66, angle:   63.44 deg
Vs: magnitude:  100.00, angle:    0.00 deg
No description has been provided for this image
In [7]:
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_9.in")

i_slv = 0
i_out = 2
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)
SR1 = slv.get_scalar_complex_1(i_slv, i_out, "S_R1",  u)
SR2 = slv.get_scalar_complex_1(i_slv, i_out, "S_R2",  u)
SL  = slv.get_scalar_complex_1(i_slv, i_out, "S_L",  u)
SC  = slv.get_scalar_complex_1(i_slv, i_out, "S_C",  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('SR1', SR1, s_format)
calc.print_complex_rect('SR2', SR2, s_format)
calc.print_complex_rect('SL',  SL,  s_format)
calc.print_complex_rect('SC',  SC,  s_format)
calc.print_complex_rect('SVs', SVs, s_format)

print('phasors in polar form:')

calc.print_complex_polar('SR1', SR1, s_format)
calc.print_complex_polar('SR2', SR2, s_format)
calc.print_complex_polar('SL',  SL,  s_format)
calc.print_complex_polar('SC',  SC,  s_format)
calc.print_complex_polar('SVs', SVs, s_format)

l_colors = ["blue", "red", "green", "grey", "dodgerblue", "tomato"]

l1 = []
l1_labels = []

color_SR1 = calc.phasor_append_1a(l1, l1_labels, SR1, "$S_{R1}$", l_colors)
color_SR2 = calc.phasor_append_1a(l1, l1_labels, SR2, "$S_{R2}$", l_colors)
color_SL  = calc.phasor_append_1a(l1, l1_labels, SL,  "$S_L$",    l_colors)
color_SC  = calc.phasor_append_1a(l1, l1_labels, SC,  "$S_C$",    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 + SR2), color_SR2)
calc.phasor_append_2(l2, l2_colors, (SL + SR2), (SL + SR2 + SC), color_SC)
calc.phasor_append_2(l2, l2_colors, (SL + SR2 + SC), (SL + SR2 + SC + SR1), color_SR1)

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 (S)', fontsize=11)
plt.ylabel('Im (S)', fontsize=11)
plt.show()
filename: phasor_9_3.dat
phasors in rectangular form:
SR1: (6245.13,    0.00)
SR2: (1469.36,    0.00)
SL: (   0.00, 5877.61)
SC: (   0.00, -4163.55)
SVs: (7714.49, 1714.06)
phasors in polar form:
SR1: magnitude: 6245.13, angle:    0.00 deg
SR2: magnitude: 1469.36, angle:    0.00 deg
SL: magnitude: 5877.61, angle:   90.00 deg
SC: magnitude: 4163.55, angle:  -90.00 deg
SVs: magnitude: 7902.61, angle:   12.53 deg
No description has been provided for this image

This notebook was contributed by Prof. Nakul Narayanan K, Govt. Engineering College, Thrissur. He may be contacted at nakul@gectcr.ac.in.

In [ ]: