Skip to content

Latest commit

 

History

History
140 lines (119 loc) · 8.4 KB

README.md

File metadata and controls

140 lines (119 loc) · 8.4 KB

Spice#/SpiceSharpParser

Windows Linux codecov CodeFactor Sonarcloud Status Sonarcloud Status Sonarcloud Status Lines of Code Duplicated Lines (%) FOSSA Status

SpiceSharpParser is a .NET library that allows to parse SPICE netlists and to simulate them using SpiceSharp.

Installation

SpiceSharpParser is available as NuGet Package.

Quickstart

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);
        }
    }
}    

Compatibility

PSpice

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.

Capabilities

Analog Behavioral Modeling supported:

  • POLY(n)
  • TABLE
  • VALUE

Note: Only voltage and current expressions are supported in TABLE, VALUE

Dot statements supported:

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
.PRINT Wiki
.TRAN Wiki
.SAVE Wiki
.SPARAM Wiki
.ST Wiki
.STEP Wiki
.SUBCKT Wiki
.TEMP Wiki

Device statements supported:

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

Supported by

Documentation

License

SpiceSharpParser is under MIT License

FOSSA Status