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 netlist = 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 - SpiceSharpParser
var parser = new SpiceParser();
var parseResult = parser.ParseNetlist(netlist);
var spiceModel = parseResult.SpiceModel;
// Simulation part - SpiceSharp
var simulation = spiceModel.Simulations.Single();
var export = spiceModel.Exports.Find(e => e.Name == "i(V1)");
simulation.ExportSimulationData += (sender, args) => Console.WriteLine(export.Extract());
simulation.Run(spiceModel.Circuit);
}
}
}
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
Note: Only voltage and current expressions are supported in 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