Skip to content

Commit

Permalink
Use latest SpiceSharp
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-golebiowski committed Oct 11, 2024
1 parent 26abcc5 commit b1e9b9c
Show file tree
Hide file tree
Showing 24 changed files with 188 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
<PackageReference Include="SpiceSharp" Version="3.2.2" />
<PackageReference Include="SpiceSharp" Version="3.2.3" />
<PackageReference Include="SpiceSharpBehavioral" Version="3.2.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
Expand Down
2 changes: 1 addition & 1 deletion src/SpiceSharpParser.IntegrationTests/BaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public static Tuple<double, double>[] RunDCSimulation(SpiceSharpModel readerResu
list.Add(new Tuple<double, double>(((DC)simulation).GetCurrentSweepValue().Last(), export.Extract()));
};

var codes = simulation.Run(readerResult.Circuit);
var codes = simulation.Run(readerResult.Circuit, -1);
var attached = simulation.AttachEvents(codes);
attached.ToArray(); // eval

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using SpiceSharp.Simulations;
using SpiceSharpParser.Common;
using SpiceSharpParser.ModelReaders.Netlist.Spice;
using System;
using System.IO;
using System.Linq;
using System.Text;
using Xunit;

Expand Down Expand Up @@ -129,7 +131,10 @@ public void When_DistributionNameSensitive_Positive_Expect_NoException()
reader.Settings.CaseSensitivity.IsDistributionNameCaseSensitive = true;
var spiceModel = reader.Read(parseResult.FinalModel);

spiceModel.Simulations[0].Run(spiceModel.Circuit);
var codes = spiceModel.Simulations[0].Run(spiceModel.Circuit, -1);
codes = spiceModel.Simulations[0].AttachEvents(codes);

codes.ToArray();
}

[Fact]
Expand All @@ -153,8 +158,11 @@ public void When_DistributionNameSensitive_Negative_Expect_Exception()
reader.Settings.CaseSensitivity.IsDistributionNameCaseSensitive = true;
var spiceModel = reader.Read(parseResult.FinalModel);

Assert.Throws<ArgumentException>(() =>
spiceModel.Simulations[0].Run(spiceModel.Circuit));
var codes = spiceModel.Simulations[0].Run(spiceModel.Circuit, -1);
codes = spiceModel.Simulations[0].AttachEvents(codes);


Assert.Throws<ArgumentException>(() => codes.ToArray());
}

[Fact]
Expand All @@ -179,7 +187,7 @@ public void BuiltInFunctionNamePositive()
reader.Settings.CaseSensitivity.IsDistributionNameCaseSensitive = true;
var spiceModel = reader.Read(parseResult.FinalModel);

var exception = Record.Exception(() => spiceModel.Simulations[0].Run(spiceModel.Circuit));
var exception = Record.Exception(() => spiceModel.Simulations[0].Run(spiceModel.Circuit).ToArray());
Assert.Null(exception);

}
Expand Down Expand Up @@ -291,7 +299,7 @@ public void ComponentNamesException()
reader.Settings.CaseSensitivity.IsEntityNamesCaseSensitive = true;
var spiceModel = reader.Read(parseResult.FinalModel);

Assert.Throws<SpiceSharp.BehaviorsNotFoundException>(() => RunOpSimulation(spiceModel, "I(r1)"));
Assert.Throws<SpiceSharpParserException>(() => RunOpSimulation(spiceModel, "I(r1)"));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ public void When_InvalidExportForSimulationWithoutFilter_Expect_Reference()
"R1 IN OUT 10e3",
"C1 OUT 0 10e-6",
".OP",
".PRINT V(OUT) I(C1)",
".PRINT V(OUT)",
".END");
RunSimulations(model);

Assert.Single(model.Prints);
Assert.Equal("#1 OP", model.Prints[0].Name);
Assert.Single(model.Prints[0].ColumnNames);
Assert.Single(model.Prints[0].Rows[0].Columns);
Assert.Single(model.Prints[0].Rows);
}

Expand Down Expand Up @@ -117,7 +116,7 @@ public void When_PrintOpWithoutFilterWithoutParameters_Expect_Reference()
RunSimulations(model);
Assert.Single(model.Prints);
Assert.Equal("#1 OP", model.Prints[0].Name);
Assert.Equal(6, model.Prints[0].ColumnNames.Count);
Assert.Equal(5, model.Prints[0].ColumnNames.Count);
Assert.Single(model.Prints[0].Rows);
}

Expand Down Expand Up @@ -157,15 +156,13 @@ public void When_PrintOpWithoutArgumentsWithoutFilter_Expect_Reference()

Assert.Single( model.Prints);
Assert.Equal("#1 OP", model.Prints[0].Name);
Assert.Equal(6, model.Prints[0].ColumnNames.Count);
Assert.Equal(5, model.Prints[0].ColumnNames.Count);

Assert.Equal("I(V1)", model.Prints[0].ColumnNames[0]);
Assert.Equal("I(R1)", model.Prints[0].ColumnNames[1]);
Assert.Equal("I(C1)", model.Prints[0].ColumnNames[2]);
Assert.Equal("V(IN)", model.Prints[0].ColumnNames[3]);
Assert.Equal("V(0)", model.Prints[0].ColumnNames[4]);
Assert.Equal("V(OUT)", model.Prints[0].ColumnNames[5]);

Assert.Equal("V(IN)", model.Prints[0].ColumnNames[2]);
Assert.Equal("V(0)", model.Prints[0].ColumnNames[3]);
Assert.Equal("V(OUT)", model.Prints[0].ColumnNames[4]);
Assert.Single(model.Prints[0].Rows);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="SpiceSharp" Version="3.2.2" />
<PackageReference Include="SpiceSharp" Version="3.2.3" />
<PackageReference Include="SpiceSharpBehavioral" Version="3.2.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="SpiceSharp" Version="3.2.2" />
<PackageReference Include="SpiceSharp" Version="3.2.3" />
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
<PackageReference Include="xunit.runner.console" Version="2.9.2">
<PrivateAssets>all</PrivateAssets>
Expand Down
2 changes: 1 addition & 1 deletion src/SpiceSharpParser.Tests/SpiceSharpParser.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="SpiceSharp" Version="3.2.2" />
<PackageReference Include="SpiceSharp" Version="3.2.3" />
<PackageReference Include="SpiceSharpBehavioral" Version="3.2.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,32 @@ public CurrentExport(string name, ISimulationWithEvents simulation, string sourc
/// </returns>
public override double Extract()
{
if (ExportRealImpl != null)
if (ExportRealImpl != null)
{
if (!ExportRealImpl.IsValid)
{
if (ExceptionsEnabled)
{
throw new SpiceSharpParserException($"Current export {Name} is invalid");
}

return double.NaN;
}

return ExportRealImpl.Value;
}
else
{
if (!ExportImpl.IsValid)
{
if (ExceptionsEnabled)
{
throw new SpiceSharpParserException($"Current export {Name} is invalid");
}

return double.NaN;
}

return ExportImpl.Value.Real;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ public CurrentImaginaryExport(string name, ISimulationWithEvents simulation, str
/// </returns>
public override double Extract()
{
if (!ExportImpl.IsValid)
{
if (ExceptionsEnabled)
{
throw new SpiceSharpParserException($"Current imaginary export {Name} is invalid");
}

return double.NaN;
}

return ExportImpl.Value.Imaginary;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ public CurrentMagnitudeExport(string name, ISimulationWithEvents simulation, str
/// </returns>
public override double Extract()
{
if (!ExportImpl.IsValid)
{
if (ExceptionsEnabled)
{
throw new SpiceSharpParserException($"Current magnitude export {Name} is invalid");
}

return double.NaN;
}

return ExportImpl.Value.Magnitude;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ public CurrentPhaseExport(string name, ISimulationWithEvents simulation, string
/// </returns>
public override double Extract()
{
if (!ExportImpl.IsValid)
{
if (ExceptionsEnabled)
{
throw new SpiceSharpParserException($"Current phase export {Name} is invalid");
}

return double.NaN;
}

return ExportImpl.Value.Phase;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ public CurrentRealExport(string name, ISimulationWithEvents simulation, string s
/// </returns>
public override double Extract()
{
if (!ExportImpl.IsValid)
{
if (ExceptionsEnabled)
{
throw new SpiceSharpParserException($"Current real export {Name} is invalid");
}

return double.NaN;
}

return ExportImpl.Value;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ public InputNoiseExport(ISimulationWithEvents simulation)

public override double Extract()
{
if (!ExportImpl.IsValid)
{
if (ExceptionsEnabled)
{
throw new SpiceSharpParserException($"Input noise density export {Name} is invalid");
}

return double.NaN;
}

return ExportImpl.Value;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ public OutputNoiseExport(ISimulationWithEvents simulation)

public override double Extract()
{
if (!ExportImpl.IsValid)
{
if (ExceptionsEnabled)
{
throw new SpiceSharpParserException($"Output noise density export {Name} is invalid");
}

return double.NaN;
}

return ExportImpl.Value;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ public VoltageDecibelExport(string name, ISimulationWithEvents simulation, strin
/// </returns>
public override double Extract()
{
if (!ExportImpl.IsValid)
{
if (ExceptionsEnabled)
{
throw new SpiceSharpParserException($"Voltage (db) export {Name} is invalid");
}

return double.NaN;
}

return Math.Log10(ExportImpl.Value.Magnitude);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,30 @@ public override double Extract()
{
if (ExportImpl != null)
{
if (!ExportImpl.IsValid)
{
if (ExceptionsEnabled)
{
throw new SpiceSharpParserException($"Voltage export {Name} is invalid");
}

return double.NaN;
}

return ExportImpl.Value.Real;
}
else
{
if (!ExportRealImpl.IsValid)
{
if (ExceptionsEnabled)
{
throw new SpiceSharpParserException($"Voltage export {Name} is invalid");
}

return double.NaN;
}

return ExportRealImpl.Value;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ public VoltageImaginaryExport(string name, ISimulationWithEvents simulation, str
/// </returns>
public override double Extract()
{
if (!ExportImpl.IsValid)
{
if (ExceptionsEnabled)
{
throw new SpiceSharpParserException($"Voltage imaginary export {Name} is invalid");
}

return double.NaN;
}

return ExportImpl.Value.Imaginary;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ public VoltageMagnitudeExport(string name, ISimulationWithEvents simulation, str
/// </returns>
public override double Extract()
{
if (!ExportImpl.IsValid)
{
if (ExceptionsEnabled)
{
throw new SpiceSharpParserException($"Voltage magnitude export {Name} is invalid");
}

return double.NaN;
}

return ExportImpl.Value.Magnitude;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ public VoltagePhaseExport(string name, ISimulationWithEvents simulation, string
/// </returns>
public override double Extract()
{
if (!ExportImpl.IsValid)
{
if (ExceptionsEnabled)
{
throw new SpiceSharpParserException($"Voltage phase export {Name} is invalid");
}

return double.NaN;
}
return ExportImpl.Value.Magnitude;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ public VoltageRealExport(string name, ISimulationWithEvents simulation, string n
/// </returns>
public override double Extract()
{
if (!ExportImpl.IsValid)
{
if (ExceptionsEnabled)
{
throw new SpiceSharpParserException($"Voltage real export {Name} is invalid");
}

return double.NaN;
}

return ExportImpl.Value;
}
}
Expand Down
Loading

0 comments on commit b1e9b9c

Please sign in to comment.