Skip to content

Commit

Permalink
Fix analysis of gyrators #513
Browse files Browse the repository at this point in the history
  • Loading branch information
mph- committed Dec 15, 2024
1 parent 68c36f2 commit 0010788
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lcapy/mna.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,14 @@ def __init__(self, cct, solver_method):

# Determine which branch currents are needed.
self.unknown_branch_currents = []
self.extra_branch_currents = []

for elt in self.cct.elements.values():
if elt.need_branch_current:
self.unknown_branch_currents.append(elt.name)
if elt.need_extra_branch_current:
self.unknown_branch_currents.append(elt.name + 'X')
self.extra_branch_currents.append(elt.name + 'X')
if elt.is_current_controlled:
cname = elt.args[0]
if cname not in self.cct.elements:
Expand Down Expand Up @@ -255,8 +257,13 @@ def _solve(self):
# Create dictionary of branch currents through elements
self._Idict = Branchdict()
for m, key in enumerate(self.unknown_branch_currents):
I = current_sign(
results[m + num_nodes], cct.elements[key].is_source)

if key in self.extra_branch_currents:
is_source = False
else:
is_source = cct.elements[key].is_source

I = current_sign(results[m + num_nodes], is_source)
self._Idict[key] = itype(I, **assumptions)

# Calculate the branch currents. These should be lazily
Expand Down
17 changes: 17 additions & 0 deletions lcapy/tests/test_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,3 +927,20 @@ def test_AM(self):

self.assertEqual(cct.AM.I, 2, 'ammeter current')
self.assertEqual(cct.AM.V, 0, 'ammeter voltage')

def test_gyrator(self):

cct = Circuit("""
P1 1 0 ; down, v_=v_1
GY1 4 5 1 0 R; right
R2 4 5; down
W 5 0_2 ; down=0.25
W 0 0_1; down=0.25
W 0_1 0_2; right
""")

self.assertEqual(cct.impedance('P1'), impedance('R**2/R2'),
'gyrator impedance')

self.assertEqual(cct.transfer('P1', 'R2'), transfer('-R2/R'),
'gyrator transfer')

0 comments on commit 0010788

Please sign in to comment.