Skip to content

Electrical

Electrical realizations shared by the engineering packages.

They are circuit components that join the nodes of a circuit.

BranchInteraction(label, *, a, b)

Bases: Interaction

Component between the nodes a and b whose current flows from a to b.

Every node holds its potential v, and the currents of the components that join a node add into its balance, which is zero, as Kirchhoff's current law says. A subclass returns its current from _get_current, or its own laws from _get_branch_laws when the current is a value of its own. A resistor, a diode, and a source in a circuit are such components, as a pipe between two tanks or a road between two towns would be.

Parameters:

Name Type Description Default
label str

The label of the interaction, unique among the components of its system.

required
a Role

The path of the node the current leaves.

required
b Role

The path of the node the current enters.

required

Examples:

>>> from skcomplex.systems.engineering.common.electrical import ResistorInteraction
>>> ResistorInteraction('load', a='top', b='bottom', R=2.0).b
'bottom'
Source code in src/skcomplex/systems/engineering/common/electrical/_components.py
48
49
50
51
def __init__(self, label: str, *, a: Role, b: Role) -> None:
    super().__init__(label)
    self.a = a
    self.b = b

CapacitorInteraction(label, *, a, b, branch, C=1.0)

Bases: BranchInteraction

Capacitor whose voltage u and current i live on the element branch.

It has C u' = i and u = a.v - b.v.

Parameters:

Name Type Description Default
label str

The label of the interaction, unique among the components of its system.

required
a Role

The path of the node the current leaves.

required
b Role

The path of the node the current enters.

required
branch Role

The path of the element that holds the voltage u and the current i of the capacitor.

required
C Annotated[float, POSITIVE]

The capacitance.

1.0

Examples:

>>> from skcomplex.core.components.elements import Element
>>> from skcomplex.core.systems import System
>>> from skcomplex.systems.engineering.common.electrical import (
...     CapacitorInteraction,
...     GroundInteraction,
...     ResistorInteraction,
... )
>>> nodes = [Element(name, values={'v': 0.0}) for name in ('top', 'bottom')]
>>> branches = [Element('tank', values={'u': 1.0, 'i': 0.0}), Element('earth', values={'i': 0.0})]
>>> interactions = [
...     CapacitorInteraction('capacitor', a='top', b='bottom', branch='tank', C=0.5),
...     ResistorInteraction('load', a='top', b='bottom', R=2.0),
...     GroundInteraction('ground', node='bottom', branch='earth'),
... ]
>>> system = System(elements=nodes + branches, interactions=interactions).prepare()
>>> round(float(system.simulate(until=1.0, dt=1.0).get_values('tank.u')[-1]), 4)
0.3679
Source code in src/skcomplex/systems/engineering/common/electrical/_components.py
147
148
149
150
151
152
153
154
155
156
157
158
def __init__(
    self,
    label: str,
    *,
    a: Role,
    b: Role,
    branch: Role,
    C: Annotated[float, POSITIVE] = 1.0,
) -> None:
    super().__init__(label, a=a, b=b)
    self.branch = branch
    self.C = C

ChuaDiodeInteraction(label, *, a, b, m0=-8 / 7, m1=-5 / 7)

Bases: BranchInteraction

Nonlinear resistor of Chua's circuit.

At the voltage u = a.v - b.v it has the current m1 u + (m0 - m1) (|u + 1| - |u - 1|) / 2.

Parameters:

Name Type Description Default
label str

The label of the interaction, unique among the components of its system.

required
a Role

The path of the node the current leaves.

required
b Role

The path of the node the current enters.

required
m0 float

The slope of the characteristic inside the breakpoints.

-8 / 7
m1 float

The slope of the characteristic outside the breakpoints.

-5 / 7

Examples:

>>> from skcomplex.systems.engineering.common.electrical import ChuaDiodeInteraction
>>> round(ChuaDiodeInteraction('diode', a='top', b='bottom').m0, 3)
-1.143
Source code in src/skcomplex/systems/engineering/common/electrical/_components.py
407
408
409
410
def __init__(self, label: str, *, a: Role, b: Role, m0: float = -8 / 7, m1: float = -5 / 7) -> None:
    super().__init__(label, a=a, b=b)
    self.m0 = m0
    self.m1 = m1

CurrentSourceInteraction(label, *, a, b, current=1.0)

Bases: BranchInteraction

Ideal source that drives the constant current current from b through the source to a.

Parameters:

Name Type Description Default
label str

The label of the interaction, unique among the components of its system.

required
a Role

The path of the node the source drives the current into.

required
b Role

The path of the node the source draws the current from.

required
current float

The current the source drives into a.

1.0

Examples:

>>> from skcomplex.systems.engineering.common.electrical import CurrentSourceInteraction
>>> CurrentSourceInteraction('source', a='top', b='bottom', current=0.5).current
0.5
Source code in src/skcomplex/systems/engineering/common/electrical/_components.py
283
284
285
def __init__(self, label: str, *, a: Role, b: Role, current: float = 1.0) -> None:
    super().__init__(label, a=a, b=b)
    self.current = current

DiodeInteraction(label, *, a, b, Is=1e-06, Vt=0.025)

Bases: BranchInteraction

Exponential diode, with the current Is (exp((a.v - b.v) / Vt) - 1).

Parameters:

Name Type Description Default
label str

The label of the interaction, unique among the components of its system.

required
a Role

The path of the anode.

required
b Role

The path of the cathode.

required
Is Annotated[float, POSITIVE]

The saturation current.

1e-06
Vt Annotated[float, POSITIVE]

The thermal voltage.

0.025

Examples:

>>> from skcomplex.systems.engineering.common.electrical import DiodeInteraction
>>> DiodeInteraction('diode', a='anode', b='cathode').Vt
0.025
Source code in src/skcomplex/systems/engineering/common/electrical/_components.py
361
362
363
364
365
366
367
368
369
370
371
372
def __init__(
    self,
    label: str,
    *,
    a: Role,
    b: Role,
    Is: Annotated[float, POSITIVE] = 1e-6,
    Vt: Annotated[float, POSITIVE] = 0.025,
) -> None:
    super().__init__(label, a=a, b=b)
    self.Is = Is
    self.Vt = Vt

GroundInteraction(label, *, node, branch)

Bases: Interaction

Reference that holds the potential of a node at zero.

The current that the ground feeds into the node, i of the element branch, balances the node.

Parameters:

Name Type Description Default
label str

The label of the interaction, unique among the components of its system.

required
node Role

The path of the node held at zero potential.

required
branch Role

The path of the element that holds the current i from the ground into the node.

required

Examples:

>>> from skcomplex.systems.engineering.common.electrical import GroundInteraction
>>> GroundInteraction('ground', node='bottom', branch='earth').node
'bottom'
Source code in src/skcomplex/systems/engineering/common/electrical/_components.py
316
317
318
319
def __init__(self, label: str, *, node: Role, branch: Role) -> None:
    super().__init__(label)
    self.node = node
    self.branch = branch

InductorInteraction(label, *, a, b, branch, L=1.0)

Bases: BranchInteraction

Inductor whose current i lives on the element branch, with L i' = a.v - b.v.

Parameters:

Name Type Description Default
label str

The label of the interaction, unique among the components of its system.

required
a Role

The path of the node the current leaves.

required
b Role

The path of the node the current enters.

required
branch Role

The path of the element that holds the current i of the inductor.

required
L Annotated[float, POSITIVE]

The inductance.

1.0

Examples:

>>> from skcomplex.systems.engineering.common.electrical import InductorInteraction
>>> InductorInteraction('coil', a='top', b='bottom', branch='coil', L=0.5).L
0.5
Source code in src/skcomplex/systems/engineering/common/electrical/_components.py
196
197
198
199
200
201
202
203
204
205
206
207
def __init__(
    self,
    label: str,
    *,
    a: Role,
    b: Role,
    branch: Role,
    L: Annotated[float, POSITIVE] = 1.0,
) -> None:
    super().__init__(label, a=a, b=b)
    self.branch = branch
    self.L = L

OperationalAmplifierInteraction(label, *, p, n, out, branch)

Bases: Interaction

Ideal operational amplifier.

Its inputs p and n draw no current, and its output drives the node out with the current i of the element branch that holds both inputs at equal potentials. The output current returns through the supply of the amplifier, so no balance takes it back.

Parameters:

Name Type Description Default
label str

The label of the interaction, unique among the components of its system.

required
p Role

The path of the noninverting input node.

required
n Role

The path of the inverting input node.

required
out Role

The path of the output node.

required
branch Role

The path of the element that holds the output current i.

required

Examples:

>>> from skcomplex.systems.engineering.common.electrical import OperationalAmplifierInteraction
>>> OperationalAmplifierInteraction('amplifier', p='ground', n='sum', out='output', branch='drive').out
'output'
Source code in src/skcomplex/systems/engineering/common/electrical/_components.py
450
451
452
453
454
455
def __init__(self, label: str, *, p: Role, n: Role, out: Role, branch: Role) -> None:
    super().__init__(label)
    self.p = p
    self.n = n
    self.out = out
    self.branch = branch

ResistorInteraction(label, *, a, b, R=1.0)

Bases: BranchInteraction

Resistor that obeys Ohm's law, with the current (a.v - b.v) / R.

Parameters:

Name Type Description Default
label str

The label of the interaction, unique among the components of its system.

required
a Role

The path of the node the current leaves.

required
b Role

The path of the node the current enters.

required
R Annotated[float, POSITIVE]

The resistance.

1.0

Examples:

>>> from skcomplex.systems.engineering.common.electrical import ResistorInteraction
>>> ResistorInteraction('load', a='top', b='bottom', R=2.0).R
2.0
Source code in src/skcomplex/systems/engineering/common/electrical/_components.py
96
97
98
def __init__(self, label: str, *, a: Role, b: Role, R: Annotated[float, POSITIVE] = 1.0) -> None:
    super().__init__(label, a=a, b=b)
    self.R = R

VoltageSourceInteraction(label, *, a, b, branch, V=1.0)

Bases: BranchInteraction

Ideal source that holds the node a at the voltage V above the node b.

Its current i, from a through the source to b, lives on the element branch.

Parameters:

Name Type Description Default
label str

The label of the interaction, unique among the components of its system.

required
a Role

The path of the positive node.

required
b Role

The path of the negative node.

required
branch Role

The path of the element that holds the current i of the source.

required
V float

The voltage.

1.0

Examples:

>>> from skcomplex.systems.engineering.common.electrical import VoltageSourceInteraction
>>> VoltageSourceInteraction('battery', a='plus', b='minus', branch='cell', V=9.0).V
9.0
Source code in src/skcomplex/systems/engineering/common/electrical/_components.py
246
247
248
249
def __init__(self, label: str, *, a: Role, b: Role, branch: Role, V: float = 1.0) -> None:
    super().__init__(label, a=a, b=b)
    self.branch = branch
    self.V = V