Python Library

If you want to manipulate the solutions for a circuit, instead of only printing the results, you might be interested in using the library provided in this package.

Circuit Class

class rtds_circuit_analysis.Circuit(netlist: str, time_step: str | None = None)

Class that represents a circuit and all its data.

Parameters:
  • netlist (str) – The netlist for the circuit. It can be either the path for a file containing the netlist, or the netlist itself directly as a string.

  • time_step (str, optional) – Value for the time step, used in the difference state equations. It is recommended to pass it in exponential form (ex.: "2.5e-6") Needs to be a string, passing it as a float may cause issues. Defaults to None.

components

List of components for the circuit.

Type:

list[Component]

currents

Dictionary that relates each component name to its currents. Does not include trivial components, which are current sources and inductors.

Type:

dict[str, sympy.Expr]

component_voltages

Dictionary that relates each component name to its voltages. Does not include trivial components, which are voltage sources and capacitors.

Type:

dict[str, sympy.Expr]

node_voltages

Dictionary that relates each node name to its voltages.

Type:

dict[str, sympy.Expr]

states

Dictionary that relates each energy storage component to its continuous state equation. It only includes the right hand side of the equation!

Type:

dict[str, sympy.Expr]

forward

Dictionary that relates each energy storage component to its discrete state equation, using the forward method. It only includes the right hand side of the equation!

Type:

dict[str, sympy.Expr]

backward

Dictionary that relates each energy storage component to its discrete state equation, using the backward method. It only includes the right hand side of the equation!

Type:

dict[str, sympy.Expr]

trapezoidal

Dictionary that relates each energy storage component to its discrete state equation, using the trapezoidal method. It only includes the right hand side of the equation!

Type:

dict[str, sympy.Expr]

time_step

The time step for the circuit.

Type:

sympy.Rational | None

print_all()

Prints all the info related to the circuit object.

print_backward(*components: Component)

Prints the state equations for the system (backward).

Parameters:

*components – List of components to get the state equations for. If empty, prints all the state equations for the circuit.

print_component_voltages(*components: Component)

Prints the voltage for the given components (excluding capacitors and voltage sources, which are obvious). If no components are given, prints the voltages for every component.

Parameters:

*components – List of components to get the voltages for. If empty, prints the voltage for every component.

print_components()

Print all components for the circuit

print_currents(*components: Component)

Prints the current for the given components (excluding inductors and current sources, which are obvious). If no components are given, prints the currents for every component.

Parameters:

*components – List of components to get the current for. If empty, prints the currents for every component.

print_forward(*components: Component)

Prints the state equations for the system (forward).

Parameters:

*components – List of components to get the state equations for. If empty, prints all the state equations for the circuit.

print_node_voltages(*nodes: str)

Prints the voltage for each node. If no nodes are given, prints the voltages for every node.

Parameters:

*nodes – List of nodes to get the voltages for. If empty, prints the voltage for every node.

print_states(*components: Component)

Prints the state equations for the system (continuous).

Parameters:

*components – List of components to get the state equations for. If empty, prints all the state equations for the circuit.

print_trapezoidal(*components: Component)

Prints the state equations for the system (trapezoidal).

Parameters:

*components – List of components to get the state equations for. If empty, prints all the state equations for the circuit.

Component Class

class rtds_circuit_analysis.parse_netlist.Component(name: str, nodes: tuple[str], value: Rational | Symbol)

Represents a component in a circuit. Mostly for internal use, although you can use it to extract the voltage and current directly from a component.

name

The name of the component.

Type:

str

type

What type the component is (“V” for voltage sources, “R” for resistors, etc)

Type:

str

nodes

The two nodes the component is connected to, in order

Type:

tuple[str]

value

The value for the component (Volts for voltage sources, Ohms for resistors, etc)

Type:

sympy.Rational | sympy.Symbol

current

The current calculated for the component

voltage

The voltage calculated for the component