Circuits

>>> from zero import Circuit

What is a ‘circuit’?

A circuit describes a collection of components connected at nodes. It may contain resistors, capacitors, inductors and op-amps, and the circuit can be supplied with an input in order to produce a current through and voltage across these components.

A circuit can be instantiated without arguments:

>>> circuit = Circuit()

You can print the circuit to retrieve a list of its constituents:

>>> print(circuit)
Circuit with 0 components and 0 nodes

Circuits are only useful once you add components. This is achieved using the various add_ methods, such as add_resistor(), add_capacitor(), add_inductor() and add_opamp().

Circuit manipulation

Circuits can be modified before and after applying analyses. Circuit components can be removed with remove_component() or replaced with replace_component().

When a component is removed, any connected nodes shared by other components are preserved.

When a component is replaced with another one, its nodes are copied to the new component and the new component’s nodes are overwritten. The components being swapped must be compatible: the number of nodes in the current and replacement component must be the same, meaning that passive components can only be swapped for other passive components, and op-amps can only be swapped for other op-amps.