Skip to content

Commit 05e708d

Browse files
Update README.md for improved clarity and structure
1 parent 10e726c commit 05e708d

1 file changed

Lines changed: 129 additions & 111 deletions

File tree

README.md

Lines changed: 129 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,149 @@
1-
# <img src="https://spicesharp.github.io/SpiceSharp/api/images/logo_full.svg" width="45px" /> Spice#/SpiceSharpParser
2-
[<img src="https://img.shields.io/nuget/vpre/SpiceSharp-Parser.svg">]( https://www.nuget.org/packages/SpiceSharp-Parser)
1+
# <img src="https://spicesharp.github.io/SpiceSharp/api/images/logo_full.svg" width="45px" /> SpiceSharpParser
32

4-
SpiceSharpParser is a .NET library that allows to parse SPICE netlists and to simulate them using SpiceSharp.
3+
[<img src="https://img.shields.io/nuget/vpre/SpiceSharp-Parser.svg">](https://www.nuget.org/packages/SpiceSharp-Parser)
4+
5+
SpiceSharpParser is a .NET library that parses SPICE netlists and simulates them using [SpiceSharp](https://github.com/SpiceSharp/SpiceSharp). It targets **netstandard2.0** and **net8.0**, so it works on .NET Framework 4.6.1+, .NET Core, and .NET 5–8+.
6+
7+
## Features
8+
9+
- Parses industry-standard SPICE netlists (PSpice / LTspice dialect)
10+
- Runs DC, AC, transient, operating-point, and noise analyses via SpiceSharp
11+
- Parameter sweeps (`.STEP`), Monte Carlo (`.MC`), and multi-temperature runs
12+
- Post-simulation measurements (`.MEAS` / `.MEASURE`) with TRIG/TARG, FIND, WHEN, AVG, RMS, MIN, MAX, INTEG, and PARAM
13+
- Analog behavioral modeling: `VALUE`, `TABLE`, `POLY(n)`
14+
- Parameterized designs with `.PARAM`, `.FUNC`, `.LET`, `.SUBCKT`
15+
- Conditional netlist sections with `.IF` / `.ELSE` / `.ENDIF`
16+
- Structured output via `.SAVE`, `.PRINT`, `.PLOT`, `.WAVE`
517

618
## Installation
719

8-
SpiceSharpParser is available as [NuGet Package](https://www.nuget.org/packages/SpiceSharp-Parser).
20+
```
21+
dotnet add package SpiceSharp-Parser
22+
```
23+
24+
Or via the Package Manager Console:
925

10-
## Quickstart
26+
```
27+
Install-Package SpiceSharp-Parser
28+
```
1129

12-
Parsing a netlist and executing a simulation is relatively straightforward. For example:
30+
## Quick Start
1331

1432
```csharp
1533
using System;
1634
using System.Linq;
1735
using SpiceSharpParser;
1836

19-
namespace SpiceSharpParserExample
20-
{
21-
class Program
22-
{
23-
static void Main(string[] programArgs)
24-
{
25-
var netlistText = string.Join(Environment.NewLine,
26-
"Diode circuit",
27-
"D1 OUT 0 1N914",
28-
"V1 OUT 0 0",
29-
".model 1N914 D(Is=2.52e-9 Rs=0.568 N=1.752 Cjo=4e-12 M=0.4 tt=20e-9)",
30-
".DC V1 -1 1 10e-3",
31-
".SAVE i(V1)",
32-
".END");
33-
34-
// Parsing part
35-
var parser = new SpiceNetlistParser();
36-
var parseResult = parser.ParseNetlist(netlistText);
37-
var netlist = parseResult.FinalModel;
38-
39-
// Translating netlist model to SpiceSharp
40-
var reader = new SpiceSharpReader();
41-
var spiceSharpModel = reader.Read(netlist);
42-
43-
// Simulation using SpiceSharp
44-
var simulation = spiceSharpModel.Simulations.Single();
45-
var export = spiceSharpModel.Exports.Find(e => e.Name == "i(V1)");
46-
simulation.EventExportData += (sender, args) => Console.WriteLine(export.Extract());
47-
var codes = simulation.Run(spiceSharpModel.Circuit, -1);
48-
codes = simulation.InvokeEvents(codes);
49-
codes.ToArray(); //eval
50-
}
51-
}
52-
}
53-
37+
var netlist = string.Join(Environment.NewLine,
38+
"Diode circuit",
39+
"D1 OUT 0 1N914",
40+
"V1 OUT 0 0",
41+
".model 1N914 D(Is=2.52e-9 Rs=0.568 N=1.752 Cjo=4e-12 M=0.4 tt=20e-9)",
42+
".DC V1 -1 1 10e-3",
43+
".SAVE i(V1)",
44+
".END");
45+
46+
// 1. Parse the netlist
47+
var parser = new SpiceNetlistParser();
48+
var parseResult = parser.ParseNetlist(netlist);
49+
50+
// 2. Translate to SpiceSharp objects
51+
var reader = new SpiceSharpReader();
52+
var model = reader.Read(parseResult.FinalModel);
53+
54+
// 3. Run the simulation
55+
var simulation = model.Simulations.Single();
56+
var export = model.Exports.Find(e => e.Name == "i(V1)");
57+
simulation.EventExportData += (sender, args) => Console.WriteLine(export.Extract());
58+
var codes = simulation.Run(model.Circuit, -1);
59+
codes = simulation.InvokeEvents(codes);
60+
codes.ToArray();
5461
```
62+
63+
### How It Works
64+
65+
| Step | API | Result |
66+
|------|-----|--------|
67+
| **Parse** | `SpiceNetlistParser.ParseNetlist()` | Parse-tree model of the netlist |
68+
| **Read** | `SpiceSharpReader.Read()` | `SpiceSharpModel` with Circuit, Simulations, Exports, Measurements |
69+
| **Simulate** | `simulation.Run()` / `InvokeEvents()` | Data available via exports and event callbacks |
70+
5571
## Compatibility
56-
### PSpice
57-
SpiceSharpParser is able to parse some of PSpice netlists.
58-
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.
59-
60-
61-
## Capabilities
62-
### Analog Behavioral Modeling supported:
63-
* POLY(n)
64-
* TABLE
65-
* VALUE
66-
67-
### Dot statements supported:
68-
| Statement | Documentation |
69-
|:------------|-----------------------:|
70-
|.AC |[Docs](src/docs/articles/ac.md)|
71-
|.APPENDMODEL |[Docs](src/docs/articles/appendmodel.md)|
72-
|.DC |[Docs](src/docs/articles/dc.md)|
73-
|.DISTRIBUTION|[Docs](src/docs/articles/distribution.md)|
74-
|.ELSE |[Docs](src/docs/articles/if.md)|
75-
|.ENDIF |[Docs](src/docs/articles/if.md)|
76-
|.FUNC |[Docs](src/docs/articles/func.md)|
77-
|.GLOBAL |[Docs](src/docs/articles/global.md)|
78-
|.IC |[Docs](src/docs/articles/ic.md)|
79-
|.IF |[Docs](src/docs/articles/if.md)|
80-
|.INCLUDE |[Docs](src/docs/articles/include.md)|
81-
|.LET |[Docs](src/docs/articles/let.md)|
82-
|.LIB |[Docs](src/docs/articles/lib.md)|
83-
|.MC |[Docs](src/docs/articles/mc.md)|
84-
|.MEAS |[Docs](src/docs/articles/meas.md)|
85-
|.MEASURE |[Docs](src/docs/articles/meas.md)|
86-
|.NODESET |[Docs](src/docs/articles/nodeset.md)|
87-
|.NOISE |[Docs](src/docs/articles/noise.md)|
88-
|.OP |[Docs](src/docs/articles/op.md)|
89-
|.OPTIONS |[Docs](src/docs/articles/options.md)|
90-
|.PARAM |[Docs](src/docs/articles/param.md)|
91-
|.PLOT |[Docs](src/docs/articles/plot.md)|
92-
|.PRINT |[Docs](src/docs/articles/print.md)|
93-
|.TRAN |[Docs](src/docs/articles/tran.md)|
94-
|.SAVE |[Docs](src/docs/articles/save.md)|
95-
|.SPARAM |[Docs](src/docs/articles/sparam.md)|
96-
|.ST |[Docs](src/docs/articles/st.md)|
97-
|.STEP |[Docs](src/docs/articles/step.md)|
98-
|.SUBCKT |[Docs](src/docs/articles/subckt.md)|
99-
|.TEMP |[Docs](src/docs/articles/temp.md)|
100-
101-
### Device statements supported:
102-
| Device Statement | Documentation |
103-
|:------------|-----------------------:|
104-
|B (Arbitrary Behavioral Voltage or Current Source)|[Docs](src/docs/articles/behavioral-source.md)|
105-
|C (Capacitor)|[Docs](src/docs/articles/capacitor.md)|
106-
|D (Diode)|[Docs](src/docs/articles/diode.md)|
107-
|E (Voltage-Controlled Voltage Source)|[Docs](src/docs/articles/vcvs.md)|
108-
|F (Current-Controlled Current Source)|[Docs](src/docs/articles/cccs.md)|
109-
|G (Voltage-Controlled Current Source)|[Docs](src/docs/articles/vccs.md)|
110-
|H (Current-Controlled Voltage Source)|[Docs](src/docs/articles/ccvs.md)|
111-
|I (Independent Current Source)|[Docs](src/docs/articles/current-source.md)|
112-
|J (JFET)|[Docs](src/docs/articles/jfet.md)|
113-
|K (Mutual Inductance)|[Docs](src/docs/articles/mutual-inductance.md)|
114-
|L (Inductor)|[Docs](src/docs/articles/inductor.md)|
115-
|M (Mosfet)|[Docs](src/docs/articles/mosfet.md)|
116-
|Q (Bipolar Junction Transistor)|[Docs](src/docs/articles/bjt.md)|
117-
|R (Resistor)|[Docs](src/docs/articles/resistor.md)|
118-
|S (Voltage Switch)|[Docs](src/docs/articles/voltage-switch.md)|
119-
|T (Lossless Transmission Line)|[Docs](src/docs/articles/transmission-line.md)|
120-
|V (Independent Voltage Source)|[Docs](src/docs/articles/voltage-source.md)|
121-
|W (Current Switch)|[Docs](src/docs/articles/current-switch.md)|
122-
|X (Subcircuit)|[Docs](src/docs/articles/subcircuit-instance.md)|
72+
73+
SpiceSharpParser handles a broad subset of **PSpice** and **LTspice** syntax. Unsupported features that may cause parse or simulation errors include `LAPLACE`, `FREQ` (analog behavioral modeling), and some advanced PSpice-only constructs.
74+
75+
## Supported Statements
76+
77+
### Dot Statements
78+
79+
| Statement | Description | Docs |
80+
|-----------|-------------|------|
81+
| `.AC` | AC small-signal frequency sweep | [Docs](src/docs/articles/ac.md) |
82+
| `.DC` | DC sweep analysis | [Docs](src/docs/articles/dc.md) |
83+
| `.TRAN` | Transient (time-domain) analysis | [Docs](src/docs/articles/tran.md) |
84+
| `.OP` | DC operating point | [Docs](src/docs/articles/op.md) |
85+
| `.NOISE` | Noise analysis | [Docs](src/docs/articles/noise.md) |
86+
| `.SAVE` | Save signals for export | [Docs](src/docs/articles/save.md) |
87+
| `.PRINT` | Tabular output | [Docs](src/docs/articles/print.md) |
88+
| `.PLOT` | XY plot output | [Docs](src/docs/articles/plot.md) |
89+
| `.MEAS` / `.MEASURE` | Post-simulation measurements | [Docs](src/docs/articles/meas.md) |
90+
| `.PARAM` | Define parameters | [Docs](src/docs/articles/param.md) |
91+
| `.FUNC` | Define functions | [Docs](src/docs/articles/func.md) |
92+
| `.LET` | Define named expressions | [Docs](src/docs/articles/let.md) |
93+
| `.SPARAM` | Scalar (eagerly evaluated) parameters | [Docs](src/docs/articles/sparam.md) |
94+
| `.SUBCKT` / `.ENDS` | Subcircuit definition | [Docs](src/docs/articles/subckt.md) |
95+
| `.INCLUDE` | Include external file | [Docs](src/docs/articles/include.md) |
96+
| `.LIB` | Include library section | [Docs](src/docs/articles/lib.md) |
97+
| `.GLOBAL` | Declare global nodes | [Docs](src/docs/articles/global.md) |
98+
| `.STEP` | Parameter sweep | [Docs](src/docs/articles/step.md) |
99+
| `.ST` | Parameter sweep (PSpice alias) | [Docs](src/docs/articles/st.md) |
100+
| `.MC` | Monte Carlo analysis | [Docs](src/docs/articles/mc.md) |
101+
| `.TEMP` | Temperature sweep | [Docs](src/docs/articles/temp.md) |
102+
| `.OPTIONS` | Simulator options | [Docs](src/docs/articles/options.md) |
103+
| `.IC` | Initial conditions | [Docs](src/docs/articles/ic.md) |
104+
| `.NODESET` | DC convergence hints | [Docs](src/docs/articles/nodeset.md) |
105+
| `.DISTRIBUTION` | Custom PDF for Monte Carlo | [Docs](src/docs/articles/distribution.md) |
106+
| `.IF` / `.ELSE` / `.ENDIF` | Conditional netlist sections | [Docs](src/docs/articles/if.md) |
107+
| `.APPENDMODEL` | Append model parameters | [Docs](src/docs/articles/appendmodel.md) |
108+
109+
### Device Statements
110+
111+
| Prefix | Device | Docs |
112+
|--------|--------|------|
113+
| **R** | Resistor | [Docs](src/docs/articles/resistor.md) |
114+
| **C** | Capacitor | [Docs](src/docs/articles/capacitor.md) |
115+
| **L** | Inductor | [Docs](src/docs/articles/inductor.md) |
116+
| **K** | Mutual Inductance | [Docs](src/docs/articles/mutual-inductance.md) |
117+
| **V** | Independent Voltage Source | [Docs](src/docs/articles/voltage-source.md) |
118+
| **I** | Independent Current Source | [Docs](src/docs/articles/current-source.md) |
119+
| **E** | Voltage-Controlled Voltage Source (VCVS) | [Docs](src/docs/articles/vcvs.md) |
120+
| **F** | Current-Controlled Current Source (CCCS) | [Docs](src/docs/articles/cccs.md) |
121+
| **G** | Voltage-Controlled Current Source (VCCS) | [Docs](src/docs/articles/vccs.md) |
122+
| **H** | Current-Controlled Voltage Source (CCVS) | [Docs](src/docs/articles/ccvs.md) |
123+
| **B** | Arbitrary Behavioral Source | [Docs](src/docs/articles/behavioral-source.md) |
124+
| **D** | Diode | [Docs](src/docs/articles/diode.md) |
125+
| **Q** | Bipolar Junction Transistor (BJT) | [Docs](src/docs/articles/bjt.md) |
126+
| **M** | MOSFET | [Docs](src/docs/articles/mosfet.md) |
127+
| **J** | JFET | [Docs](src/docs/articles/jfet.md) |
128+
| **S** | Voltage Switch | [Docs](src/docs/articles/voltage-switch.md) |
129+
| **W** | Current Switch | [Docs](src/docs/articles/current-switch.md) |
130+
| **T** | Lossless Transmission Line | [Docs](src/docs/articles/transmission-line.md) |
131+
| **X** | Subcircuit Instance | [Docs](src/docs/articles/subcircuit-instance.md) |
132+
133+
### Analog Behavioral Modeling
134+
135+
- `POLY(n)` — polynomial transfer functions
136+
- `TABLE` — piecewise-linear lookup tables
137+
- `VALUE` — arbitrary expression-based sources
123138

124139
## Documentation
125-
* Documentation articles are available in [src/docs/articles](src/docs/articles).
126-
* API documentation is available at <https://spicesharp.github.io/SpiceSharpParser/api/index.html>.
140+
141+
Full documentation is available in [src/docs/articles](src/docs/articles), including a [Getting Started](src/docs/articles/intro.md) guide.
142+
143+
API reference: <https://spicesharp.github.io/SpiceSharpParser/api/index.html>
127144

128145
## License
129-
SpiceSharpParser is under MIT License
146+
147+
SpiceSharpParser is licensed under the [MIT License](LICENSE).
130148

131149
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FSpiceSharp%2FSpiceSharpParser.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2FSpiceSharp%2FSpiceSharpParser?ref=badge_large)

0 commit comments

Comments
 (0)