SpiceSharpParser is a .NET library that parses SPICE netlists and simulates them using SpiceSharp. It supports a wide subset of PSpice and LTspice syntax including DC, AC, transient, noise, and operating-point analyses.
Install from NuGet:
dotnet add package SpiceSharp-Parser
Or via the NuGet Package Manager:
Install-Package SpiceSharp-Parser
using System;
using System.Linq;
using SpiceSharpParser;
var netlist = string.Join(Environment.NewLine,
"Low-pass RC filter",
"V1 IN 0 AC 1",
"R1 IN OUT 1k",
"C1 OUT 0 1u",
".AC DEC 10 1 1MEG",
".SAVE V(OUT)",
".END");
// Parse
var parser = new SpiceNetlistParser();
var parseResult = parser.ParseNetlist(netlist);
// Translate to SpiceSharp objects
var reader = new SpiceSharpReader();
var spiceModel = reader.Read(parseResult.FinalModel);
// Run simulation
var sim = spiceModel.Simulations.Single();
var export = spiceModel.Exports.Find(e => e.Name == "V(OUT)");
sim.EventExportData += (sender, args) => Console.WriteLine(export.Extract());
sim.Execute(spiceModel.Circuit);Using SpiceSharpParser involves three steps:
- Parse — convert a SPICE netlist string into a parse-tree model with
SpiceNetlistParser.ParseNetlist(). - Read — translate the parse-tree model into SpiceSharp simulation objects (circuit, simulations, exports) with
SpiceSharpReader.Read(). - Simulate — run the SpiceSharp simulations and collect results via exports and events.
SpiceSharpReader.Read() returns a SpiceSharpModel containing:
| Property | Description |
|---|---|
Circuit |
The SpiceSharp Circuit with all components |
Simulations |
List of simulation objects (DC, AC, Transient, etc.) |
Exports |
Signal exports created by .SAVE, .PRINT, .PLOT |
XyPlots |
Plot data from .PLOT statements |
Prints |
Tabular data from .PRINT statements |
Measurements |
Results from .MEAS / .MEASURE statements |
Title |
Netlist title (first line) |
Export data during simulation using the EventExportData event:
var export = spiceModel.Exports.Find(e => e.Name == "V(OUT)");
sim.EventExportData += (sender, args) =>
{
double value = (double)export.Extract();
// process value
};When .STEP is used, the simulation runs multiple times. Each sweep iteration fires EventExportData with appropriate parameter values:
sim.EventExportData += (sender, args) =>
{
Console.WriteLine($"{export.Extract()}");
};SpiceSharpParser supports a comprehensive set of SPICE statements and devices. See the individual documentation articles for details on each:
- Analysis:
.AC,.DC,.TRAN,.OP,.NOISE - Output:
.SAVE,.PRINT,.PLOT,.MEAS - Parameters:
.PARAM,.FUNC,.LET,.SPARAM - Circuit structure:
.SUBCKT,.INCLUDE,.LIB,.GLOBAL - Simulation control:
.STEP,.MC,.TEMP,.OPTIONS,.IC,.NODESET - Behavioral modeling:
VALUE,TABLE,POLY(n),Bsources - Devices: R, L, C, K, D, Q, M, J, V, I, E, F, G, H, B, S, W, T, X