Phasors

An $RL$ circuit with $R = 10\,\Omega$, $L = 0.01\,$H is connected to a voltage source $V_s(t) = 100\,\cos\,(1000\,t)$. Determine
  1. the angle between the source voltage and current phasors,
  2. active and reactive powers drawn from the source,
  3. the capacitance required to be connected in parallel with the $RL$ load to make the reactive power drawn from the source zero.
(Follow the convention that $\cos\,(\omega \,t)$ corresponds to the phasor $1\,\angle {0}$.)
In [1]:
from IPython.display import Image
Image(filename =r'phasor_3_fig_1.png', width=320)
Out[1]:
No description has been provided for this image
In [2]:
# RL circuit
# run this cell to view the circuit file.
%pycat phasor_3_1_orig.in
Execute the following cell to run GSEIM on phasor_3_1_orig.in.
In [3]:
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("phasor_3_1_orig.in")
os.system('run_gseim phasor_3_1_orig.in')
Circuit: filename = phasor_3_1_orig.in
main: i_solve = 0
GSEIM: Program completed.
Out[3]:
0
In [4]:
import numpy as np
import gseim_calc as calc

rad_to_deg = 180.0/np.pi

slv = calc.slv("phasor_3_1_orig.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)
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('Vs', Vs, s_format)

print('phasors in polar form:')

calc.print_complex_polar('IR', IR, s_format)
calc.print_complex_polar('Vs', Vs, s_format)

phi_IR = np.angle(IR)*rad_to_deg
phi_Vs = np.angle(Vs)*rad_to_deg

print('phi_IR: %6.1f'%phi_IR, 'deg')
print('phi_Vs: %6.1f'%phi_Vs, 'deg')
print('phi_IR-phi_Vs: %6.1f'%(phi_IR-phi_Vs), 'deg')

pf = np.cos(np.angle(Vs)-np.angle(IR))
print('p.f.: %6.3f'%pf)

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

s_format = "%7.2f"

print('power drawn from the source in rectangular form:')
calc.print_complex_rect('SVs', SVs, s_format)

print('power drawn from the source in polar form:')
calc.print_complex_polar('SVs', SVs, s_format)
filename: phasor_3_1_1.dat
phasors in rectangular form:
IR: (   5.00,   -5.00)
Vs: ( 100.00,    0.00)
phasors in polar form:
IR: magnitude:    7.07, angle:  -45.00 deg
Vs: magnitude:  100.00, angle:    0.00 deg
phi_IR:  -45.0 deg
phi_Vs:    0.0 deg
phi_IR-phi_Vs:  -45.0 deg
p.f.:  0.707
filename: phasor_3_1_2.dat
power drawn from the source in rectangular form:
SVs: ( 250.01,  250.00)
power drawn from the source in polar form:
SVs: magnitude:  353.56, angle:   45.00 deg
In [5]:
# circuit with C in parallel with RL
# run this cell to view the circuit file.
%pycat phasor_3_2_orig.in

We now replace the string \$C with the value of our choice by running the python script given below. It takes an existing circuit file phasor_3_2_orig.in and produces a new circuit file phasor_3_2.in, after replacing \$C with the value of our choice.

In [6]:
import gseim_calc as calc
s_C = '25.78e-6' # to be changed by user
l = [
  ('$C', s_C),
]
calc.replace_strings_1("phasor_3_2_orig.in", "phasor_3_2.in", l)
print('phasor_3_2.in is ready for execution')
phasor_3_2.in is ready for execution
Execute the following cell to run GSEIM on phasor_3_2.in.
In [7]:
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("phasor_3_2.in")
os.system('run_gseim phasor_3_2.in')
Circuit: filename = phasor_3_2.in
main: i_solve = 0
GSEIM: Program completed.
Out[7]:
0

The last step (i.e., running GSEIM on phasor_3_2.in) creates data files phasor_3_2_1.dat and phasor_3_2_2.dat in the same directory. We can now use the python code below to compute and display the quantities of interest.

In [8]:
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_3_2.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)
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)

phi_Is = np.angle(Is)*rad_to_deg
phi_Vs = np.angle(Vs)*rad_to_deg

print('phi_Is: %6.1f'%phi_Is, 'deg')
print('phi_Vs: %6.1f'%phi_Vs, 'deg')
print('phi_Is-phi_Vs: %6.1f'%(phi_Is-phi_Vs), 'deg')

pf = np.cos(np.angle(Vs)-np.angle(Is))
print('p.f.: %6.3f'%pf)

s_format = "%7.2f"

print('phasors in rectangular form:')

calc.print_complex_rect('IR', IR, s_format)
calc.print_complex_rect('IC', IC, 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('IC', IC, 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_IC  = calc.phasor_append_1a(l1, l1_labels, IC,  "$I_C$",    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, IR, (IR + IC), color_IC)

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_3_2_1.dat
phi_Is:  -25.8 deg
phi_Vs:    0.0 deg
phi_Is-phi_Vs:  -25.8 deg
p.f.:  0.900
phasors in rectangular form:
IR: (   5.00,   -5.00)
IC: (   0.00,    2.58)
Is: (   5.00,   -2.42)
Vs: ( 100.00,    0.00)
phasors in polar form:
IR: magnitude:    7.07, angle:  -45.00 deg
IC: magnitude:    2.58, angle:   90.00 deg
Is: magnitude:    5.56, angle:  -25.85 deg
Vs: magnitude:  100.00, angle:    0.00 deg
No description has been provided for this image
In [9]:
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_3_2.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)
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)
SL  = slv.get_scalar_complex_1(i_slv, i_out, "S_L",  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('SC',  SC,  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('SC',  SC,  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_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)
color_SL  = calc.phasor_append_1a(l1, l1_labels, SL,  "$S_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, SL, (SL + SR), color_SR)
calc.phasor_append_2(l2, l2_colors, (SL + SR), (SL + SR + SC), color_SC)

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_3_2_2.dat
phasors in rectangular form:
SR: ( 250.01,    0.00)
SL: (   0.00,  250.00)
SC: (   0.00, -128.90)
SVs: ( 250.01,  121.10)
phasors in polar form:
SR: magnitude:  250.01, angle:    0.00 deg
SL: magnitude:  250.00, angle:   90.00 deg
SC: magnitude:  128.90, angle:  -90.00 deg
SVs: magnitude:  277.80, angle:   25.85 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 [ ]: