1 unstable release

Uses new Rust 2024

0.1.0 Oct 11, 2025

#204 in Simulation

AGPL-3.0-only

35KB
663 lines

rspice

Pure-Rust circuit simulation backend.

Status

See CHANGELOG.md for more information.

Done

  • Passive components.
  • Transient simulation.

To Do

  • Active components.
  • Non-linear components.
  • Other simulation modes.

Using the API

See the documentation.


lib.rs:

rspice is a pure-Rust circuit simulation backend.

Creating circuits

use rspice::Circuit;
use rspice::components::{Resistor, VoltageSource, Ground};

let mut circuit = Circuit::new();
// nets are wires connecting possibly multiple components
let top_wire = circuit.createNet();
let bottom_wire = circuit.createNet();
// components are created and connected like this
let R1 = Resistor::create(&mut circuit, top_wire, bottom_wire, 100.0);
VoltageSource::create(&mut circuit, top_wire, bottom_wire, 5.0);
// we use a ground to set a voltage reference
// since the simulation will fail otherwise
Ground::create(&mut circuit, bottom_wire);

Simulating circuits

The following simulation types are supported:

  • Transient: the circuit is simulated over time, step by step.

Transient analysis


// ...

// takes total duration and step size as arguments;
// make sure steps are short enough to capture
// any relevant frequencies in the circuit
let result = circuit.performTransientAnalysis(1.0, 1.0e-3).unwrap();
let time = 0.4;
assert_eq!(5.0, result.voltage_at(top_wire, time));
assert_eq!(0.0, result.voltage_at(bottom_wire, time));
// currents are measured at each connection, from component to net
assert_eq!(-5.0/100.0, result.current_at(&R1, 0, time)); // top_wire -> R1
assert_eq!(5.0/100.0, result.current_at(&R1, 1, time)); // R1 -> bottom_wire

Dependencies

~68KB