SpiceSharpParser is a .NET library that allows to parse SPICE netlists and to simulate them using SpiceSharp.
SpiceSharpParser is available as NuGet Package.
Parsing a netlist and executing a simulation is relatively straightforward. For example:
using System;
using System.Linq;
using SpiceSharpParser;
namespace SpiceSharpParserExample
{
class Program
{
static void Main(string[] programArgs)
{
var netlistText = string.Join(Environment.NewLine,
"Diode circuit",
"D1 OUT 0 1N914",
"V1 OUT 0 0",
".model 1N914 D(Is=2.52e-9 Rs=0.568 N=1.752 Cjo=4e-12 M=0.4 tt=20e-9)",
".DC V1 -1 1 10e-3",
".SAVE i(V1)",
".END");
// Parsing part
var parser = new SpiceNetlistParser();
var parseResult = parser.ParseNetlist(netlistText);
var netlist = parseResult.FinalModel;
// Translating netlist model to SpiceSharp
var reader = new SpiceSharpReader();
var spiceSharpModel = reader.Read(netlist);
// Simulation using SpiceSharp
var simulation = spiceSharpModel.Simulations.Single();
var export = spiceSharpModel.Exports.Find(e => e.Name == "i(V1)");
simulation.EventExportData += (sender, args) => Console.WriteLine(export.Extract());
var codes = simulation.Run(spiceSharpModel.Circuit, -1);
codes = simulation.InvokeEvents(codes);
codes.ToArray(); //eval
}
}
}
SpiceSharpParser is able to parse some of PSpice netlists. At the moment due to lack of implementation of LAPLACE and FREQ (part of analog behavioral modeling) and other features parsing or simulation can fail.
- POLY(n)
- TABLE
- VALUE
Statement | Documentation |
---|---|
.AC | Wiki |
.APPENDMODEL | Wiki |
.DC | Wiki |
.DISTRIBUTION | Wiki |
.ELSE | Wiki |
.ENDIF | Wiki |
.FUNC | Wiki |
.GLOBAL | Wiki |
.IC | Wiki |
.IF | Wiki |
.INCLUDE | Wiki |
.LET | Wiki |
.LIB | Wiki |
.MC | Wiki |
.NODESET | Wiki |
.NOISE | Wiki |
.OP | Wiki |
.OPTIONS | Wiki |
.PARAM | Wiki |
.PLOT | Wiki |
Wiki | |
.TRAN | Wiki |
.SAVE | Wiki |
.SPARAM | Wiki |
.ST | Wiki |
.STEP | Wiki |
.SUBCKT | Wiki |
.TEMP | Wiki |
Device Statement | Documentation |
---|---|
B (Arbitrary Behavioral Voltage or Current Source) | Wiki |
C (Capacitor) | Wiki |
D (Diode) | Wiki |
E (Voltage-Controlled Voltage Source) | Wiki |
F (Current-Controlled Current Source) | Wiki |
G (Voltage-Controlled Current Source) | Wiki |
H (Current-Controlled Voltage Source) | Wiki |
I (Independent Current Source) | Wiki |
J (JFET) | Wiki |
K (Mutual Inductance) | Wiki |
L (Inductor) | Wiki |
M (Mosfet) | Wiki |
Q (Bipolar Junction Transistor) | Wiki |
R (Resistor) | Wiki |
S (Voltage Switch) | Wiki |
T (Lossless Transmission Line) | Wiki |
V (Independent Voltage Source) | Wiki |
W (Current Switch) | Wiki |
X (Subcircuit) | Wiki |
- API documentation is available at https://spicesharp.github.io/SpiceSharpParser/api/index.html.
- Wiki is available at https://github.com/SpiceSharp/SpiceSharpParser/wiki
SpiceSharpParser is under MIT License