Skip to content

Commit

Permalink
Merge pull request #38 from SpiceSharp/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
marcin-golebiowski authored Oct 25, 2018
2 parents e210cd7 + 11d1710 commit 9c2de77
Show file tree
Hide file tree
Showing 80 changed files with 2,190 additions and 371 deletions.
81 changes: 47 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,31 @@ var netlist = string.Join(Environment.NewLine,
".SAVE i(V1)",
".END");

\\ Parsing part - SpiceSharpParser
var parser = new SpiceParser();
var parseResult = parser.ParseNetlist(netlist);
var spiceSharpModel = parseResult.SpiceSharpModel;

\\ Simulation part - SpiceSharp
var simulation = spiceSharpModel.Simulations.Single();
var export = spiceSharpModel.Exports.Find(e => e.Name == "i(V1)");
simulation.ExportSimulationData += (sender, args) => Console.WriteLine(export.Extract());
simulation.Run(spiceSharpModel.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 a few other features parsing can fail.

## Documentation
* API documentation is available at <https://spicesharp.github.io/SpiceSharpParser/api/index.html>.
* Wiki is available at <https://github.com/SpiceSharp/SpiceSharpParser/wiki>

## Capabilities
### Analog Behavioral Modeling supported:
* POLY(n)
* TABLE
* VALUE

## Features
### Dot statements
### Dot statements supported:
| Statement | Documentation |
|:------------|-----------------------:|
|.AC |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/.AC)|
Expand Down Expand Up @@ -79,7 +87,7 @@ simulation.Run(spiceSharpModel.Circuit);
|.SUBCKT |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/.SUBCKT)|
|.TEMP |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/.TEMP)|

### Device statements
### Device statements supported:
| Device Statement | Documentation |
|:------------|-----------------------:|
|C (Capacitor)|[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/C)|
Expand All @@ -99,52 +107,57 @@ simulation.Run(spiceSharpModel.Circuit);
|W (Current Switch)|[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/W)|
|X (Subcircuit)|[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/X)|

### Expression function
### Functions in expressions supported:
| Function name | Documentation |
|:------------|---------------------:|
|@ |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/@)|
|** |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/**)|
|cos |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/cos)|
|sin |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/sin)|
|tan |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/tan)|
|cosh |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/cosh)|
|sinh |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/sinh)|
|tanh |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/tanh)|
|abs |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/abs)|
|acos |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/acos)|
|asin |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/asin)|
|atan |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/atan)|
|atan2 |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/atan2)|
|def |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/def)|
|lazy |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/lazy)|
|if |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/if)|
|gauss |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/gauss)|
|random |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/random)|
|flat |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/flat)|
|table |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/table)|
|pow |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/pow)|
|pwr |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/pwr)|
|pwrs |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/pwrs)|
|sqrt |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/sqrt)|
|min |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/min)|
|max |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/max)|
|limit |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/limit)|
|ln |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/ln)|
|log |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/log)|
|log10 |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/log10)|
|cbrt |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/cbrt)|
|buf |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/buf)|
|cbrt |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/cbrt)|
|ceil |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/ceil)|
|abs |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/abs)|
|cos |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/cos)|
|cosh |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/cosh)|
|db |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/db)|
|def |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/def)|
|exp |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/exp)|
|flat |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/flat)|
|floor |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/floor)|
|gauss |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/gauss)|
|hypot |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/hypot)|
|if |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/if)|
|int |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/int)|
|inv |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/inv)|
|exp |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/exp)|
|db |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/db)|
|lazy |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/lazy)|
|limit |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/limit)|
|ln |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/ln)|
|log |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/log)|
|log10 |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/log10)|
|max |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/max)|
|min |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/min)|
|pow |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/pow)|
|pwr |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/pwr)|
|pwrs |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/pwrs)|
|random |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/random)|
|round |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/round)|
|sgn |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/sgn)|
|sin |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/sin)|
|sinh |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/sinh)|
|sqrt |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/sqrt)|
|table |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/table)|
|tan |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/tan)|
|tanh |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/tanh)|
|u |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/u)|
|uramp |[Wiki](https://github.com/SpiceSharp/SpiceSharpParser/wiki/uramp)|


## Documentation
* API documentation is available at <https://spicesharp.github.io/SpiceSharpParser/api/index.html>.
* Wiki is available at <https://github.com/SpiceSharp/SpiceSharpParser/wiki>

## License
SpiceSharpParser is under MIT License
2 changes: 1 addition & 1 deletion src/SpiceSharp-Parser.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{CEDE104D
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SpiceSharpParser.CodeAnalysis", "SpiceSharpParser.CodeAnalysis\SpiceSharpParser.CodeAnalysis.csproj", "{690C3742-17AD-46F6-A73D-CAE33C780523}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpiceSharpParser.PerformanceTests", "SpiceSharpParser.PerformanceTests\SpiceSharpParser.PerformanceTests.csproj", "{2F7A7389-F1C2-4824-9594-5E102CFACC88}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SpiceSharpParser.PerformanceTests", "SpiceSharpParser.PerformanceTests\SpiceSharpParser.PerformanceTests.csproj", "{2F7A7389-F1C2-4824-9594-5E102CFACC88}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
using Xunit;

namespace SpiceSharpParser.IntegrationTests
{
public class PolyTests : BaseTests
{
[Fact]
public void VoltageControlledVoltageSourceFirstFormat()
{
var netlist = ParseNetlist(
"Poly(1) E test circuit - first format",
"R1 1 0 100",
"V1 1 0 2",
"ESource 2 0 POLY(1) 1 0 2 1", // V(1) + 2
".OP",
".SAVE V(2,0)",
".END");

Assert.NotNull(netlist);
double export = RunOpSimulation(netlist, "V(2,0)");
Assert.Equal(4, export);
}

[Fact]
public void VoltageControlledVoltageSourceSecondFormat()
{
var netlist = ParseNetlist(
"Poly(1) E test circuit - second format",
"R1 1 0 100",
"V1 1 0 2",
"ESource 2 0 POLY(1) (1,0) 2 1", // V(1) + 2
".OP",
".SAVE V(2,0)",
".END");

Assert.NotNull(netlist);
double export = RunOpSimulation(netlist, "V(2,0)");
Assert.Equal(4, export);
}

[Fact]
public void VoltageControlledVoltageSourceFirstFormatSecondDimension()
{
var netlist = ParseNetlist(
"Poly(1) E test circuit - first format",
"R1 1 0 100",
"V1 1 0 2",
"V3 3 0 3",
"ESource 2 0 POLY(2) 1 0 3 0 2 1 1", // V(1) + V(3) + 2
".OP",
".SAVE V(2,0)",
".END");

Assert.NotNull(netlist);
double export = RunOpSimulation(netlist, "V(2,0)");
Assert.Equal(7, export);
}

[Fact]
public void VoltageControlledVoltageSourceSecondFormatSecondDimension()
{
var netlist = ParseNetlist(
"Poly(1) E test circuit - second format",
"R1 1 0 100",
"V1 1 0 2",
"V3 3 0 3",
"ESource 2 0 POLY(2) (1,0) (3,0) 2 1 1 ", // V(1) + V(3) + 2
".OP",
".SAVE V(2,0)",
".END");

Assert.NotNull(netlist);
double export = RunOpSimulation(netlist, "V(2,0)");
Assert.Equal(7, export);
}

[Fact]
public void VoltageControlledCurrentSourceFirstFormat()
{
var netlist = ParseNetlist(
"Poly(1) G test circuit",
"R1 1 0 100",
"V1 2 0 2",
"GSource 1 0 POLY(1) 2 0 2 1", // V(2) + 2
".OP",
".SAVE I(GSource)",
".END");

Assert.NotNull(netlist);
double export = RunOpSimulation(netlist, "I(GSource)");
Assert.Equal(4, export);
}

[Fact]
public void VoltageControlledCurrentSourceSecondFormat()
{
var netlist = ParseNetlist(
"Poly(1) G test circuit",
"R1 1 0 100",
"V1 2 0 2",
"GSource 1 0 POLY(1) (2,0) 2 1", // V(2) + 2
".OP",
".SAVE I(GSource)",
".END");

Assert.NotNull(netlist);
double export = RunOpSimulation(netlist, "I(GSource)");
Assert.Equal(4, export);
}

[Fact]
public void CurrentControlledCurrentSource()
{
var netlist = ParseNetlist(
"Poly(1) F test circuit",
"R1 1 0 100",
"R2 1 0 200",
"I1 1 0 2",
"FSource 2 0 POLY(1) I1 2 1", // I(I1) + 2
".OP",
".SAVE I(FSource)",
".END");

Assert.NotNull(netlist);
double export = RunOpSimulation(netlist, "I(FSource)");
Assert.Equal(4, export);
}

[Fact]
public void CurrentControlledVoltageSource()
{
var netlist = ParseNetlist(
"Poly(1) H test circuit",
"R1 1 0 100",
"I1 1 0 2",
"HSource 2 0 POLY(1) I1 2 1", // I(I1) + 2
".OP",
".SAVE V(2,0)",
".END");

Assert.NotNull(netlist);
double export = RunOpSimulation(netlist, "V(2,0)");
Assert.Equal(4, export);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using Xunit;

namespace SpiceSharpParser.IntegrationTests
{
public class TableTests : BaseTests
{
[Fact]
public void ParsingFirstFormat()
{
var netlist = ParseNetlist(
"TABLE circuit",
"V1 1 0 1.5m",
"R1 1 0 10",
"E12 2 1 TABLE {V(1,0)} = (0,1) (1m,2) (2m,3)",
"R2 2 0 10",
".SAVE V(2,1)",
".OP",
".END");

var export = RunOpSimulation(netlist, "V(2,1)");
Assert.NotNull(netlist);
Assert.Equal(2.5, export);
}

[Fact]
public void ParsingSecondFormat()
{
var netlist = ParseNetlist(
"TABLE circuit",
"V1 1 0 1.5m",
"R1 1 0 10",
"E12 2 1 TABLE {V(1,0)} (0,1) (1m,2) (2m,3)",
"R2 2 0 10",
".SAVE V(2,1)",
".OP",
".END");
var export = RunOpSimulation(netlist, "V(2,1)");
Assert.NotNull(netlist);
Assert.Equal(2.5, export);
}

[Fact]
public void ParsingThirdFormat()
{
var netlist = ParseNetlist(
"TABLE circuit",
"V1 1 0 1.5m",
"R1 1 0 10",
"E12 2 1 TABLE {V(1,0)} ((0,1) (1m,2) (2m,3))",
"R2 2 0 10",
".SAVE V(2,1)",
".OP",
".END");
var export = RunOpSimulation(netlist, "V(2,1)");
Assert.NotNull(netlist);
Assert.Equal(2.5, export);
}

[Fact]
public void ParsingAdvancedExpression()
{
var netlist = ParseNetlist(
"TABLE circuit",
"V1 1 0 1.5",
"V2 2 1 2.5",
"R1 3 2 10",
"R2 3 0 10",
"E12 3 2 TABLE {9 + (V(1,0) + V(2,0))} ((-10,-10) (10, 10))",
".SAVE V(3,2)",
".OP",
".END");
Assert.NotNull(netlist);
var export = RunOpSimulation(netlist, "V(3,2)");
Assert.NotNull(netlist);
Assert.Equal(10, export);
}
}
}
Loading

0 comments on commit 9c2de77

Please sign in to comment.