Exemple #1
0
    def test_VRL1(self):
        """Lcapy: check VRL circuit

        """
        a = Circuit()
        a.add('V1 1 0 {V1 / s}')
        a.add('R1 1 2')
        a.add('L1 2 0 L1 0')

        # This currently fails due to two symbols of the same name
        # having different assumptions.

        # Note, V1 acts as a short-circuit for the impedance/admittance
        self.assertEqual2(
            a.thevenin(1, 2).Voc, a.Voc(1, 2), "incorrect thevenin voltage")
        self.assertEqual2(
            a.thevenin(1, 2).Z, a.impedance(1, 2),
            "incorrect thevenin impedance")
        self.assertEqual2(
            a.norton(1, 2).Isc, a.Isc(1, 2), "incorrect norton current")
        self.assertEqual2(
            a.norton(1, 2).Y, a.admittance(1, 2),
            "incorrect norton admittance")
        self.assertEqual2(a.impedance(1, 2), (R('R1') | L('L1')).Z,
                          "Z incorrect across R1")
        self.assertEqual2(a.impedance(2, 0), (R('R1') | L('L1')).Z,
                          "Z incorrect across L1")
        self.assertEqual2(a.impedance(1, 0), R(0).Z, "Z incorrect across V1")

        self.assertEqual2(a.admittance(1, 2), (R('R1') | L('L1')).Y,
                          "Y incorrect across R1")
        self.assertEqual2(a.admittance(2, 0), (R('R1') | L('L1')).Y,
                          "Y incorrect across L1")
        # This has a non-invertible A matrix.
        # self.assertEqual2(a.admittance(1, 0), R(0).Y, "Y incorrect across V1")

        self.assertEqual2(a.Voc(1, 0),
                          V('V1' / s).Voc, "Voc incorrect across V1")
        self.assertEqual(a.is_ivp, True, "Initial value problem incorrect")
        self.assertEqual(a.is_dc, False, "DC incorrect")
        self.assertEqual(a.is_ac, False, "AC incorrect")
Exemple #2
0
from lcapy import Vdc, R, L, C
from matplotlib.pyplot import figure, savefig, show
import numpy as np

a = Vdc(10) + R(0.1) + C(0.4) + L(0.2)

a.Isc.pprint()

t = np.linspace(0, 10, 1000)

fig = figure()
ax = fig.add_subplot(111)
ax.plot(t, a.Isc.transient_response(t), linewidth=2)
ax.set_xlabel('Time (s)')
ax.set_ylabel('Current (A)')
ax.grid(True)

show()
Exemple #3
0
S = 310e-4
Bl = 10.0

omegas = 2 * np.pi * fs
Rms = Qms / (omegas * Cms)

Rs = Bl**2 / Rms
Ls = Bl**2 * Cms
Cs = Mms / (Bl**2)

print Rms
print Rs
print Ls
print Cs

a = Series(R(Re) + L(Le)).chain(IdealGyrator(Bl))
b = a.chain(Series(R(Rms) + L(Mms) + C(Cms)))

f = np.logspace(0, np.log10(20e3), 2000)
Zin = b.short_circuit(2).Z.frequency_response(f)

fig = figure()
ax = fig.add_subplot(111)
#ax.semilogx(f, abs(Zin), linewidth=2)
ax.semilogx(f, Zin.real, linewidth=2)
#ax.semilogx(f, Zin.imag, linewidth=2)
ax.set_xlabel('Frequency (Hz)')
ax.set_ylabel('Resistance (ohms)')
ax.grid(True)

fig = figure()
Exemple #4
0
from lcapy import Vdc, R, L, C, I, pprint

L1 = L(10)
L2 = L(20)

print('Series inductors')
L3 = L1 + L2
pprint(L3)
pprint(L3.simplify())
pprint(L3.norton().simplify())


print('Parallel inductors')
L4 = L1 | L2
pprint(L4)
pprint(L4.simplify())
pprint(L4.norton().simplify())


C1 = C(10)
C2 = C(20)

C3 = C1 + C2

print('Series capacitors')
pprint(C3)
pprint(C3.simplify())
pprint(C3.norton().simplify())


C4 = C1 | C2
Exemple #5
0
from lcapy import Vstep, R, L, C, t
from matplotlib.pyplot import savefig
from numpy import linspace

a = Vstep(10) + R(0.1) + C(0.4) + L(0.2, 0)

vt = linspace(0, 10, 1000)
a.Isc(t).plot(vt)

savefig('series-VRLC1-isc.png')
Exemple #6
0
from lcapy import R, C, L
N = (R(1) + ((R(2) + R(3)) | (L(1) + L(2) + L(3)) | (C(6) + C(7) + C(8)))) | (R(4) + R(5))
N.draw(label_values=True)



Exemple #7
0
from lcapy import Vstep, R, L, C
import numpy as np
from matplotlib.pyplot import figure, savefig, show

# This is posed as an initial value problem so cannot
# determine result for t < 0.
a1 = Vstep(5) + L(10, 0)
a2 = a1 | C(1, 5)
b1 = a1 | R(5)
b2 = a2 | R(5)

t = np.linspace(-1, 10, 1000)

fig = figure()
ax = fig.add_subplot(111)
# Open-circuit voltage across R
ax.plot(t, b1.v.evaluate(t), linewidth=2, label='without C')
ax.plot(t, b2.v.evaluate(t), linewidth=2, label='with C')
ax.legend()
ax.set_xlabel('Time (s)')
ax.set_ylabel('Voltage (V)')
ax.grid(True)

fig = figure()
ax = fig.add_subplot(111)
# Short-circuit current through R
ax.plot(t, b1.isc.evaluate(t), linewidth=2, label='without C')
ax.plot(t, b2.isc.evaluate(t), linewidth=2, label='with C')
ax.legend()
ax.set_xlabel('Time (s)')
ax.set_ylabel('Current (A)')
Exemple #8
0
from lcapy import Vdc, R, L, C, LSection, Shunt
import numpy as np
from matplotlib.pyplot import figure, savefig, show

a1 = LSection(L(10), C(1, 5))
b1 = a1.prepend(Shunt(Vdc(5))).load(R(5))

a2 = LSection(L(10), C(1e-10, 5))
b2 = a2.prepend(Shunt(Vdc(5))).load(R(5))

a1 = (Vdc(5) + L(10))
a2 = (Vdc(5) + L(10)) | C(1, 5)
b1 = a1.load(R(5))
b2 = a2.load(R(5))

t = np.linspace(0, 10, 1000)

fig = figure()
ax = fig.add_subplot(111)
# Voltage across R
ax.plot(t, b1.V.impulse_response(t), linewidth=2, label='without C')
ax.plot(t, b2.V.impulse_response(t), linewidth=2, label='with C')
ax.legend()
ax.set_xlabel('Time (s)')
ax.set_ylabel('Voltage (V)')
ax.grid(True)

fig = figure()
ax = fig.add_subplot(111)
# Current through R
ax.plot(t, b1.I.impulse_response(t), linewidth=2, label='without C')
Exemple #9
0
from lcapy import C, L
n = (C('C1') | L('L1')) + (C('C2') | L('L2'))
n.draw(__file__.replace('.py', '.png'))

Exemple #10
0
from lcapy import Vdc, R, L, C
import numpy as np
from matplotlib.pyplot import figure, savefig, show

a1 = (Vdc(5) + L(10))
a2 = (Vdc(5) + L(10)) | C(1, 5)
b1 = a1.load(R(5))
b2 = a2.load(R(5))

t = np.linspace(0, 10, 1000)

fig = figure()
ax = fig.add_subplot(111)
# Voltage across R
ax.plot(t, b1.V.impulse_response(t), linewidth=2, label='without C')
ax.plot(t, b2.V.impulse_response(t), linewidth=2, label='with C')
ax.legend()
ax.set_xlabel('Time (s)')
ax.set_ylabel('Voltage (V)')
ax.grid(True)

fig = figure()
ax = fig.add_subplot(111)
# Current through R
ax.plot(t, b1.I.impulse_response(t), linewidth=2, label='without C')
ax.plot(t, b2.I.impulse_response(t), linewidth=2, label='with C')
ax.legend()
ax.set_xlabel('Time (s)')
ax.set_ylabel('Current (A)')
ax.grid(True)
Exemple #11
0
from lcapy import R, C, L
n = ((R('R1') + L('L1')) + (C('C2') | ((R('R2') + L('L2')) +
                                       (C('C3') | (R('R3') + L('L3'))))))
n.draw(__file__.replace('.py', '.png'), form='ladder')
Exemple #12
0
from lcapy import R, C, L
(((R(1) | C(2)) + L(3) + R(4)) | R(5)).draw('RLC2.png')
Exemple #13
0
from lcapy import R, C, L

((R(1) + L(2)) | C(3)).draw('pickupv.png', form='vertical')
Exemple #14
0
from lcapy import R, L
n = L('L1') | (R('R1') + (L('L2') | (R('R2') + (L('L3') | R('R3')))))
n.draw(__file__.replace('.py', '.png'), layout='ladder')

Exemple #15
0
from lcapy import R, L, C, LSection, pprint, ZPK

C1 = C('C_1')
L1 = L('L_1')
C2 = C('C_2')
L2 = L('L_2')

a = LSection(C1 | L1, C2 | L2)

Av = a.Vtransfer

pprint(Av.canonical())

pprint(Av.ZPK())

pprint(Av.poles())

pprint(Av.zeros())

Exemple #16
0
from lcapy import R, L
n = L(2) + (R(3) | (L(4) + (R(5) | (L(6)))))
n.draw(__file__.replace('.py', '.png'), layout='ladder')

Exemple #17
0
from lcapy import R, C, L

((R(1) + L(2)) | C(3)).smodel().draw('pickup-s.png')
Exemple #18
0
from lcapy import R, L, C, LSection, pprint, ZPK

C1 = C('C_1')
L1 = L('L_1')
R1 = R('R_1')

a = LSection(R1, C1 | L1)

Av = a.Vtransfer

pprint(Av.canonical())

pprint(Av.ZPK())

pprint(Av.poles())

pprint(Av.zeros())

Exemple #19
0
from lcapy import Vdc, R, L, C
import numpy as np
from matplotlib.pyplot import figure, savefig, show

a = (Vdc(5) + L(10)) | R(5)
b = Vdc(5) + L(10) + R(5)

t = np.linspace(0, 10, 1000)

fig = figure()
ax = fig.add_subplot(111)
# Voltage across R
ax.plot(t, a.V.impulse_response(t), linewidth=2)
ax.set_xlabel('Time (s)')
ax.set_ylabel('Voltage (V)')
ax.grid(True)

fig = figure()
ax = fig.add_subplot(111)
# Current through R
ax.plot(t, b.I.impulse_response(t), linewidth=2)
ax.set_xlabel('Time (s)')
ax.set_ylabel('Current (A)')
ax.grid(True)

show()
Exemple #20
0
Cms = 1.0e-3
S = 310e-4
Bl = 10.0

omegas = 2 * np.pi * fs
Rms = Qms / (omegas * Cms)

Rs = Bl**2 / Rms
Ls = Bl**2 * Cms
Cs = Mms / (Bl**2)

print Rms
print Rs
print Ls
print Cs

a = Series(R(Re) + L(Le)).chain(IdealTransformer(1 / Bl))
b = a.chain(Shunt(R(1 / Rms) | C(Mms) | L(Cms)))

f = np.logspace(0, 5, 2000)
Zin = b.open_circuit(2).Z.frequency_response(f)

fig = figure()
ax = fig.add_subplot(111)
ax.semilogx(f, Zin, linewidth=2)
ax.set_xlabel('Frequency (Hz)')
ax.set_ylabel('Impedance (ohms)')
ax.grid(True)

show()
from lcapy import Istep, R, L, C
from matplotlib.pyplot import figure, savefig, show
import numpy as np

a = Istep(10) | R(0.1) | C(0.4) | L(0.2)

a.Voc.pprint()

t = np.linspace(0, 10, 1000)

fig = figure()
ax = fig.add_subplot(111)
ax.plot(t, a.Voc.transient_response(t), linewidth=2)
ax.set_xlabel('Time (s)')
ax.set_ylabel('Voltage (V)')
ax.grid(True)

savefig('parallel-IRLC1-voc.png')

show()


Exemple #22
0
from lcapy import Vdc, R, L, C
from matplotlib.pyplot import figure, savefig, show
import numpy as np

a = R(0.1) + C(0.4) + L(0.2)

a.Z.pprint()

f = np.linspace(0, 1000, 1000)

fig = figure()
ax = fig.add_subplot(111)
ax.plot(f, abs(a.Z.frequency_response(f)), linewidth=2)
ax.set_xlabel('Frequency (Hz)')
ax.set_ylabel('Impedance (ohms)')
ax.grid(True)


show()
Exemple #23
0
from lcapy import R, L
n = (R('R1') | L('L1')) + (R('R2') | L('L2'))
n.draw(__file__.replace('.py', '.png'))

Exemple #24
0
from lcapy import R, C, L

n = C('C1') | ((R('R1') + L('L1')) + (C('C2') | ((R('R2') + L('L2')) +
                                                 (C('C3') |
                                                  (R('R3') + L('L3'))))))
n.draw(__file__.replace('.py', '.png'), layout='ladder')
Exemple #25
0
from lcapy import R, C, L
n = C('C1') | ((R('R1') + L('L1')) + (C('C2') | ((R('R2') + L('L2')) + (C('C3') | (R('R3') + L('L3')) + C('C4')))))
n.draw(__file__.replace('.py', '.png'), layout='ladder')

Exemple #26
0
from lcapy import Vstep, R, L, C
import numpy as np
from matplotlib.pyplot import figure, savefig, show

a = (Vstep(5) + L(10)) | R(5)
b = Vstep(5) + L(10) + R(5)

t = np.linspace(-1, 10, 1000)

fig = figure()
ax = fig.add_subplot(111)
# Open-circuit voltage across R
ax.plot(t, a.v.evaluate(t), linewidth=2)
ax.set_xlabel('Time (s)')
ax.set_ylabel('Voltage (V)')
ax.grid(True)

fig = figure()
ax = fig.add_subplot(111)
# Short-circuit current through R
ax.plot(t, b.isc.evaluate(t), linewidth=2)
ax.set_xlabel('Time (s)')
ax.set_ylabel('Short-circuit current (A)')
ax.grid(True)

show()
Exemple #27
0
from lcapy import C, L
n = (C('C1') + L('L1')) | (C('C2') + L('L2'))
n.draw(__file__.replace('.py', '.png'))

Exemple #28
0
from lcapy import Vdc, R, L, C
from matplotlib.pyplot import figure, savefig, show
import numpy as np

a = R(10) + C(1e-4) + L(1e-3)

a.Z.canonical().pprint()
a.Z.ZPK().pprint()

f = np.logspace(0, 5, 1000)

fig = figure()
ax = fig.add_subplot(111)
ax.loglog(f, abs(a.Z.frequency_response(f)), linewidth=2)
ax.set_xlabel('Frequency (Hz)')
ax.set_ylabel('Impedance (ohms)')
ax.grid(True)

show()

b = R('R') + C('C') + L('L')

b.Z.canonical().pprint()
b.Z.ZPK().pprint()
Exemple #29
0
from lcapy import Vstep, R, L, C
import numpy as np
from matplotlib.pyplot import figure, savefig, show

a = Vstep(5) + L(10)
b = a | R(5)

t = np.linspace(-1, 10, 1000)

fig = figure()
ax = fig.add_subplot(111)
# Open-circuit voltage across R
ax.plot(t, b.v.evaluate(t), linewidth=2)
ax.set_xlabel('Time (s)')
ax.set_ylabel('Voltage (V)')
ax.grid(True)

fig = figure()
ax = fig.add_subplot(111)
# Short-circuit current through R
ax.plot(t, b.isc.evaluate(t), linewidth=2)
ax.set_xlabel('Time (s)')
ax.set_ylabel('Current (A)')
ax.grid(True)

show()
Exemple #30
0
from lcapy import R, L
n = L(2) | (R(3) + (L(4) | (R(5) + (L(6)))))
n.draw(__file__.replace('.py', '.png'), form='ladder')