Skip to main content

Crate sindr

Crate sindr 

Source
Expand description

Rust circuit simulator. SPICE-style MNA solver with built-in semiconductor device models.

sindr solves a Circuit — a list of components and a ground node — and returns voltages, currents, and power for every component. The solver picks the right path automatically:

  • Linear DC — direct solve of the MNA system.
  • Nonlinear DC — Newton–Raphson when diodes, BJTs, MOSFETs, etc. are present.
  • Transient — backward-Euler timestepping when capacitors, inductors, or time-varying sources are present.
  • AC small-signal — sinusoidal-steady-state via ac_analysis::solve_ac.
  • DC sweep — parameter sweep over a component value via dc_sweep.
  • Temperature sweep — operating-point sweep over junction temperature via temperature_sweep.

Device physics (diode, BJT, MOSFET, IGBT, JFET, varactor companion models) live in the companion crate sindr-devices. sindr re-exports the few enums you’ll typically need (BjtKind, MosfetKind, JfetKind, etc.).

§Quick start

Build a voltage divider, solve it, read the divided voltage:

use sindr::{Circuit, CircuitElement, solve_circuit};

let circuit = Circuit {
    ground_node: "0".into(),
    components: vec![
        CircuitElement::VoltageSource {
            id: "V1".into(),
            nodes: ["n1".into(), "0".into()],
            voltage: 10.0,
            waveform: None,
        },
        CircuitElement::Resistor {
            id: "R1".into(),
            nodes: ["n1".into(), "n2".into()],
            resistance: 1_000.0,
        },
        CircuitElement::Resistor {
            id: "R2".into(),
            nodes: ["n2".into(), "0".into()],
            resistance: 2_000.0,
        },
    ],
};

let result = solve_circuit(&circuit).unwrap();

// V_n2 = 10 V * R2/(R1+R2) = 10 * 2/3 ≈ 6.667 V
let v_n2 = result.node_voltages["n2"];
assert!((v_n2 - 6.6667).abs() < 1e-3);

§Conventions

  • Ground node must exist on at least one component. Its voltage is defined as 0 V — every other voltage is reported relative to it.
  • Node names are arbitrary strings ("0", "gnd", "vcc", …). Components share a node simply by referencing the same string.
  • SI units throughout: V, A, Ω, F, H, s, K.
  • Sign conventions are documented per CircuitElement variant.

§Cargo features

  • serde (default)Serialize/Deserialize impls on the public types. Disable for embedded / no-allocator targets.
  • examples — exposes the examples module with built-in named circuits (voltage divider, BJT amp, RC transient, etc.).
[dependencies]
sindr = "0.1"

# No serde:
sindr = { version = "0.1", default-features = false }

§Where to look next

Re-exports§

pub use examples::get_examples;
pub use examples::ExampleCircuit;
pub use circuit::Circuit;
pub use circuit::CircuitElement;
pub use dc_sweep::dc_sweep;
pub use dc_sweep::DcSweepResult;
pub use error::SimError;
pub use mna::MnaSystem;
pub use node_map::NodeMap;
pub use results::BjtResult;
pub use results::ComponentResult;
pub use results::McuResult;
pub use results::MosfetResult;
pub use results::OpAmpResult;
pub use results::RelayResult;
pub use results::SimulationResult;
pub use results::TimestepSnapshot;
pub use results::TransientData;
pub use temp_sweep::temperature_sweep;
pub use temp_sweep::TempSweepPoint;
pub use temp_sweep::TempSweepResult;
pub use validation::validate_circuit;
pub use waveform::Waveform;

Modules§

ac_analysis
AC small-signal analysis module.
circuit
Circuit input format.
dc_sweep
DC parameter sweep module.
error
Error type returned by the solver.
examples
Built-in example circuits.
mna
Modified Nodal Analysis (MNA) matrix system.
newton_raphson
Newton-Raphson nonlinear solver.
node_map
Node-name ↔ matrix-index mapping.
results
Solver output types.
stamp
Component → MNA matrix stamps.
temp_sweep
Temperature sweep analysis.
transient
validation
Pre-solve circuit validation.
waveform
Time-varying waveform definitions for voltage/current sources.

Structs§

IgbtParams
IGBT parameters (simplified model).
VaractorParams
Varactor diode parameters.

Enums§

BjtKind
BJT polarity.
JfetKind
MosfetKind
MOSFET type (NMOS or PMOS).

Functions§

solve_circuit
Solves a circuit end-to-end and returns voltages, currents, and power for every component.
solve_circuit_with_initial_voltages
Like solve_circuit but seeds the Newton–Raphson initial guess with the supplied per-node voltages (V), keyed by node name. Equivalent to SPICE’s .NODESET directive — useful when a circuit has multiple operating points (e.g. Schmitt triggers, latches) or when the default heuristic fails to converge.