Crate rspice

Crate rspice 

Source
Expand description

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

Modules§

components
A number of provided components.

Structs§

Circuit
Electronic circuit, containing a number of connected basic components.
ComponentRef
Reference to a component in a circuit.
ConnectionRef
Reference to a connection between a component and a net.
EquationRef
Reference to an equation in a linear system.
NetRef
Reference to a net in a circuit.
TransientMatrix
Matrix representing a transient circuit simulation’s linear equation.
TransientResult
The result of running a transient simulation.
TransientVector
Vector representing a transient circuit simulation’s voltages and currents.

Enums§

RspiceError
Generic error type.

Traits§

BasicComponent
Component that directly interacts with the simulator.