Skip to content

Commit

Permalink
Check if circuit has twoport for loop and nodal analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
mph- committed Dec 26, 2024
1 parent 0285066 commit bf264b8
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 7 deletions.
11 changes: 9 additions & 2 deletions doc/circuits.rst
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,9 @@ of an ideal resistor and a noise voltage source using the
Mesh analysis
-------------

Lcapy can output the mesh equations by applying Kirchhoff's voltage
law around each loop in a circuit. For example, consider the netlist:
Lcapy can output the mesh equations for a planar circuit by applying
Kirchhoff's voltage law around each loop in the circuit. For example,
consider the netlist:

>>> cct = Circuit("""
...V1 1 0; down
Expand Down Expand Up @@ -323,6 +324,10 @@ The mesh currents can be found with the `solve_laplace()` method.
This solves the circuit using Laplace transform methods and returns a
dictionary of results.

The mesh analysis implementation does not support twoport components,
such as transformers and gyrators.


.. _nodal-analysis:

Nodal analysis
Expand Down Expand Up @@ -433,6 +438,8 @@ The node voltages can be found with the `solve_laplace()` method.
This solves the circuit using Laplace transform methods and returns a
dictionary of results.

The nodal analysis implementation does not support twoport components,
such as transformers and gyrators. Instead use modified nodal analysis.

.. _modified-nodal-analysis:

Expand Down
2 changes: 1 addition & 1 deletion lcapy/analysis.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
This module collects information about a circuit.
Copyright 2022--203 Michael Hayes, UCECE
Copyright 2022--2024 Michael Hayes, UCECE
"""

Expand Down
5 changes: 5 additions & 0 deletions lcapy/circuitgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ class CircuitGraph(object):
@classmethod
def from_circuit(cls, cct):

if cct.twoports != []:
raise ValueError('Cannot create CircuitGraph with twoport components: ' + ', '.join(cct.twoports))
# Perhaps could split twoports into an input oneport and an
# output oneport?

G = nx.Graph()

dummy = 0
Expand Down
7 changes: 7 additions & 0 deletions lcapy/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def __init__(self, cct):
self.open_circuits = []
self.ports = []
self.transformers = []
self.twoports = []
self.voltage_sources = []
self.wires = []

Expand All @@ -44,6 +45,12 @@ def __init__(self, cct):
elif elt.is_wire:
self.wires.append(eltname)

# Note, this includes all twoport components (TP, TF, GY,
# etc) and not just TP.
if elt.is_twoport:
self.twoports.append(eltname)


def __repr__(self):

return str(vars(self))
11 changes: 10 additions & 1 deletion lcapy/loopanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

class LoopAnalysis(object):
"""This performs for loop analysis. Currently, it uses mesh analysis
and so is only applicable to circuits with a planar topology.
and so is only applicable to circuits with a planar topology and
without twoport components.
The API is likely to change since different invocations find
different current loops.
Expand Down Expand Up @@ -51,6 +52,14 @@ class LoopAnalysis(object):
"""

# twoport components could be handled by splitting into
# input and output oneports. In the case of an ideal transformer,
# an unknown voltage across the primary could be added to the mesh
# equations. The voltage across the secondary is the primary voltage
# multiplied by N2 / N1. An auxiliary equation is required
# relating the mesh currents in the primary and secondary loops:
# ib = -N1 / N2 ia.

@classmethod
def from_circuit(cls, cct):

Expand Down
4 changes: 2 additions & 2 deletions lcapy/mnacpts.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,14 +610,14 @@ def is_capacitor(self):

@property
def is_oneport(self):
"""Return True if component is a oneport."""
"""Return True if component is any oneport (R, C, L, V, I, etc.)."""

from .oneport import OnePort
return isinstance(self.cpt, OnePort)

@property
def is_twoport(self):
"""Return True if component is a twoport."""
"""Return True if component is any twoport (TP, TF, GY, etc.)."""

from .twoport import TwoPort
return isinstance(self.cpt, TwoPort)
Expand Down
16 changes: 15 additions & 1 deletion lcapy/netlistmixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,18 @@ def analysis(self):
@cached_property
def branch_list(self):
"""Determine list of names of branch elements, e.g.,
['C1', 'V1', 'R1', 'R2']."""
['C1', 'V1', 'R1', 'R2'].
Two-port components (TF, GY, TP) are ignored. Perhaps
they could be split into input and output one-ports?
"""

branch_list = []
for key, elt in self.elements.items():
if elt.is_twoport:
warn('Ignoring twoport component ' + key)
continue

if elt.type not in ('W', 'O', 'P', 'K', 'XX'):
branch_list.append(elt.name)
return branch_list
Expand Down Expand Up @@ -418,6 +426,12 @@ def transformers(self):

return self.components.transformers

@property
def twoports(self):
"""Return list of twoports."""

return self.components.twoports

@property
def voltage_sources(self):
"""Return list of voltage_sources."""
Expand Down

0 comments on commit bf264b8

Please sign in to comment.