CircuitS Functions

Following is a list of all provided CircuitS functions.

Creating a circuit

create_circuitFunction
circuit = create_circuit()

Creates and returns an empty circuit object.

add_elementFunction
add_element(elem::Vector, circuit::Circuit)

Adds an element to the circuit.

Arguments

  • elem::Vector: Element to be added. Elements are given in specific formats:
    • [type, id, a, b]
    • [type, id, a, b, IC]
    • [type, id, [a1,a2], b]
    • [type, id, [a1,a2], [b1,b2]]
    • [type, id, [a1,a2], [b1,b2], IC]
    Details of each element are found in the docs.
  • circuit::Circuit: the circuit object to which the element will be added to

Examples

add_element([Resistor, "R1", 1, 0], circuit)
add_element([Voltage, "V1", 1, 0], circuit)
remove_elementFunction
remove_element(elem::String, circuit::Circuit)

Removes an element with given id elem from the circuit.

For a full list of supported elements go to Elements section.

Getters

get_equationsFunction
get_equations(circuit::Circuit)

Returns a list of MNA equations with applied replacements.

Arguments

  • circuit::Circuit: Initialized circuit

Returns

result::Vector: A list of all equations

Examples

result = get_equations(circuit);
get_variablesFunction
get_variables(circuit::Circuit)

Returns a list of MNA variables - symbols for node potentials and some currents.

Arguments

  • circuit::Circuit: Initialized circuit

Returns

result::Vector: A list of all variables

Examples

result = get_variables(circuit);

Simulation

Before every simulation, a circuit has to be initialized in order to create MNA equations and make the necessary replacements.

init_circuitFunction
init_circuit(circuit::Circuit, replacements::Dict, omega::String="")

Prepares the circuit for simulation. Circuits have to be initialized before the simulation every time a new element is added.

Arguments

  • circuit::Circuit: A circuit to be initialized
  • replacements::Dict: Dictionary of replacements in the circuit, given in format: Dict([ R1 => R, R2 => R, ...])
    • R1, R2 and R are symbols
  • omega::String: A replacement for s=j*omega
Note

If given, omega has to be a single symbol, given as a string. It can be replaced by a complex term in replacements::Dict.

Examples

@variables R1, R2, R
init_circuit(circuit, Dict([ R1 => R, R2 => R]);
simulateFunction
simulate(circuit::Circuit, simpl::Bool = true)

Simulates the circuit by calculating node potentials and some currents (MNA).

Arguments

  • circuit::Circuit: A circuit to be simulated
  • simpl::Bool = true: Flag indicating whether to simplify the resulting equations

Returns

result::Dict: A dictionary of all calculated potentials and currents

Examples

result = simulate(circuit);
Limitations

Due to limitations of simplify function in JuliaSymbolics, some more complex circuits will fail to simulate and throw Assertation Error. This can be avoided by passing false as a second argument to simulate function, but then the resulting equations may be impossible to read.

Simplify and solve_for functions are also relatively slower than those similar in other languages. It is not uncommon for these functions to take minutes to finish.

These limitations will be illustrated through examples in the following sections.