openmaterials.ai / codes / ngspice

ngspice: SPICE circuit simulation with mixed-signal and device-level extensions

The open-source successor of Berkeley Spice3f5, merged with the XSPICE code models and the CIDER device simulator, that solves DC, AC and transient analyses of a netlist.

What it is and how it works

Kirchhoff's laws, solved per time step

ngspice solves analog nodes iteratively from Kirchhoff's laws with a sparse matrix at each time point. Digital nodes propagate events in the same executable, a native mixed-mode simulator (ngspice manual 47).

Seven analyses

DC operating point and sweep (.op, .dc), AC small-signal (.ac), transient (.tran), pole-zero, small-signal distortion, sensitivity and noise (ngspice manual 47).

Device models

Gummel-Poon bipolar models including VBIC, diodes, JFET and JFET2, the six original MOSFET levels, BSIM3, BSIM4, BSIMSOI, plus Verilog-A via OpenVAF (ngspice manual 47).

XSPICE code models

Code model instances start with A and take a .MODEL card (ngspice manual 47). Over 60 functional blocks and a 12-state digital type (ngspice XSPICE page).

Two matrix solvers

Sparse 1.3 is the default and is required for noise and CIDER. option klu selects KLU for large MOS circuits with thousands of transistors (ngspice manual 47).

Shared library

Built as .so or .dll, ngspice takes a netlist from a host program, runs in its own thread and calls back at each time point. KiCad uses it (ngspice shared page).

By the numbers

How it is used

  1. Write the netlist

    Title line, element cards (R, C, M, X), .model cards, analysis lines such as .op or .tran.

  2. Load extra models

    osdi model.osdi for OpenVAF-compiled Verilog-A. spinit loads the .cm code model libraries.

  3. Run

    ngspice netlist.cir, or with -b for batch mode, or from a host via the shared library.

  4. Read results

    print, plot and wrdata write the vectors. option numdgt sets the significant digits.