What Is Circuit Simulation?
A circuit simulator solves one question: given a circuit, what are the voltages and currents?
You draw a schematic — resistors, capacitors, transistors, voltage sources connected by wires. The simulator turns that drawing into a system of equations, solves them, and hands you back numbers: the voltage at every node, the current through every branch.
This is what SPICE does. It has been doing it since 1973, when Larry Nagel wrote the original at UC Berkeley. Every chip designed since then — every phone, laptop, car, satellite — was simulated in SPICE or a descendant of it before it was built.
spice-rs is a faithful port of ngspice, the open-source SPICE, rewritten in Rust. This guide will teach you how it works, from the inside out.
The three laws
Everything SPICE computes follows from two conservation laws and one constitutive relationship:
Kirchhoff's Current Law (KCL): The sum of currents entering any node is zero. Current is conserved — what flows in must flow out.
Kirchhoff's Voltage Law (KVL): The sum of voltage drops around any closed loop is zero. Energy is conserved — a charge that travels in a circle returns to the same potential.
Ohm's Law (and its nonlinear generalizations): Each component defines a relationship between the voltage across it and the current through it. For a resistor,
KCL gives us one equation per node. The component equations tell us how to fill in the coefficients. Solve the system, and you have your answer.
From schematic to numbers
Consider the simplest possible circuit: a voltage source and a resistor.
The circuit has two nodes: in and gnd (ground, our reference at 0V). The voltage source forces in says the current leaving through R1 must equal the current supplied by V1:
That's the simulation result. One node voltage, one branch current. For this circuit you don't need a computer — but the method scales to millions of nodes, and SPICE uses the same approach for all of them.
A circuit worth simulating
Now add a second resistor to make a voltage divider. Drag the sliders — the schematic re-renders with updated component values and the simulated
Three nodes: in, mid, gnd. We know
KCL at node mid: current in from R1 equals current out through R2.
Try making R2 much larger than R1:
The next chapter shows how that matrix is built.