diff --git a/.github/workflows/test-windows.yml b/.github/workflows/test-windows.yml index 502c7af9..27797114 100644 --- a/.github/workflows/test-windows.yml +++ b/.github/workflows/test-windows.yml @@ -36,7 +36,7 @@ jobs: shell: powershell run: | New-Item -Path .\.sonar\scanner -ItemType Directory - dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner --version 5.2.0 + dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner --version 9.0.0 - name: Build and analyze env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any diff --git a/src/SpiceSharpParser.CodeAnalysis/SpiceSharpParser.CodeAnalysis.csproj b/src/SpiceSharpParser.CodeAnalysis/SpiceSharpParser.CodeAnalysis.csproj index 0a3ae859..f33b6c0b 100644 --- a/src/SpiceSharpParser.CodeAnalysis/SpiceSharpParser.CodeAnalysis.csproj +++ b/src/SpiceSharpParser.CodeAnalysis/SpiceSharpParser.CodeAnalysis.csproj @@ -21,9 +21,9 @@ - - - + + + all runtime; build; native; contentfiles; analyzers diff --git a/src/SpiceSharpParser.IntegrationTests/BaseTests.cs b/src/SpiceSharpParser.IntegrationTests/BaseTests.cs index 27aeadd3..8d97218d 100644 --- a/src/SpiceSharpParser.IntegrationTests/BaseTests.cs +++ b/src/SpiceSharpParser.IntegrationTests/BaseTests.cs @@ -8,6 +8,7 @@ using System.Text; using SpiceSharpParser.Common; using System.Threading; +using Microsoft.CodeAnalysis.CSharp.Syntax; namespace SpiceSharpParser.IntegrationTests { @@ -140,7 +141,7 @@ public static List RunSimulationsAndReturnExports(SpiceSharpModel reader { var dcResult = new List(); result.Add(dcResult); - simulation.ExportSimulationData += (sender, e) => + simulation.EventExportData += (sender, e) => { dcResult.Add(export.Extract()); }; @@ -148,7 +149,7 @@ public static List RunSimulationsAndReturnExports(SpiceSharpModel reader if (simulation is OP) { - simulation.ExportSimulationData += (sender, e) => + simulation.EventExportData += (sender, e) => { var opResult = export.Extract(); result.Add(opResult); @@ -159,7 +160,7 @@ public static List RunSimulationsAndReturnExports(SpiceSharpModel reader { var tranResult = new List>(); result.Add(tranResult); - simulation.ExportSimulationData += (sender, e) => + simulation.EventExportData += (sender, e) => { tranResult.Add(new Tuple(e.Time, export.Extract())); }; @@ -168,7 +169,10 @@ public static List RunSimulationsAndReturnExports(SpiceSharpModel reader foreach (var simulation in readerResult.Simulations) { - simulation.Run(readerResult.Circuit); + var codes = simulation.Run(readerResult.Circuit, -1); + codes = simulation.AttachEvents(codes); + + codes.ToArray(); //eval } return result; @@ -185,7 +189,10 @@ public static void RunSimulations(SpiceSharpModel readerResult) { foreach (var simulation in readerResult.Simulations) { - simulation.Run(readerResult.Circuit); + var codes = simulation.Run(readerResult.Circuit, -1); + codes = simulation.AttachEvents(codes); + + codes.ToArray(); // eval } } @@ -194,13 +201,14 @@ public static double RunOpSimulation(SpiceSharpModel readerResult, string nameOf double result = double.NaN; var export = readerResult.Exports.Find(e => e.Name == nameOfExport); var simulation = readerResult.Simulations.Single(); - simulation.ExportSimulationData += (sender, e) => + simulation.EventExportData += (sender, e) => { result = export.Extract(); }; - simulation.Run(readerResult.Circuit); - + var codes = simulation.Run(readerResult.Circuit, -1); + codes = simulation.AttachEvents(codes); + codes.ToArray(); // eval return result; } @@ -209,7 +217,7 @@ public static double[] RunOpSimulation(SpiceSharpModel readerResult, params stri var simulation = readerResult.Simulations.Single(); double[] result = new double[nameOfExport.Length]; - simulation.ExportSimulationData += (sender, e) => + simulation.EventExportData += (sender, e) => { for (var i = 0; i < nameOfExport.Length; i++) { @@ -217,8 +225,10 @@ public static double[] RunOpSimulation(SpiceSharpModel readerResult, params stri result[i] = export.Extract(); } }; - - simulation.Run(readerResult.Circuit); + + var codes = simulation.Run(readerResult.Circuit, -1); + var attached = simulation.AttachEvents(codes); + attached.ToArray(); // eval return result; } @@ -228,7 +238,7 @@ public static Tuple[] RunOpSimulation(SpiceSharpModel readerResu var simulation = readerResult.Simulations.First(s => s is OP); Tuple[] result = new Tuple[readerResult.Exports.Count]; - simulation.ExportSimulationData += (sender, e) => + simulation.EventExportData += (sender, e) => { for (var i = 0; i < readerResult.Exports.Count; i++) { @@ -244,7 +254,9 @@ public static Tuple[] RunOpSimulation(SpiceSharpModel readerResu } }; - simulation.Run(readerResult.Circuit); + var codes = simulation.Run(readerResult.Circuit, -1); + var attached = simulation.AttachEvents(codes); + attached.ToArray(); // eval return result; } @@ -255,12 +267,14 @@ public static Tuple[] RunTransientSimulation(SpiceSharpModel rea var export = readerResult.Exports.Find(e => e.Name == nameOfExport && e.Simulation is Transient); var simulation = readerResult.Simulations.First(s => s is Transient); - simulation.ExportSimulationData += (sender, e) => + simulation.EventExportData += (sender, e) => { list.Add(new Tuple(e.Time, export.Extract())); }; - simulation.Run(readerResult.Circuit); + var codes = simulation.Run(readerResult.Circuit, -1); + var attached = simulation.AttachEvents(codes); + attached.ToArray(); // eval return list.ToArray(); } @@ -270,13 +284,15 @@ public static Tuple[] RunDCSimulation(SpiceSharpModel readerResu var list = new List>(); var export = readerResult.Exports.Find(e => e.Name == nameOfExport && e.Simulation is DC); - var simulation = readerResult.Simulations.First(s => s is DC); - simulation.ExportSimulationData += (sender, e) => + var simulation = readerResult.Simulations.First(s => s is DC d); + simulation.EventExportData += (sender, e) => { - list.Add(new Tuple(e.GetSweepValues().First(), export.Extract())); + list.Add(new Tuple(((DC)simulation).GetCurrentSweepValue().Last(), export.Extract())); }; - simulation.Run(readerResult.Circuit); + var codes = simulation.Run(readerResult.Circuit, -1); + var attached = simulation.AttachEvents(codes); + attached.ToArray(); // eval return list.ToArray(); } diff --git a/src/SpiceSharpParser.IntegrationTests/Common/CaseSensitivityTests.cs b/src/SpiceSharpParser.IntegrationTests/Common/CaseSensitivityTests.cs index a13f145d..cce88875 100644 --- a/src/SpiceSharpParser.IntegrationTests/Common/CaseSensitivityTests.cs +++ b/src/SpiceSharpParser.IntegrationTests/Common/CaseSensitivityTests.cs @@ -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; @@ -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] @@ -153,8 +158,11 @@ public void When_DistributionNameSensitive_Negative_Expect_Exception() reader.Settings.CaseSensitivity.IsDistributionNameCaseSensitive = true; var spiceModel = reader.Read(parseResult.FinalModel); - Assert.Throws(() => - spiceModel.Simulations[0].Run(spiceModel.Circuit)); + var codes = spiceModel.Simulations[0].Run(spiceModel.Circuit, -1); + codes = spiceModel.Simulations[0].AttachEvents(codes); + + + Assert.Throws(() => codes.ToArray()); } [Fact] @@ -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); } @@ -291,7 +299,7 @@ public void ComponentNamesException() reader.Settings.CaseSensitivity.IsEntityNamesCaseSensitive = true; var spiceModel = reader.Read(parseResult.FinalModel); - Assert.Throws(() => RunOpSimulation(spiceModel, "I(r1)")); + Assert.Throws(() => RunOpSimulation(spiceModel, "I(r1)")); } [Fact] diff --git a/src/SpiceSharpParser.IntegrationTests/DotStatements/PrintTests.cs b/src/SpiceSharpParser.IntegrationTests/DotStatements/PrintTests.cs index b2a35871..4c345ade 100644 --- a/src/SpiceSharpParser.IntegrationTests/DotStatements/PrintTests.cs +++ b/src/SpiceSharpParser.IntegrationTests/DotStatements/PrintTests.cs @@ -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); } @@ -164,7 +163,6 @@ public void When_PrintOpWithoutArgumentsWithoutFilter_Expect_Reference() 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); } diff --git a/src/SpiceSharpParser.IntegrationTests/SpiceSharpParser.IntegrationTests.csproj b/src/SpiceSharpParser.IntegrationTests/SpiceSharpParser.IntegrationTests.csproj index b01db443..779e77f2 100644 --- a/src/SpiceSharpParser.IntegrationTests/SpiceSharpParser.IntegrationTests.csproj +++ b/src/SpiceSharpParser.IntegrationTests/SpiceSharpParser.IntegrationTests.csproj @@ -16,21 +16,21 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - + + + + + - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/SpiceSharpParser.IntegrationTests/Waveforms/PulseTests.cs b/src/SpiceSharpParser.IntegrationTests/Waveforms/PulseTests.cs index 53563f4a..bf209b72 100644 --- a/src/SpiceSharpParser.IntegrationTests/Waveforms/PulseTests.cs +++ b/src/SpiceSharpParser.IntegrationTests/Waveforms/PulseTests.cs @@ -22,7 +22,7 @@ public void Test01() var simulation = netlist.Simulations.First(s => s is Transient); bool riseHit = false, risenHit = false, fallHit = false, fallenHit = false; - simulation.ExportSimulationData += (sender, args) => + simulation.EventExportData += (sender, args) => { if (Math.Abs(args.Time - 0.2) < 1e-12) riseHit = true; @@ -34,7 +34,8 @@ public void Test01() fallenHit = true; }; - simulation.Run(netlist.Circuit); + var events = simulation.Run(netlist.Circuit); + simulation.AttachEvents(events).ToArray(); Assert.True(riseHit); Assert.True(risenHit); @@ -57,7 +58,7 @@ public void Test02() var simulation = netlist.Simulations.First(s => s is Transient); bool riseHit = false, risenHit = false, fallHit = false, fallenHit = false; - simulation.ExportSimulationData += (sender, args) => + simulation.EventExportData += (sender, args) => { if (Math.Abs(args.Time - 0.2) < 1e-12) riseHit = true; @@ -69,7 +70,12 @@ public void Test02() fallenHit = true; }; - simulation.Run(netlist.Circuit); + + var events = simulation.Run(netlist.Circuit); + var codes = simulation.AttachEvents(events); + + //eval + codes.ToArray(); Assert.True(riseHit); Assert.True(risenHit); diff --git a/src/SpiceSharpParser.IntegrationTests/Waveforms/PwlTests.cs b/src/SpiceSharpParser.IntegrationTests/Waveforms/PwlTests.cs index 59b45a1c..7bff3038 100644 --- a/src/SpiceSharpParser.IntegrationTests/Waveforms/PwlTests.cs +++ b/src/SpiceSharpParser.IntegrationTests/Waveforms/PwlTests.cs @@ -27,7 +27,7 @@ public void Test01() var wasHit1 = false; var wasHit2 = false; - simulation.ExportSimulationData += (sender, args) => + simulation.EventExportData += (sender, args) => { if (args.Time == 1.111) { @@ -39,10 +39,13 @@ public void Test01() wasHit2 = true; } - Assert.True(EqualsWithTol(2.0, args.GetVoltage("a"))); + Assert.True(EqualsWithTol(2.0, simulation.GetVoltage("a"))); }; - simulation.Run(netlist.Circuit); + var codes = simulation.Run(netlist.Circuit); + var withEvents = simulation.AttachEvents(codes); + + withEvents.ToArray(); //eval Assert.True(wasHit1); Assert.True(wasHit2); diff --git a/src/SpiceSharpParser.IntegrationTests/Waveforms/SineTests.cs b/src/SpiceSharpParser.IntegrationTests/Waveforms/SineTests.cs index 5e877f33..67122e90 100644 --- a/src/SpiceSharpParser.IntegrationTests/Waveforms/SineTests.cs +++ b/src/SpiceSharpParser.IntegrationTests/Waveforms/SineTests.cs @@ -25,9 +25,9 @@ public void Test01(double offset, double amplitude, double frequency, double del frequency = 2.0 * Math.PI; phase = phase * Math.PI / 180; - simulation.ExportSimulationData += (sender, args) => + simulation.EventExportData += (sender, args) => { - var time = args.Time; + var time = ((Transient)simulation).Time; time -= delay; // Calculate sine wave result (no offset) @@ -43,10 +43,12 @@ public void Test01(double offset, double amplitude, double frequency, double del // Return result (with offset) var expected = offset + result; - Assert.True(EqualsWithTol(expected, args.GetVoltage("1"))); + Assert.True(EqualsWithTol(expected, simulation.GetVoltage("1"))); }; - simulation.Run(netlist.Circuit); + foreach (var code in simulation.AttachEvents(simulation.Run(netlist.Circuit))) + { + } } @@ -65,7 +67,7 @@ public void Test02(double offset, double amplitude, double frequency, double del frequency = 2.0 * Math.PI; phase = phase * Math.PI / 180; - simulation.ExportSimulationData += (sender, args) => + simulation.EventExportData += (sender, args) => { var time = args.Time; time -= delay; @@ -83,10 +85,14 @@ public void Test02(double offset, double amplitude, double frequency, double del // Return result (with offset) var expected = offset + result; - Assert.True(EqualsWithTol(expected, args.GetVoltage("1"))); + Assert.True(EqualsWithTol(expected, simulation.GetVoltage("1"))); }; - simulation.Run(netlist.Circuit); + var events = simulation.Run(netlist.Circuit); + foreach (var code in simulation.AttachEvents(events)) + { + + } } } diff --git a/src/SpiceSharpParser.PerformanceTests/SpiceSharpParser.PerformanceTests.csproj b/src/SpiceSharpParser.PerformanceTests/SpiceSharpParser.PerformanceTests.csproj index 030e682c..bb9c6264 100644 --- a/src/SpiceSharpParser.PerformanceTests/SpiceSharpParser.PerformanceTests.csproj +++ b/src/SpiceSharpParser.PerformanceTests/SpiceSharpParser.PerformanceTests.csproj @@ -7,15 +7,15 @@ - - - + + + - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/SpiceSharpParser.Tests/ModelReaders/Spice/Readers/Controls/Simulations/MonteCarloResultTests.cs b/src/SpiceSharpParser.Tests/ModelReaders/Spice/Readers/Controls/Simulations/MonteCarloResultTests.cs index c64f2c5e..a8b5c563 100644 --- a/src/SpiceSharpParser.Tests/ModelReaders/Spice/Readers/Controls/Simulations/MonteCarloResultTests.cs +++ b/src/SpiceSharpParser.Tests/ModelReaders/Spice/Readers/Controls/Simulations/MonteCarloResultTests.cs @@ -1,4 +1,5 @@ using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.Controls.Simulations; using Xunit; @@ -11,8 +12,8 @@ public void CollectMinMax() { var monteCarloResult = new MonteCarloResult(); - var op1 = new OP("op1"); - var op2 = new OP("op2"); + var op1 = new OpWithEvents("op1"); + var op2 = new OpWithEvents("op2"); monteCarloResult.Collect(op1, 1); monteCarloResult.Collect(op1, 2); @@ -31,7 +32,7 @@ public void GetPlotMax() { var monteCarloResult = new MonteCarloResult(); - var sim = new OP("op1"); + var sim = new OpWithEvents("op1"); monteCarloResult.Collect(sim, -1); monteCarloResult.Collect(sim, 4); @@ -47,8 +48,8 @@ public void GetPlotMaxMoreBins() { var monteCarloResult = new MonteCarloResult(); - var sim = new OP("op1"); - var sim2 = new OP("op2"); + var sim = new OpWithEvents("op1"); + var sim2 = new OpWithEvents("op2"); monteCarloResult.Collect(sim, -1); monteCarloResult.Collect(sim, 4); @@ -65,7 +66,7 @@ public void GetPlotMin() { var monteCarloResult = new MonteCarloResult(); - var sim = new OP("op1"); + var sim = new OpWithEvents("op1"); monteCarloResult.Collect(sim, -1); monteCarloResult.Collect(sim, 4); @@ -81,8 +82,8 @@ public void GetPlotMinMoreBins() { var monteCarloResult = new MonteCarloResult(); - var sim = new OP("op1"); - var sim2 = new OP("op2"); + var sim = new OpWithEvents("op1"); + var sim2 = new OpWithEvents("op2"); monteCarloResult.Collect(sim, -1); monteCarloResult.Collect(sim, 4); diff --git a/src/SpiceSharpParser.Tests/SpiceSharpParser.Tests.csproj b/src/SpiceSharpParser.Tests/SpiceSharpParser.Tests.csproj index 1b46625d..bd066ce8 100644 --- a/src/SpiceSharpParser.Tests/SpiceSharpParser.Tests.csproj +++ b/src/SpiceSharpParser.Tests/SpiceSharpParser.Tests.csproj @@ -14,25 +14,25 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + all runtime; build; native; contentfiles; analyzers - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/IReadingContext.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/IReadingContext.cs index 6fdd98d3..b04b6cec 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/IReadingContext.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/IReadingContext.cs @@ -2,6 +2,7 @@ using SpiceSharp.Components; using SpiceSharp.Entities; using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.Common.Evaluation; using SpiceSharpParser.ModelReaders.Netlist.Spice.Context.Models; using SpiceSharpParser.ModelReaders.Netlist.Spice.Evaluation; @@ -88,7 +89,7 @@ public interface IReadingContext /// Should be re-evaluated before temperature. /// Simulation. /// Should log the error. - void SetParameter(IEntity entity, string parameterName, string expression, bool beforeTemperature = true, Simulation simulation = null, bool logError = false); + void SetParameter(IEntity entity, string parameterName, string expression, bool beforeTemperature = true, ISimulationWithEvents simulation = null, bool logError = false); /// /// Sets parameter of entity to value of expression. @@ -98,7 +99,7 @@ public interface IReadingContext /// Value expression. /// Should be re-evaluated before temperature. /// Simulation. - void SetParameter(IEntity entity, string parameterName, Parameter valueExpression, bool beforeTemperature = true, Simulation simulation = null); + void SetParameter(IEntity entity, string parameterName, Parameter valueExpression, bool beforeTemperature = true, ISimulationWithEvents simulation = null); /// /// Sets the initial voltage. @@ -125,8 +126,8 @@ public interface IReadingContext bool FindObject(string objectId, out IEntity entity); - ExpressionParser CreateExpressionParser(Simulation simulation); + ExpressionParser CreateExpressionParser(ISimulationWithEvents simulation); - ExpressionResolver CreateExpressionResolver(Simulation simulation); + ExpressionResolver CreateExpressionResolver(ISimulationWithEvents simulation); } } \ No newline at end of file diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/ISimulationPreparations.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/ISimulationPreparations.cs index b3e2f97c..619adc83 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/ISimulationPreparations.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/ISimulationPreparations.cs @@ -1,12 +1,13 @@ using SpiceSharp.Entities; using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using System; namespace SpiceSharpParser.ModelReaders.Netlist.Spice.Context { public interface ISimulationPreparations { - void Prepare(Simulation simulation); + void Prepare(ISimulationWithEvents simulation); void SetNodeSetVoltage(string nodeId, string expression); @@ -16,10 +17,10 @@ public interface ISimulationPreparations void SetParameterBeforeTemperature(IEntity @object, string paramName, double value); - void SetParameterBeforeTemperature(IEntity @object, string paramName, double value, Simulation simulation); + void SetParameterBeforeTemperature(IEntity @object, string paramName, double value, ISimulationWithEvents simulation); - void ExecuteActionBeforeSetup(Action action); + void ExecuteActionBeforeSetup(Action action); - void ExecuteActionAfterSetup(Action action); + void ExecuteActionAfterSetup(Action action); } } \ No newline at end of file diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Models/IModelsRegistry.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Models/IModelsRegistry.cs index 2be2b4cc..c66a878b 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Models/IModelsRegistry.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Models/IModelsRegistry.cs @@ -2,13 +2,14 @@ using System.Collections.Generic; using SpiceSharp.Entities; using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.Models.Netlist.Spice.Objects; namespace SpiceSharpParser.ModelReaders.Netlist.Spice.Context.Models { public interface IModelsRegistry { - void SetModel(Entity entity, Simulation simulation, Parameter modelNameParameter, string exceptionMessage, Action setModelAction, IReadingContext context); + void SetModel(Entity entity, ISimulationWithEvents simulation, Parameter modelNameParameter, string exceptionMessage, Action setModelAction, IReadingContext context); Model FindModel(string modelName); diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Models/IStochasticModelsRegistry.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Models/IStochasticModelsRegistry.cs index 6563c4a4..52ea20f7 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Models/IStochasticModelsRegistry.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Models/IStochasticModelsRegistry.cs @@ -1,4 +1,5 @@ using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using System; using System.Collections.Generic; @@ -20,9 +21,9 @@ void RegisterModelLot( SpiceSharpParser.Models.Netlist.Spice.Objects.Parameter tolerance, string distributionName); - Model ProvideStochasticModel(string componentName, Simulation simulation, Model model); + Model ProvideStochasticModel(string componentName, ISimulationWithEvents simulation, Model model); - Dictionary> GetStochasticModels(Simulation simulation); + Dictionary> GetStochasticModels(ISimulationWithEvents simulation); Dictionary GetStochasticModelDevParameters(string baseModel); diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Models/StochasticModelsRegistry.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Models/StochasticModelsRegistry.cs index 731c5556..06c2543b 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Models/StochasticModelsRegistry.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Models/StochasticModelsRegistry.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using SpiceSharp.Entities; -using SpiceSharp.Simulations; using SpiceSharpParser.Common; using SpiceSharpParser.Common.Validation; using SpiceSharpParser.Models.Netlist.Spice.Objects; @@ -44,7 +43,7 @@ public StochasticModelsRegistry(IEnumerable modelNamesGenerators /// /// Gets or sets the dictionary of stochastic models. /// - protected Dictionary>> StochasticModels { get; set; } = new Dictionary>>(); + protected Dictionary>> StochasticModels { get; set; } = new Dictionary>>(); /// /// Gets or sets the list of all models in the registry. @@ -150,7 +149,7 @@ public void RegisterModelLot( /// If a model is stochastic (dev, lot) then a copy of model with be returned. /// If a model is not stochastic then a raw model is returned. /// - public Model ProvideStochasticModel(string componentName, Simulation simulation, Model model) + public Model ProvideStochasticModel(string componentName, ISimulationWithEvents simulation, Model model) { if (ModelsGenerators.Any(m => m.Key == model.Name)) { @@ -182,7 +181,7 @@ public Model ProvideStochasticModel(string componentName, Simulation simulation, /// /// A dictionary of base models and their stochastic models. /// - public Dictionary> GetStochasticModels(Simulation simulation) + public Dictionary> GetStochasticModels(ISimulationWithEvents simulation) { return StochasticModels.ContainsKey(simulation) ? StochasticModels[simulation] @@ -232,7 +231,7 @@ public Dictionary GetStochasticModelLotParameter return null; } - public void SetModel(Entity entity, Simulation simulation, Parameter modelNameParameter, string exceptionMessage, Action setModelAction, IReadingContext context) + public void SetModel(Entity entity, ISimulationWithEvents simulation, Parameter modelNameParameter, string exceptionMessage, Action setModelAction, IReadingContext context) { var model = FindModelEntity(modelNameParameter.Value); @@ -291,7 +290,7 @@ public IModelsRegistry CreateChildRegistry(List generators) AllModels = new Dictionary(AllModels, StringComparerProvider.Get(IsModelNameCaseSensitive)), ModelsWithDev = new Dictionary>(ModelsWithDev), ModelsWithLot = new Dictionary>(ModelsWithLot), - StochasticModels = new Dictionary>>(StochasticModels), + StochasticModels = new Dictionary>>(StochasticModels), }; return result; diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/ReadingContext.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/ReadingContext.cs index 87bbab95..2ae38de0 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/ReadingContext.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/ReadingContext.cs @@ -259,7 +259,7 @@ public virtual void Read(Statements statements, ISpiceStatementsOrderer orderer) } } - public void SetParameter(IEntity entity, string parameterName, string expression, bool beforeTemperature = true, Simulation simulation = null, bool logError = true) + public void SetParameter(IEntity entity, string parameterName, string expression, bool beforeTemperature = true, ISimulationWithEvents simulation = null, bool logError = true) { if (entity == null) { @@ -311,7 +311,7 @@ public void SetParameter(IEntity entity, string parameterName, string expression } } - public void SetParameter(IEntity entity, string parameterName, Parameter parameter, bool beforeTemperature = true, Simulation simulation = null) + public void SetParameter(IEntity entity, string parameterName, Parameter parameter, bool beforeTemperature = true, ISimulationWithEvents simulation = null) { if (entity == null) { @@ -354,7 +354,7 @@ public void SetParameter(IEntity entity, string parameterName, Parameter paramet } } - public ExpressionParser CreateExpressionParser(Simulation simulation) + public ExpressionParser CreateExpressionParser(ISimulationWithEvents simulation) { var evalContext = simulation != null ? EvaluationContext.GetSimulationContext(simulation) @@ -369,7 +369,7 @@ public ExpressionParser CreateExpressionParser(Simulation simulation) return parser; } - public ExpressionResolver CreateExpressionResolver(Simulation simulation) + public ExpressionResolver CreateExpressionResolver(ISimulationWithEvents simulation) { var evalContext = simulation != null ? EvaluationContext.GetSimulationContext(simulation) diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/SimulationEvaluationContexts.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/SimulationEvaluationContexts.cs index c6c05d08..a01ad011 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/SimulationEvaluationContexts.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/SimulationEvaluationContexts.cs @@ -1,4 +1,5 @@ using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.ModelReaders.Netlist.Spice.Evaluation; using System; using System.Collections.Generic; @@ -13,12 +14,12 @@ public class SimulationEvaluationContexts public SimulationEvaluationContexts(EvaluationContext sourceContext) { SourceContext = sourceContext ?? throw new ArgumentNullException(nameof(sourceContext)); - Contexts = new Dictionary(); + Contexts = new Dictionary(); } protected EvaluationContext SourceContext { get; } - protected Dictionary Contexts { get; } + protected Dictionary Contexts { get; } /// /// Gets the expression context for simulation. @@ -27,7 +28,7 @@ public SimulationEvaluationContexts(EvaluationContext sourceContext) /// /// Expression context. /// - public EvaluationContext GetContext(Simulation simulation) + public EvaluationContext GetContext(ISimulationWithEvents simulation) { if (simulation == null) { diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/SimulationPreparations.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/SimulationPreparations.cs index d55d2ee1..4ce69b1f 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/SimulationPreparations.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/SimulationPreparations.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SpiceSharp.Entities; using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.ModelReaders.Netlist.Spice.Context.Updates; namespace SpiceSharpParser.ModelReaders.Netlist.Spice.Context @@ -12,26 +13,26 @@ public SimulationPreparations(EntityUpdates entityUpdates, SimulationUpdates sim { EntityUpdates = entityUpdates ?? throw new ArgumentNullException(nameof(entityUpdates)); SimulationUpdates = simulationUpdates ?? throw new ArgumentNullException(nameof(simulationUpdates)); - BeforeSetup = new List>(); - AfterSetup = new List>(); + BeforeSetup = new List>(); + AfterSetup = new List>(); } protected EntityUpdates EntityUpdates { get; } protected SimulationUpdates SimulationUpdates { get; } - protected List> BeforeSetup { get; } + protected List> BeforeSetup { get; } - protected List> AfterSetup { get; } + protected List> AfterSetup { get; } - public void Prepare(Simulation simulation) + public void Prepare(ISimulationWithEvents simulation) { if (simulation == null) { throw new ArgumentNullException(nameof(simulation)); } - simulation.BeforeSetup += (_, _) => + simulation.EventBeforeSetup += (_, _) => { foreach (var action in BeforeSetup) { @@ -39,7 +40,7 @@ public void Prepare(Simulation simulation) } }; - simulation.AfterSetup += (_, _) => + simulation.EventAfterSetup += (_, _) => { foreach (var action in AfterSetup) { @@ -99,12 +100,12 @@ public void SetICVoltage(string nodeId, string expression) }); } - public void ExecuteActionBeforeSetup(Action action) + public void ExecuteActionBeforeSetup(Action action) { BeforeSetup.Add(action); } - public void ExecuteActionAfterSetup(Action action) + public void ExecuteActionAfterSetup(Action action) { AfterSetup.Add(action); } @@ -144,7 +145,7 @@ public void SetParameterBeforeTemperature(IEntity @object, string paramName, dou EntityUpdates.Add(@object, paramName, value, true); } - public void SetParameterBeforeTemperature(IEntity @object, string paramName, double value, Simulation simulation) + public void SetParameterBeforeTemperature(IEntity @object, string paramName, double value, ISimulationWithEvents simulation) { if (@object == null) { diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Sweeps/IParameterSweepUpdater.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Sweeps/IParameterSweepUpdater.cs index d2cc42c2..03467c27 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Sweeps/IParameterSweepUpdater.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Sweeps/IParameterSweepUpdater.cs @@ -1,4 +1,5 @@ using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.Models.Netlist.Spice.Objects; using System.Collections.Generic; @@ -12,6 +13,6 @@ public interface IParameterSweepUpdater /// Simulation to set. /// Reading context. /// Parameter values. - void Update(Simulation simulation, IReadingContext context, List> parameterValues); + void Update(ISimulationWithEvents simulation, IReadingContext context, List> parameterValues); } } \ No newline at end of file diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Sweeps/ParameterSweepUpdater.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Sweeps/ParameterSweepUpdater.cs index c0150d9a..5ed39f9b 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Sweeps/ParameterSweepUpdater.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Sweeps/ParameterSweepUpdater.cs @@ -1,6 +1,7 @@ using SpiceSharp.Components; using SpiceSharp.Entities; using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.Models.Netlist.Spice.Objects.Parameters; using System; using System.Collections.Generic; @@ -16,7 +17,7 @@ public class ParameterSweepUpdater : IParameterSweepUpdater /// Reading context. /// Parameter values. public void Update( - Simulation simulation, + ISimulationWithEvents simulation, IReadingContext context, List> parameterValues) { @@ -38,7 +39,7 @@ public void Update( UpdateSweep(simulation, context, parameterValues); } - protected void UpdateSweep(Simulation simulation, IReadingContext context, List> parameterValues) + protected void UpdateSweep(ISimulationWithEvents simulation, IReadingContext context, List> parameterValues) { foreach (var paramToSet in parameterValues) { @@ -64,7 +65,7 @@ protected void UpdateSweep(Simulation simulation, IReadingContext context, List< } } - protected void SetDeviceParameter(Simulation simulation, IReadingContext context, KeyValuePair paramToSet, ReferenceParameter rp) + protected void SetDeviceParameter(ISimulationWithEvents simulation, IReadingContext context, KeyValuePair paramToSet, ReferenceParameter rp) { string objectName = rp.Name; string paramName = rp.Argument; @@ -74,7 +75,7 @@ protected void SetDeviceParameter(Simulation simulation, IReadingContext context } } - protected void SetModelParameter(Simulation simulation, IReadingContext context, KeyValuePair paramToSet, BracketParameter bp) + protected void SetModelParameter(ISimulationWithEvents simulation, IReadingContext context, KeyValuePair paramToSet, BracketParameter bp) { string modelName = bp.Name; string paramName = bp.Parameters[0].Value; @@ -90,15 +91,15 @@ protected void SetModelParameter(Simulation simulation, IReadingContext context, } } - protected void SetSimulationParameter(Simulation simulation, IReadingContext context, KeyValuePair paramToSet) + protected void SetSimulationParameter(Common.ISimulationWithEvents simulation, IReadingContext context, KeyValuePair paramToSet) { - simulation.BeforeSetup += (_, _) => + simulation.EventBeforeSetup += (_, _) => { context.EvaluationContext.SetParameter(paramToSet.Key.Value, paramToSet.Value, simulation); }; } - protected void SetIndependentSource(IEntity @entity, Simulation simulation, IReadingContext context, KeyValuePair paramToSet) + protected void SetIndependentSource(IEntity @entity, ISimulationWithEvents simulation, IReadingContext context, KeyValuePair paramToSet) { if (@entity is CurrentSource || @entity is VoltageSource) { diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Updates/EntityUpdates.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Updates/EntityUpdates.cs index 092b3217..e3d996c5 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Updates/EntityUpdates.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Updates/EntityUpdates.cs @@ -1,5 +1,6 @@ using SpiceSharp.Entities; using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.Common.Evaluation.Expressions; using SpiceSharpParser.ModelReaders.Netlist.Spice.Evaluation; using System; @@ -15,7 +16,7 @@ public EntityUpdates(bool isParameterNameCaseSensitive, EvaluationContext contex IsParameterNameCaseSensitive = isParameterNameCaseSensitive; Context = context; CommonUpdates = new ConcurrentDictionary(); - SimulationSpecificUpdates = new ConcurrentDictionary>(); + SimulationSpecificUpdates = new ConcurrentDictionary>(); SimulationEntityParametersCache = new ConcurrentDictionary(); } @@ -25,20 +26,20 @@ public EntityUpdates(bool isParameterNameCaseSensitive, EvaluationContext contex protected ConcurrentDictionary CommonUpdates { get; set; } - protected ConcurrentDictionary> SimulationSpecificUpdates { get; set; } + protected ConcurrentDictionary> SimulationSpecificUpdates { get; set; } protected ConcurrentDictionary SimulationEntityParametersCache { get; } - public void Apply(Simulation simulation) + public void Apply(ISimulationWithEvents simulation) { if (simulation == null) { throw new ArgumentNullException(nameof(simulation)); } - if (simulation is BiasingSimulation biasingSimulation) + if (simulation is ISimulationWithEvents biasingSimulation && biasingSimulation is BiasingSimulation) { - biasingSimulation.BeforeTemperature += (_, _) => + biasingSimulation.EventBeforeTemperature += (_, _) => { foreach (var entity in CommonUpdates.Keys) { @@ -46,7 +47,7 @@ public void Apply(Simulation simulation) foreach (var entityUpdate in beforeTemperature) { - EvaluationContext context = GetEntityContext(simulation, entity.Name); + EvaluationContext context = GetEntityContext(biasingSimulation, entity.Name); if (context != null) { var value = entityUpdate.GetValue(context); @@ -59,7 +60,7 @@ public void Apply(Simulation simulation) } }; - biasingSimulation.BeforeTemperature += (_, _) => + biasingSimulation.EventBeforeTemperature += (_, _) => { if (SimulationSpecificUpdates.ContainsKey(simulation)) { @@ -69,7 +70,7 @@ public void Apply(Simulation simulation) foreach (var entityUpdate in beforeTemperature) { - EvaluationContext context = GetEntityContext(simulation, entityPair.Key.Name); + EvaluationContext context = GetEntityContext(biasingSimulation, entityPair.Key.Name); if (context != null) { var value = entityUpdate.GetValue(context); @@ -85,7 +86,7 @@ public void Apply(Simulation simulation) } } - public void Add(IEntity entity, string parameterName, string expression, bool beforeTemperature, Simulation simulation) + public void Add(IEntity entity, string parameterName, string expression, bool beforeTemperature, ISimulationWithEvents simulation) { if (entity == null) { @@ -178,7 +179,7 @@ public void Add(IEntity entity, string parameterName, double value, bool beforeT } } - public void Add(IEntity entity, string parameterName, double value, bool beforeTemperature, Simulation simulation) + public void Add(IEntity entity, string parameterName, double value, bool beforeTemperature, ISimulationWithEvents simulation) { if (entity == null) { @@ -211,7 +212,7 @@ public void Add(IEntity entity, string parameterName, double value, bool beforeT } } - private EvaluationContext GetEntityContext(Simulation simulation, string entityName) + private EvaluationContext GetEntityContext(ISimulationWithEvents simulation, string entityName) { var context = Context.GetSimulationContext(simulation).Find(entityName); return context; diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Updates/SimulationUpdateAction.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Updates/SimulationUpdateAction.cs index c7b02727..5d82593f 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Updates/SimulationUpdateAction.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Updates/SimulationUpdateAction.cs @@ -1,15 +1,16 @@ using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using System; namespace SpiceSharpParser.ModelReaders.Netlist.Spice.Context.Updates { public class SimulationUpdateAction { - public SimulationUpdateAction(Action action) + public SimulationUpdateAction(Action action) { Run = action; } - public Action Run { get; private set; } + public Action Run { get; private set; } } } \ No newline at end of file diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Updates/SimulationUpdates.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Updates/SimulationUpdates.cs index e1a81907..f6150731 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Updates/SimulationUpdates.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Context/Updates/SimulationUpdates.cs @@ -1,4 +1,5 @@ using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -10,31 +11,32 @@ public class SimulationUpdates public SimulationUpdates(SimulationEvaluationContexts contexts) { Contexts = contexts; - SimulationBeforeSetupActions = new ConcurrentDictionary>(); - SimulationBeforeTemperatureActions = new ConcurrentDictionary>(); + SimulationBeforeSetupActions = new ConcurrentDictionary>(); + SimulationBeforeTemperatureActions = new ConcurrentDictionary>(); CommonBeforeSetupActions = new List(); CommonBeforeTemperatureActions = new List(); } protected SimulationEvaluationContexts Contexts { get; private set; } - protected ConcurrentDictionary> SimulationBeforeSetupActions { get; } + protected ConcurrentDictionary> SimulationBeforeSetupActions { get; } - protected ConcurrentDictionary> SimulationBeforeTemperatureActions { get; } + protected ConcurrentDictionary> SimulationBeforeTemperatureActions { get; } protected List CommonBeforeSetupActions { get; } protected List CommonBeforeTemperatureActions { get; } - public void Apply(Simulation simulation) + public void Apply(ISimulationWithEvents simulation) { if (simulation == null) { throw new ArgumentNullException(nameof(simulation)); } + ISimulationWithEvents biasingSimulation = simulation as ISimulationWithEvents; // Apply common updates - simulation.BeforeSetup += (_, _) => + biasingSimulation.EventBeforeSetup += (_, _) => { foreach (var action in CommonBeforeSetupActions) { @@ -52,10 +54,9 @@ public void Apply(Simulation simulation) } }; - BiasingSimulation biasingSimulation = simulation as BiasingSimulation; if (biasingSimulation != null) { - biasingSimulation.BeforeTemperature += (_, _) => + biasingSimulation.EventBeforeTemperature += (_, _) => { foreach (var action in CommonBeforeTemperatureActions) { @@ -75,7 +76,7 @@ public void Apply(Simulation simulation) } } - public void AddBeforeSetup(Simulation simulation, Action action) + public void AddBeforeSetup(ISimulationWithEvents simulation, Action action) { if (simulation == null) { @@ -92,7 +93,7 @@ public void AddBeforeSetup(Simulation simulation, Action action) + public void AddBeforeTemperature(ISimulationWithEvents simulation, Action action) { if (simulation == null) { @@ -109,7 +110,7 @@ public void AddBeforeTemperature(Simulation simulation, Action action) + public void AddBeforeSetup(Action action) { if (action == null) { @@ -119,7 +120,7 @@ public void AddBeforeSetup(Action acti CommonBeforeSetupActions.Add(new SimulationUpdateAction(action)); } - public void AddBeforeTemperature(Action action) + public void AddBeforeTemperature(Action action) { if (action == null) { diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Evaluation/EvaluationContext.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Evaluation/EvaluationContext.cs index ad623ae2..dc7f6415 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Evaluation/EvaluationContext.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Evaluation/EvaluationContext.cs @@ -17,7 +17,7 @@ public class EvaluationContext : IEvaluationContext private readonly SpiceNetlistCaseSensitivitySettings _caseSettings; private readonly ConcurrentDictionary _cache; private readonly SimulationEvaluationContexts _simulationEvaluationContexts; - private Simulation _simulation; + private ISimulationWithEvents _simulation; public EvaluationContext( string name, @@ -116,7 +116,7 @@ public int? Seed /// public List Children { get; set; } - public Simulation Simulation + public ISimulationWithEvents Simulation { get => _simulation; set @@ -160,7 +160,7 @@ public void SetParameter(string parameterName, double value) } } - public void SetParameter(string parameterName, double value, Simulation simulation) + public void SetParameter(string parameterName, double value, ISimulationWithEvents simulation) { if (simulation != null) { @@ -432,7 +432,7 @@ public List GetExpressionParameters(string expression, bool @throw) return ExpressionFeaturesReader.GetParameters(expression, this, @throw).ToList(); } - public EvaluationContext GetSimulationContext(Simulation simulation) + public EvaluationContext GetSimulationContext(ISimulationWithEvents simulation) { return _simulationEvaluationContexts.GetContext(simulation); } diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/ISpiceSharpModel.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/ISpiceSharpModel.cs index e5380e13..e80e0b1b 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/ISpiceSharpModel.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/ISpiceSharpModel.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using SpiceSharp; using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.Common.Validation; using SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.Controls.Exporters; using SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.Controls.Plots; @@ -19,7 +20,7 @@ public interface ISpiceSharpModel /// /// Gets the list of simulation from the netlist. /// - List Simulations { get; } + List Simulations { get; } /// /// Gets the title of the netlist. diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Common/ExportFactory.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Common/ExportFactory.cs index 136b8e84..6c503bf0 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Common/ExportFactory.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Common/ExportFactory.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.Common.Validation; using SpiceSharpParser.ModelReaders.Netlist.Spice.Context; using SpiceSharpParser.ModelReaders.Netlist.Spice.Mappings; @@ -15,7 +16,7 @@ public class ExportFactory : IExportFactory public Export Create( Parameter exportParameter, IReadingContext context, - Simulation simulation, + ISimulationWithEvents simulation, IMapper mapper) { if (exportParameter is BracketParameter bp) diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Common/IExportFactory.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Common/IExportFactory.cs index 5c70775b..40e055fe 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Common/IExportFactory.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Common/IExportFactory.cs @@ -1,4 +1,5 @@ using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.ModelReaders.Netlist.Spice.Context; using SpiceSharpParser.ModelReaders.Netlist.Spice.Mappings; using SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.Controls.Exporters; @@ -11,7 +12,7 @@ public interface IExportFactory Export Create( Parameter exportParameter, IReadingContext context, - Simulation simulation, + ISimulationWithEvents simulation, IMapper mapper); } } \ No newline at end of file diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/ExportControl.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/ExportControl.cs index 2bb423ba..c3939718 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/ExportControl.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/ExportControl.cs @@ -1,5 +1,6 @@ using SpiceSharp.Entities; using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.ModelReaders.Netlist.Spice.Context; using SpiceSharpParser.ModelReaders.Netlist.Spice.Mappings; using SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.Controls.Common; @@ -37,12 +38,12 @@ protected ExportControl(IMapper mapper, IExportFactory exportFactory) /// /// Generates a new export. /// - protected Export GenerateExport(Parameter parameter, IReadingContext context, Simulation simulation) + protected Export GenerateExport(Parameter parameter, IReadingContext context, ISimulationWithEvents simulation) { return ExportFactory.Create(parameter, context, simulation, Mapper); } - protected List CreateExportsForAllVoltageAndCurrents(Simulation simulation, IReadingContext context) + protected List CreateExportsForAllVoltageAndCurrents(ISimulationWithEvents simulation, IReadingContext context) { var result = new List(); var nodes = new List(); @@ -103,7 +104,7 @@ protected List CreateExportsForAllVoltageAndCurrents(Simulation simulati return result; } - protected List GenerateExports(ParameterCollection parameterCollection, Simulation simulation, IReadingContext context) + protected List GenerateExports(ParameterCollection parameterCollection, ISimulationWithEvents simulation, IReadingContext context) { if (parameterCollection == null || parameterCollection.Count == 0 || (parameterCollection.Count == 1 && parameterCollection[0].Value.ToLower() == "merge")) { @@ -137,7 +138,7 @@ protected List GenerateExports(ParameterCollection parameterCollection, return result; } - protected string GetFirstDimensionLabel(Simulation simulation) + protected string GetFirstDimensionLabel(ISimulationWithEvents simulation) { string firstColumnName = null; diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/CurrentExports/CurrentDecibelExport.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/CurrentExports/CurrentDecibelExport.cs index 14054e36..73042956 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/CurrentExports/CurrentDecibelExport.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/CurrentExports/CurrentDecibelExport.cs @@ -15,7 +15,7 @@ public class CurrentDecibelExport : Export /// Name of export. /// A simulation /// An identifier - public CurrentDecibelExport(string name, Simulation simulation, string source) + public CurrentDecibelExport(string name, ISimulationWithEvents simulation, string source) : base(simulation) { Name = name ?? throw new ArgumentNullException(nameof(name)); @@ -46,16 +46,6 @@ public CurrentDecibelExport(string name, Simulation simulation, string source) /// public override double Extract() { - if (!ExportImpl.IsValid) - { - if (ExceptionsEnabled) - { - throw new SpiceSharpParserException($"Current decibel export '{Name}' is invalid"); - } - - return double.NaN; - } - // TODO: Verify with Sven.... return 20.0 * Math.Log10(ExportImpl.Value.Magnitude); } diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/CurrentExports/CurrentExport.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/CurrentExports/CurrentExport.cs index 778c8be9..c30586ec 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/CurrentExports/CurrentExport.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/CurrentExports/CurrentExport.cs @@ -14,7 +14,7 @@ public class CurrentExport : Export /// Name of export. /// A simulation. /// A name of current source. - public CurrentExport(string name, Simulation simulation, string source) + public CurrentExport(string name, ISimulationWithEvents simulation, string source) : base(simulation) { Name = name ?? throw new System.NullReferenceException(nameof(name)); @@ -58,7 +58,7 @@ public CurrentExport(string name, Simulation simulation, string source) /// public override double Extract() { - if (ExportRealImpl != null) + if (ExportRealImpl != null) { if (!ExportRealImpl.IsValid) { diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/CurrentExports/CurrentImaginaryExport.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/CurrentExports/CurrentImaginaryExport.cs index 6a5a2b85..6f11d114 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/CurrentExports/CurrentImaginaryExport.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/CurrentExports/CurrentImaginaryExport.cs @@ -15,7 +15,7 @@ public class CurrentImaginaryExport : Export /// Name of export. /// A simulation. /// A name of current source. - public CurrentImaginaryExport(string name, Simulation simulation, string source) + public CurrentImaginaryExport(string name, ISimulationWithEvents simulation, string source) : base(simulation) { Name = name ?? throw new ArgumentNullException(nameof(name)); @@ -50,7 +50,7 @@ public override double Extract() { if (ExceptionsEnabled) { - throw new SpiceSharpParserException($"Current imaginary export '{Name}' is invalid"); + throw new SpiceSharpParserException($"Current imaginary export {Name} is invalid"); } return double.NaN; diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/CurrentExports/CurrentMagnitudeExport.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/CurrentExports/CurrentMagnitudeExport.cs index a3048d05..a6933872 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/CurrentExports/CurrentMagnitudeExport.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/CurrentExports/CurrentMagnitudeExport.cs @@ -15,7 +15,7 @@ public class CurrentMagnitudeExport : Export /// Name of export. /// A simulation. /// An identifier. - public CurrentMagnitudeExport(string name, Simulation simulation, string source) + public CurrentMagnitudeExport(string name, ISimulationWithEvents simulation, string source) : base(simulation) { Name = name ?? throw new ArgumentNullException(nameof(name)); @@ -50,7 +50,7 @@ public override double Extract() { if (ExceptionsEnabled) { - throw new SpiceSharpParserException($"Current magnitude export '{Name}' is invalid"); + throw new SpiceSharpParserException($"Current magnitude export {Name} is invalid"); } return double.NaN; diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/CurrentExports/CurrentPhaseExport.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/CurrentExports/CurrentPhaseExport.cs index ada42e33..58c21b1f 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/CurrentExports/CurrentPhaseExport.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/CurrentExports/CurrentPhaseExport.cs @@ -15,7 +15,7 @@ public class CurrentPhaseExport : Export /// Name of export. /// A simulation /// An identifier - public CurrentPhaseExport(string name, Simulation simulation, string source) + public CurrentPhaseExport(string name, ISimulationWithEvents simulation, string source) : base(simulation) { Name = name ?? throw new ArgumentNullException(nameof(name)); @@ -50,7 +50,7 @@ public override double Extract() { if (ExceptionsEnabled) { - throw new SpiceSharpParserException($"Current phase export '{Name}' is invalid"); + throw new SpiceSharpParserException($"Current phase export {Name} is invalid"); } return double.NaN; diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/CurrentExports/CurrentRealExport.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/CurrentExports/CurrentRealExport.cs index e03909c4..cbd96f07 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/CurrentExports/CurrentRealExport.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/CurrentExports/CurrentRealExport.cs @@ -15,7 +15,7 @@ public class CurrentRealExport : Export /// Name of export. /// A simulation /// An identifier of source - public CurrentRealExport(string name, Simulation simulation, string source) + public CurrentRealExport(string name, ISimulationWithEvents simulation, string source) : base(simulation) { Name = name ?? throw new ArgumentNullException(nameof(name)); @@ -50,7 +50,7 @@ public override double Extract() { if (ExceptionsEnabled) { - throw new SpiceSharpParserException($"Current real export '{Name}' is invalid"); + throw new SpiceSharpParserException($"Current real export {Name} is invalid"); } return double.NaN; diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/Export.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/Export.cs index 82144166..3525da8f 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/Export.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/Export.cs @@ -1,4 +1,5 @@ using SpiceSharp.Simulations; +using SpiceSharpParser.Common; namespace SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.Controls.Exporters { @@ -13,12 +14,12 @@ public abstract class Export /// /// The simulation. /// - protected Export(Simulation simulation) + protected Export(ISimulationWithEvents simulation) { Simulation = simulation; } - public Simulation Simulation { get; } + public ISimulationWithEvents Simulation { get; } /// /// Gets or sets the name. diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/InputNoiseExport.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/InputNoiseExport.cs index a0df72e0..4f9107a0 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/InputNoiseExport.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/InputNoiseExport.cs @@ -5,7 +5,7 @@ namespace SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.Controls.Exporters { public class InputNoiseExport : Export { - public InputNoiseExport(Simulation simulation) + public InputNoiseExport(ISimulationWithEvents simulation) : base(simulation) { ExportImpl = new InputNoiseDensityExport((Noise)simulation); diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/OutputNoiseExport.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/OutputNoiseExport.cs index 9703a0c8..7daeb8e5 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/OutputNoiseExport.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/OutputNoiseExport.cs @@ -5,7 +5,7 @@ namespace SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.Controls.Exporters { public class OutputNoiseExport : Export { - public OutputNoiseExport(Simulation simulation) + public OutputNoiseExport(ISimulationWithEvents simulation) : base(simulation) { ExportImpl = new OutputNoiseDensityExport((Noise)simulation); diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/PropertyExport.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/PropertyExport.cs index 7ad7b2e2..11d9b1e2 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/PropertyExport.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/PropertyExport.cs @@ -16,7 +16,7 @@ public class PropertyExport : Export /// A simulation. /// A identifier of component. /// Name of property for export. - public PropertyExport(string name, Simulation simulation, string source, string property) + public PropertyExport(string name, ISimulationWithEvents simulation, string source, string property) : base(simulation) { Name = name ?? throw new NullReferenceException(nameof(name)); @@ -52,16 +52,6 @@ public PropertyExport(string name, Simulation simulation, string source, string /// public override double Extract() { - if (!ExportRealImpl.IsValid) - { - if (ExceptionsEnabled) - { - throw new SpiceSharpParserException($"Property export {Name} is invalid"); - } - - return double.NaN; - } - return ExportRealImpl.Value; } } diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/VoltageExporter.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/VoltageExporter.cs index 47eedc2b..1240bfcb 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/VoltageExporter.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/VoltageExporter.cs @@ -33,8 +33,8 @@ public override Export CreateExport( } // Get the nodes - string node, reference = null; - string nodePath, referencePath; + string node, reference = "0"; // default ground + string nodePath, referencePath = "O"; if (parameters[0] is VectorParameter vector) { diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/VoltageExports/VoltageDecibelExport.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/VoltageExports/VoltageDecibelExport.cs index a2e978e4..88f29355 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/VoltageExports/VoltageDecibelExport.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/VoltageExports/VoltageDecibelExport.cs @@ -1,5 +1,6 @@ using SpiceSharp.Simulations; using SpiceSharpParser.Common; +using System; namespace SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.Controls.Exporters.VoltageExports { @@ -15,7 +16,7 @@ public class VoltageDecibelExport : Export /// Simulation. /// Positive node. /// Negative reference node. - public VoltageDecibelExport(string name, Simulation simulation, string node, string reference = null) + public VoltageDecibelExport(string name, ISimulationWithEvents simulation, string node, string reference = null) : base(simulation) { Name = name ?? throw new System.ArgumentNullException(nameof(name)); @@ -56,13 +57,13 @@ public override double Extract() { if (ExceptionsEnabled) { - throw new SpiceSharpParserException($"Voltage decibel export '{Name}' is invalid"); + throw new SpiceSharpParserException($"Voltage (db) export {Name} is invalid"); } return double.NaN; } - return ExportImpl.Decibels; + return Math.Log10(ExportImpl.Value.Magnitude); } } } \ No newline at end of file diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/VoltageExports/VoltageExport.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/VoltageExports/VoltageExport.cs index 768aecbe..58b54f80 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/VoltageExports/VoltageExport.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/VoltageExports/VoltageExport.cs @@ -1,4 +1,5 @@ using SpiceSharp.Simulations; +using SpiceSharpParser.Common; namespace SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.Controls.Exporters.VoltageExports { @@ -14,7 +15,7 @@ public class VoltageExport : Export /// Simulation. /// Positive node. /// Negative reference node. - public VoltageExport(string name, Simulation simulation, string node, string reference = null) + public VoltageExport(string name, ISimulationWithEvents simulation, string node, string reference = null) : base(simulation) { Name = name ?? throw new System.ArgumentNullException(nameof(name)); @@ -68,6 +69,11 @@ public override double Extract() { if (!ExportImpl.IsValid) { + if (ExceptionsEnabled) + { + throw new SpiceSharpParserException($"Voltage export {Name} is invalid"); + } + return double.NaN; } @@ -77,6 +83,11 @@ public override double Extract() { if (!ExportRealImpl.IsValid) { + if (ExceptionsEnabled) + { + throw new SpiceSharpParserException($"Voltage export {Name} is invalid"); + } + return double.NaN; } diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/VoltageExports/VoltageImaginaryExport.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/VoltageExports/VoltageImaginaryExport.cs index 1356fe9c..17625c50 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/VoltageExports/VoltageImaginaryExport.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/VoltageExports/VoltageImaginaryExport.cs @@ -15,7 +15,7 @@ public class VoltageImaginaryExport : Export /// Simulation /// Positive node /// Negative reference node - public VoltageImaginaryExport(string name, Simulation simulation, string node, string reference = null) + public VoltageImaginaryExport(string name, ISimulationWithEvents simulation, string node, string reference = null) : base(simulation) { Name = name ?? throw new System.ArgumentNullException(nameof(name)); diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/VoltageExports/VoltageMagnitudeExport.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/VoltageExports/VoltageMagnitudeExport.cs index 56c3695c..62abf959 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/VoltageExports/VoltageMagnitudeExport.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/VoltageExports/VoltageMagnitudeExport.cs @@ -15,7 +15,7 @@ public class VoltageMagnitudeExport : Export /// Simulation /// Positive node /// Negative reference node - public VoltageMagnitudeExport(string name, Simulation simulation, string node, string reference = null) + public VoltageMagnitudeExport(string name, ISimulationWithEvents simulation, string node, string reference = null) : base(simulation) { Name = name ?? throw new System.ArgumentNullException(nameof(name)); diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/VoltageExports/VoltagePhaseExport.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/VoltageExports/VoltagePhaseExport.cs index 09d35e5f..f98c781e 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/VoltageExports/VoltagePhaseExport.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/VoltageExports/VoltagePhaseExport.cs @@ -15,7 +15,7 @@ public class VoltagePhaseExport : Export /// Simulation /// Positive node /// Negative reference node - public VoltagePhaseExport(string name, Simulation simulation, string node, string reference = null) + public VoltagePhaseExport(string name, ISimulationWithEvents simulation, string node, string reference = null) : base(simulation) { Name = name ?? throw new System.ArgumentNullException(nameof(name)); @@ -61,8 +61,7 @@ public override double Extract() return double.NaN; } - - return ExportImpl.Phase; + return ExportImpl.Value.Magnitude; } } } \ No newline at end of file diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/VoltageExports/VoltageRealExport.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/VoltageExports/VoltageRealExport.cs index fdced063..aef7475f 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/VoltageExports/VoltageRealExport.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Exporters/VoltageExports/VoltageRealExport.cs @@ -15,7 +15,7 @@ public class VoltageRealExport : Export /// Simulation /// Positive node /// Negative reference node - public VoltageRealExport(string name, Simulation simulation, string node, string reference = null) + public VoltageRealExport(string name, ISimulationWithEvents simulation, string node, string reference = null) : base(simulation) { Name = name ?? throw new System.ArgumentNullException(nameof(name)); @@ -56,7 +56,7 @@ public override double Extract() { if (ExceptionsEnabled) { - throw new SpiceSharpParserException($"Voltage real export '{Name}' is invalid"); + throw new SpiceSharpParserException($"Voltage real export {Name} is invalid"); } return double.NaN; diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/PlotControl.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/PlotControl.cs index 2a506c07..9c80af9f 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/PlotControl.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/PlotControl.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.Common.Validation; using SpiceSharpParser.ModelReaders.Netlist.Spice.Context; using SpiceSharpParser.ModelReaders.Netlist.Spice.Mappings; @@ -87,7 +88,7 @@ public override void Read(Control statement, IReadingContext context) } } - private IEnumerable FilterSimulations(IEnumerable simulations, string type) + private IEnumerable FilterSimulations(IEnumerable simulations, string type) { var typeLowered = type.ToLower(); @@ -103,7 +104,7 @@ private IEnumerable FilterSimulations(IEnumerable simula } } - private void CreatePlot(string plotImage, ParameterCollection parameters, IReadingContext context, Simulation simulation) + private void CreatePlot(string plotImage, ParameterCollection parameters, IReadingContext context, ISimulationWithEvents simulation) { var plot = new XyPlot(simulation.Name); List exports = GenerateExports(parameters, simulation, context); @@ -113,11 +114,11 @@ private void CreatePlot(string plotImage, ParameterCollection parameters, IReadi plot.Series.Add(new Series(export.Name)); } - simulation.ExportSimulationData += (sender, args) => CreatePointForSeries(simulation, context, args, exports, plot.Series); - simulation.AfterExecute += (sender, args) => AddPlotToResultIfValid(plotImage, context, plot, simulation); + simulation.EventExportData += (sender, args) => CreatePointForSeries(simulation, context, args, exports, plot.Series); + simulation.EventAfterExecute += (sender, args) => AddPlotToResultIfValid(plotImage, context, plot, simulation); } - private void CreatePlot(string plotImage, ParameterCollection parameters, IReadingContext context, IEnumerable simulations) + private void CreatePlot(string plotImage, ParameterCollection parameters, IReadingContext context, IEnumerable simulations) { var plot = new XyPlot($"Merged: {plotImage}"); foreach (var simulation in simulations) @@ -131,13 +132,13 @@ private void CreatePlot(string plotImage, ParameterCollection parameters, IReadi } plot.Series.AddRange(series); - simulation.ExportSimulationData += (sender, args) => CreatePointForSeries(simulation, context, args, exports, series); + simulation.EventExportData += (sender, args) => CreatePointForSeries(simulation, context, args, exports, series); } context.Result.XyPlots.Add(plot); } - private void AddPlotToResultIfValid(string plotImage, IReadingContext context, XyPlot plot, Simulation simulation) + private void AddPlotToResultIfValid(string plotImage, IReadingContext context, XyPlot plot, ISimulationWithEvents simulation) { for (int i = plot.Series.Count - 1; i >= 0; i--) { @@ -158,38 +159,11 @@ private void AddPlotToResultIfValid(string plotImage, IReadingContext context, X } } - private void CreatePointForSeries(Simulation simulation, IReadingContext context, ExportDataEventArgs eventArgs, List exports, List series) + private void CreatePointForSeries(ISimulationWithEvents simulation, IReadingContext context, object eventArgs, List exports, List series) { double x = 0; - if (simulation is Transient) - { - x = eventArgs.Time; - } - - if (simulation is AC) - { - x = eventArgs.Frequency; - } - - if (simulation is Noise) - { - x = eventArgs.Frequency; - } - - if (simulation is DC) - { - if (eventArgs.GetSweepValues().Length > 1) - { - // TODO: Add support for DC Sweeps > 1 - context.Result.ValidationResult.AddError( - ValidationEntrySource.Reader, - ".PLOT doesn't support sweep count > 1"); - return; - } - - x = eventArgs.GetSweepValues().FirstOrDefault(); - } + //TODO for (var i = 0; i < exports.Count; i++) { diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/PrintControl.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/PrintControl.cs index 4db1b6be..ced5fc24 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/PrintControl.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/PrintControl.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.Common.Validation; using SpiceSharpParser.ModelReaders.Netlist.Spice.Context; using SpiceSharpParser.ModelReaders.Netlist.Spice.Mappings; @@ -52,7 +53,7 @@ public override void Read(Control statement, IReadingContext context) string printImage = statement.Name + ":" + statement.Parameters; if (type != null && SupportedPrintTypes.Contains(type)) { - foreach (Simulation simulation in FilterSimulations(context.Result.Simulations, type)) + foreach (ISimulationWithEvents simulation in FilterSimulations(context.Result.Simulations, type)) { string firstColumnName = GetFirstDimensionLabel(simulation); CreatePrint(printImage, statement.Parameters.Skip(1), context, simulation, firstColumnName, true); @@ -60,7 +61,7 @@ public override void Read(Control statement, IReadingContext context) } else { - foreach (Simulation simulation in context.Result.Simulations) + foreach (ISimulationWithEvents simulation in context.Result.Simulations) { string firstColumnName = GetFirstDimensionLabel(simulation); CreatePrint(printImage, statement.Parameters, context, simulation, firstColumnName, false); @@ -68,32 +69,25 @@ public override void Read(Control statement, IReadingContext context) } } - private static void CreateRowInPrint(ref int rowIndex, Simulation simulation, IReadingContext context, ExportDataEventArgs eventArgs, List exports, Print print) + private static void CreateRowInPrint(ref int rowIndex, ISimulationWithEvents simulation, IReadingContext context, ExportData eventArgs, List exports, Print print) { Row row = new Row(rowIndex++); double x = 0; - if (simulation is Transient) + if (simulation is Transient t) { - x = eventArgs.Time; + x = t.Time; } - if (simulation is AC) + if (simulation is AC a) { - x = eventArgs.Frequency; + x = a.Frequency; } - if (simulation is DC) + if (simulation is DC d) { - if (eventArgs.GetSweepValues().Length > 1) - { - // TODO: Add support for DC Sweeps > 1 - context.Result.ValidationResult.AddError(ValidationEntrySource.Reader, ".PRINT doesn't support sweep count > 1"); - return; - } - - x = eventArgs.GetSweepValues().FirstOrDefault(); + x = d.GetCurrentSweepValue().Last(); } if (!(simulation is OP)) @@ -108,7 +102,7 @@ private static void CreateRowInPrint(ref int rowIndex, Simulation simulation, IR double val = exports[i].Extract(); row.Columns.Add(val); } - catch (Exception) + catch (Exception ex) { row.Columns.Add(double.NaN); } @@ -117,7 +111,7 @@ private static void CreateRowInPrint(ref int rowIndex, Simulation simulation, IR print.Rows.Add(row); } - private IEnumerable FilterSimulations(IEnumerable simulations, string type) + private IEnumerable FilterSimulations(IEnumerable simulations, string type) { var typeLowered = type.ToLower(); @@ -133,7 +127,7 @@ private IEnumerable FilterSimulations(IEnumerable simula } } - private void CreatePrint(string printImage, ParameterCollection parameters, IReadingContext context, Simulation simulation, string firstColumnName, bool filterSpecified) + private void CreatePrint(string printImage, ParameterCollection parameters, IReadingContext context, ISimulationWithEvents simulation, string firstColumnName, bool filterSpecified) { var print = new Print(simulation.Name); @@ -150,11 +144,11 @@ private void CreatePrint(string printImage, ParameterCollection parameters, IRea } int rowIndex = 0; - simulation.ExportSimulationData += (_, args) => CreateRowInPrint(ref rowIndex, simulation, context, args, exports, print); - simulation.AfterExecute += (_, _) => AddPrintToResultIfValid(printImage, context, print, simulation, filterSpecified); + simulation.EventExportData += (_, args) => CreateRowInPrint(ref rowIndex, simulation, context, args, exports, print); + simulation.EventAfterExecute += (_, _) => AddPrintToResultIfValid(printImage, context, print, simulation, filterSpecified); } - private void AddPrintToResultIfValid(string printImage, IReadingContext context, Print print, Simulation simulation, bool filterSpecified) + private void AddPrintToResultIfValid(string printImage, IReadingContext context, Print print, ISimulationWithEvents simulation, bool filterSpecified) { if (!filterSpecified) { diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/SaveControl.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/SaveControl.cs index 1997f096..33386f3e 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/SaveControl.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/SaveControl.cs @@ -4,6 +4,7 @@ using System.Reflection; using SpiceSharp.Entities; using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.Common.Validation; using SpiceSharpParser.ModelReaders.Netlist.Spice.Context; using SpiceSharpParser.ModelReaders.Netlist.Spice.Mappings; @@ -228,7 +229,7 @@ private void CreateAcSweepPlot(string variableName, List exports, IReadi private void AddOpPointToSeries(Context.Sweeps.ParameterSweep firstParameterSweep, Export export, IReadingContext context, Series series) { - export.Simulation.ExportSimulationData += (object sender, ExportDataEventArgs e) => + export.Simulation.EventExportData += (object sender, ExportData e) => { var expressionContext = context.EvaluationContext.GetSimulationContext(export.Simulation); var firstParameterSweepParameter = expressionContext.Parameters[firstParameterSweep.Parameter.Value]; @@ -240,7 +241,7 @@ private void AddOpPointToSeries(Context.Sweeps.ParameterSweep firstParameterSwee private void AddTranPointsToSeries(Export export, Series series) { - export.Simulation.ExportSimulationData += (object sender, ExportDataEventArgs e) => + export.Simulation.EventExportData += (object sender, ExportData e) => { series.Points.Add(new Point() { X = e.Time, Y = export.Extract() }); }; @@ -248,7 +249,7 @@ private void AddTranPointsToSeries(Export export, Series series) private void AddAcPointsToSeries(Export export, Series series) { - export.Simulation.ExportSimulationData += (object sender, ExportDataEventArgs e) => + export.Simulation.EventExportData += (object sender, ExportData e) => { series.Points.Add(new Point() { X = e.Frequency, Y = export.Extract() }); }; @@ -340,7 +341,7 @@ private void AddLetExport(IReadingContext context, Type simulationType, SinglePa } } - private IEnumerable Filter(IEnumerable simulations, Type simulationType) + private IEnumerable Filter(IEnumerable simulations, Type simulationType) { if (simulationType == null) { diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/ACControl.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/ACControl.cs index 22e23320..4ebc53c8 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/ACControl.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/ACControl.cs @@ -1,4 +1,5 @@ using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.Common.Validation; using SpiceSharpParser.ModelReaders.Netlist.Spice.Context; using SpiceSharpParser.ModelReaders.Netlist.Spice.Mappings; @@ -27,7 +28,7 @@ public override void Read(Control statement, IReadingContext context) CreateSimulations(statement, context, CreateAcSimulation); } - private AC CreateAcSimulation(string name, Control statement, IReadingContext context) + private ACWithEvents CreateAcSimulation(string name, Control statement, IReadingContext context) { switch (statement.Parameters.Count) { @@ -47,7 +48,7 @@ private AC CreateAcSimulation(string name, Control statement, IReadingContext co return null; } - AC ac; + ACWithEvents ac; string type = statement.Parameters.Get(0).Value.ToLower(); var numberSteps = context.Evaluator.EvaluateDouble(statement.Parameters.Get(1)); @@ -56,9 +57,9 @@ private AC CreateAcSimulation(string name, Control statement, IReadingContext co switch (type) { - case "lin": ac = new AC(name, new LinearSweep(start, stop, (int)numberSteps)); break; - case "oct": ac = new AC(name, new OctaveSweep(start, stop, (int)numberSteps)); break; - case "dec": ac = new AC(name, new DecadeSweep(start, stop, (int)numberSteps)); break; + case "lin": ac = new ACWithEvents(name, new LinearSweep(start, stop, (int)numberSteps)); break; + case "oct": ac = new ACWithEvents(name, new OctaveSweep(start, stop, (int)numberSteps)); break; + case "dec": ac = new ACWithEvents(name, new DecadeSweep(start, stop, (int)numberSteps)); break; default: context.Result.ValidationResult.AddError(ValidationEntrySource.Reader, "LIN, DEC or OCT expected", statement.LineInfo); return null; diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/DCControl.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/DCControl.cs index 77e16f08..6ec40fba 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/DCControl.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/DCControl.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.Common.Validation; using SpiceSharpParser.ModelReaders.Netlist.Spice.Context; using SpiceSharpParser.ModelReaders.Netlist.Spice.Mappings; @@ -29,7 +30,7 @@ public override void Read(Control statement, IReadingContext context) CreateSimulations(statement, context, CreateDCSimulation); } - private DC CreateDCSimulation(string name, Control statement, IReadingContext context) + private ISimulationWithEvents CreateDCSimulation(string name, Control statement, IReadingContext context) { int count = statement.Parameters.Count / 4; switch (statement.Parameters.Count - (4 * count)) @@ -69,7 +70,7 @@ private DC CreateDCSimulation(string name, Control statement, IReadingContext co sweeps.Add(sweep); } - DC dc = new DC(name, sweeps); + DcWithEvents dc = new DcWithEvents(name, sweeps); // TODO: Consult with Sven /*dc.OnParameterSearch += (sender, e) => diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Decorators/CircuitTemperatureSimulationDecorator.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Decorators/CircuitTemperatureSimulationDecorator.cs index 972b7518..c5f937a8 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Decorators/CircuitTemperatureSimulationDecorator.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Decorators/CircuitTemperatureSimulationDecorator.cs @@ -1,4 +1,5 @@ using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using System; namespace SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.Controls.Simulations.Decorators @@ -12,16 +13,19 @@ public CircuitTemperatureSimulationDecorator(double circuitTemperature) _circuitTemperature = circuitTemperature; } - public Simulation Decorate(Simulation simulation) + public ISimulationWithEvents Decorate(ISimulationWithEvents simulation) { - EventHandler setState = (object sender, TemperatureStateEventArgs e) => + OnBeforeTemperature setState = (object sender, TemperatureStateEventArgs e) => { - e.State.Temperature = _circuitTemperature; + if (e != null) + { + e.State.Temperature = _circuitTemperature; + } }; - if (simulation is BiasingSimulation biasingSimulation) + if (simulation is ISimulationWithEvents biasingSimulation) { - biasingSimulation.BeforeTemperature += setState; + biasingSimulation.EventBeforeTemperature += setState; } return simulation; diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Decorators/EnableStochasticModelsSimulationDecorator.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Decorators/EnableStochasticModelsSimulationDecorator.cs index 1922ca6c..46a45e6a 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Decorators/EnableStochasticModelsSimulationDecorator.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Decorators/EnableStochasticModelsSimulationDecorator.cs @@ -21,11 +21,11 @@ public EnableStochasticModelsSimulationDecorator(IReadingContext context) _context = context; } - public Simulation Decorate(Simulation simulation) + public ISimulationWithEvents Decorate(ISimulationWithEvents simulation) { if (_context.ModelsRegistry is IStochasticModelsRegistry modelsRegistry) { - simulation.BeforeExecute += (object sender, BeforeExecuteEventArgs arg) => + simulation.EventBeforeExecute += (object sender, object arg) => { foreach (var stochasticModels in modelsRegistry.GetStochasticModels(simulation)) { @@ -53,7 +53,7 @@ public Simulation Decorate(Simulation simulation) return simulation; } - private void SetModelLotModelParameters(Simulation simulation, string baseModel, IEntity componentModel, Dictionary stochasticLotParameters) + private void SetModelLotModelParameters(ISimulationWithEvents simulation, string baseModel, IEntity componentModel, Dictionary stochasticLotParameters) { var comparer = StringComparerProvider.Get(false); foreach (var stochasticParameter in stochasticLotParameters) @@ -74,7 +74,7 @@ private void SetModelLotModelParameters(Simulation simulation, string baseModel, } } - private void SetModelDevModelParameters(Simulation simulation, IEntity componentModel, Dictionary stochasticDevParameters) + private void SetModelDevModelParameters(ISimulationWithEvents simulation, IEntity componentModel, Dictionary stochasticDevParameters) { foreach (var stochasticParameter in stochasticDevParameters) { diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Decorators/NominalTemperatureSimulationDecorator.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Decorators/NominalTemperatureSimulationDecorator.cs index 2b5105b5..c0c18abf 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Decorators/NominalTemperatureSimulationDecorator.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Decorators/NominalTemperatureSimulationDecorator.cs @@ -1,5 +1,5 @@ using SpiceSharp.Simulations; -using System; +using SpiceSharpParser.Common; namespace SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.Controls.Simulations.Decorators { @@ -12,16 +12,16 @@ public NominalTemperatureSimulationDecorator(double nominalTemperatureInKelvins) _nominalTemperatureInKelvins = nominalTemperatureInKelvins; } - public Simulation Decorate(Simulation simulation) + public ISimulationWithEvents Decorate(ISimulationWithEvents simulation) { - EventHandler setState = (_, e) => + OnBeforeTemperature setState = (_, e) => { e.State.NominalTemperature = _nominalTemperatureInKelvins; }; if (simulation is BiasingSimulation biasingSimulation) { - biasingSimulation.BeforeTemperature += setState; + simulation.EventBeforeTemperature += setState; } return simulation; diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Factories/CreateSimulationsForAllParameterSweepsAndTemperaturesFactory.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Factories/CreateSimulationsForAllParameterSweepsAndTemperaturesFactory.cs index 168d079c..4aac18ca 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Factories/CreateSimulationsForAllParameterSweepsAndTemperaturesFactory.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Factories/CreateSimulationsForAllParameterSweepsAndTemperaturesFactory.cs @@ -1,5 +1,4 @@ using SpiceSharp; -using SpiceSharp.Simulations; using SpiceSharpParser.Common; using SpiceSharpParser.ModelReaders.Netlist.Spice.Context; using SpiceSharpParser.ModelReaders.Netlist.Spice.Context.Sweeps; @@ -34,9 +33,9 @@ public CreateSimulationsForAllParameterSweepsAndTemperaturesFactory(ICreateSimul /// Statement. /// Context. /// Create simulation factory. - public List CreateSimulations(Control statement, IReadingContext context, Func createSimulation) + public List CreateSimulations(Control statement, IReadingContext context, Func createSimulation) { - var result = new List(); + var result = new List(); ProcessTempParameterSweep(context); @@ -66,7 +65,7 @@ public List CreateSimulations(Control statement, IReadingContext con { int[] indexes = NumberSystem.GetValueInSystem(i, system); - Func createSimulationWithSweepParametersFactory = + Func createSimulationWithSweepParametersFactory = (name, control, modifiedContext) => { List> parameterValues = @@ -143,7 +142,7 @@ protected void ProcessTempParameterSweep(IReadingContext context) } } - protected void SetSweepSimulation(IReadingContext context, List> parameterValues, Simulation simulation) + protected void SetSweepSimulation(IReadingContext context, List> parameterValues, ISimulationWithEvents simulation) { ParameterUpdater.Update(simulation, context, parameterValues); } diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Factories/CreateSimulationsForAllTemperaturesFactory.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Factories/CreateSimulationsForAllTemperaturesFactory.cs index a7855d2f..df9e3c08 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Factories/CreateSimulationsForAllTemperaturesFactory.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Factories/CreateSimulationsForAllTemperaturesFactory.cs @@ -1,5 +1,6 @@ using SpiceSharp; using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.ModelReaders.Netlist.Spice.Context; using SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.Controls.Simulations.Decorators; using SpiceSharpParser.Models.Netlist.Spice.Objects; @@ -11,9 +12,9 @@ namespace SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.Controls.Simulatio { public class CreateSimulationsForAllTemperaturesFactory : ICreateSimulationsForAllTemperaturesFactory { - public List CreateSimulations(Control statement, IReadingContext context, Func createSimulation) + public List CreateSimulations(Control statement, IReadingContext context, Func createSimulation) { - var result = new List(); + var result = new List(); if (context.SimulationConfiguration.TemperaturesInKelvins.Count > 0) { @@ -30,7 +31,7 @@ public List CreateSimulations(Control statement, IReadingContext con return result; } - protected Simulation CreateSimulationForTemperature(Control statement, IReadingContext context, Func createSimulation, double? temp) + protected ISimulationWithEvents CreateSimulationForTemperature(Control statement, IReadingContext context, Func createSimulation, double? temp) { var simulation = createSimulation(GetSimulationName(context, statement, temp), statement, context); @@ -40,7 +41,7 @@ protected Simulation CreateSimulationForTemperature(Control statement, IReadingC return simulation; } - protected void SetTempVariable(IReadingContext context, double? operatingTemperatureInKelvins, Simulation simulation) + protected void SetTempVariable(IReadingContext context, double? operatingTemperatureInKelvins, ISimulationWithEvents simulation) { double temp; if (operatingTemperatureInKelvins.HasValue) @@ -54,14 +55,14 @@ protected void SetTempVariable(IReadingContext context, double? operatingTempera if (simulation is BiasingSimulation biasingSimulation) { - biasingSimulation.BeforeTemperature += (_, _) => + simulation.EventBeforeTemperature += (_, _) => { context.EvaluationContext.SetParameter("TEMP", temp, simulation); }; } } - protected void SetSimulationTemperatures(Simulation simulation, double? operatingTemperatureInKelvins, double? nominalTemperatureInKelvins) + protected void SetSimulationTemperatures(ISimulationWithEvents simulation, double? operatingTemperatureInKelvins, double? nominalTemperatureInKelvins) { if (operatingTemperatureInKelvins.HasValue) { diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Factories/CreateSimulationsForMonteCarloFactory.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Factories/CreateSimulationsForMonteCarloFactory.cs index cb485947..a9492fc5 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Factories/CreateSimulationsForMonteCarloFactory.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Factories/CreateSimulationsForMonteCarloFactory.cs @@ -1,4 +1,5 @@ using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.ModelReaders.Netlist.Spice.Context; using SpiceSharpParser.ModelReaders.Netlist.Spice.Mappings; using SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.Controls.Common; @@ -43,14 +44,14 @@ public CreateSimulationsForMonteCarloFactory( /// Statement. /// Context. /// Simulation factory. - public List Create(Control statement, IReadingContext context, Func createSimulation) + public List Create(Control statement, IReadingContext context, Func createSimulation) { context.Result.MonteCarloResult.Enabled = true; context.Result.MonteCarloResult.Seed = context.SimulationConfiguration.MonteCarloConfiguration.Seed; context.Result.MonteCarloResult.OutputVariable = context.SimulationConfiguration.MonteCarloConfiguration.OutputVariable.Value; context.Result.MonteCarloResult.Function = context.SimulationConfiguration.MonteCarloConfiguration.Function; - var result = new List(); + var result = new List(); for (var i = 0; i < context.SimulationConfiguration.MonteCarloConfiguration.Runs; i++) { @@ -62,7 +63,7 @@ public List Create(Control statement, IReadingContext context, Func< return result; } - protected void AttachMonteCarloDataGathering(IReadingContext context, IEnumerable simulations) + protected void AttachMonteCarloDataGathering(IReadingContext context, IEnumerable simulations) { foreach (var simulation in simulations) { @@ -70,11 +71,11 @@ protected void AttachMonteCarloDataGathering(IReadingContext context, IEnumerabl } } - protected void AttachMonteCarloDataGatheringForSimulation(IReadingContext context, Simulation simulation) + protected void AttachMonteCarloDataGatheringForSimulation(IReadingContext context, ISimulationWithEvents simulation) { var exportParam = context.SimulationConfiguration.MonteCarloConfiguration.OutputVariable; - simulation.BeforeSetup += (sender, args) => + simulation.EventBeforeSetup += (sender, args) => { Export export = context.Result.Exports.FirstOrDefault(e => e.Simulation == simulation && e.Name == exportParam.Value); @@ -83,7 +84,7 @@ protected void AttachMonteCarloDataGatheringForSimulation(IReadingContext contex export = ExportFactory.Create(exportParam, context, simulation, MapperExporter); } - simulation.ExportSimulationData += (exportSender, exportArgs) => + simulation.EventExportData += (exportSender, exportArgs) => { if (export != null) { diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Factories/ICreateSimulationsForAllParameterSweepsAndTemperaturesFactory.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Factories/ICreateSimulationsForAllParameterSweepsAndTemperaturesFactory.cs index 37b16f6d..b351866a 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Factories/ICreateSimulationsForAllParameterSweepsAndTemperaturesFactory.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Factories/ICreateSimulationsForAllParameterSweepsAndTemperaturesFactory.cs @@ -1,4 +1,5 @@ using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.ModelReaders.Netlist.Spice.Context; using SpiceSharpParser.Models.Netlist.Spice.Objects; using System; @@ -8,6 +9,6 @@ namespace SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.Controls.Simulatio { public interface ICreateSimulationsForAllParameterSweepsAndTemperaturesFactory { - List CreateSimulations(Control statement, IReadingContext context, Func createSimulation); + List CreateSimulations(Control statement, IReadingContext context, Func createSimulation); } } \ No newline at end of file diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Factories/ICreateSimulationsForAllTemperaturesFactory.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Factories/ICreateSimulationsForAllTemperaturesFactory.cs index f63078c9..ad50d2b6 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Factories/ICreateSimulationsForAllTemperaturesFactory.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Factories/ICreateSimulationsForAllTemperaturesFactory.cs @@ -1,4 +1,5 @@ using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.ModelReaders.Netlist.Spice.Context; using SpiceSharpParser.Models.Netlist.Spice.Objects; using System; @@ -8,6 +9,6 @@ namespace SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.Controls.Simulatio { public interface ICreateSimulationsForAllTemperaturesFactory { - List CreateSimulations(Control statement, IReadingContext context, Func createSimulation); + List CreateSimulations(Control statement, IReadingContext context, Func createSimulation); } } \ No newline at end of file diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Factories/ICreateSimulationsForMonteCarloFactory.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Factories/ICreateSimulationsForMonteCarloFactory.cs index 15a11410..601e659f 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Factories/ICreateSimulationsForMonteCarloFactory.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/Factories/ICreateSimulationsForMonteCarloFactory.cs @@ -1,4 +1,5 @@ using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.ModelReaders.Netlist.Spice.Context; using SpiceSharpParser.Models.Netlist.Spice.Objects; using System; @@ -8,6 +9,6 @@ namespace SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.Controls.Simulatio { public interface ICreateSimulationsForMonteCarloFactory { - List Create(Control statement, IReadingContext context, Func createSimulation); + List Create(Control statement, IReadingContext context, Func createSimulation); } } \ No newline at end of file diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/ISimulationDecorator.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/ISimulationDecorator.cs index e0d4006b..63a8732c 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/ISimulationDecorator.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/ISimulationDecorator.cs @@ -1,9 +1,10 @@ using SpiceSharp.Simulations; +using SpiceSharpParser.Common; namespace SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.Controls.Simulations { public interface ISimulationDecorator { - Simulation Decorate(Simulation simulation); + ISimulationWithEvents Decorate(ISimulationWithEvents simulation); } } \ No newline at end of file diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/ISimulationsFactory.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/ISimulationsFactory.cs index 7304069f..7a9da5f5 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/ISimulationsFactory.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/ISimulationsFactory.cs @@ -1,4 +1,5 @@ using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.ModelReaders.Netlist.Spice.Context; using SpiceSharpParser.Models.Netlist.Spice.Objects; using System; @@ -7,6 +8,6 @@ namespace SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.Controls.Simulatio { public interface ISimulationsFactory { - void Create(Control statement, IReadingContext context, Func createSimulation); + void Create(Control statement, IReadingContext context, Func createSimulation); } } \ No newline at end of file diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/MonteCarloResult.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/MonteCarloResult.cs index 6dcc9530..0cbe5cbb 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/MonteCarloResult.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/MonteCarloResult.cs @@ -27,12 +27,12 @@ public class MonteCarloResult /// /// Gets or sets the dictionary of max values. /// - public Dictionary Max { get; protected set; } = new Dictionary(); + public Dictionary Max { get; protected set; } = new Dictionary(); /// /// Gets or sets the dictionary of min values. /// - public Dictionary Min { get; protected set; } = new Dictionary(); + public Dictionary Min { get; protected set; } = new Dictionary(); /// /// Gets or sets the output variable name. @@ -49,7 +49,7 @@ public class MonteCarloResult /// /// Simulation of the result. /// Result value. - public void Collect(Simulation simulation, double result) + public void Collect(ISimulationWithEvents simulation, double result) { if (simulation == null) { diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/NoiseControl.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/NoiseControl.cs index ec666568..f2c2d4a8 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/NoiseControl.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/NoiseControl.cs @@ -1,4 +1,5 @@ using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.Common.Validation; using SpiceSharpParser.ModelReaders.Netlist.Spice.Context; using SpiceSharpParser.ModelReaders.Netlist.Spice.Mappings; @@ -31,9 +32,9 @@ public override void Read(Control statement, IReadingContext context) CreateSimulations(statement, context, CreateNoiseSimulation); } - private Noise CreateNoiseSimulation(string name, Control statement, IReadingContext context) + private ISimulationWithEvents CreateNoiseSimulation(string name, Control statement, IReadingContext context) { - Noise noise = null; + NoiseWithEvents noise = null; // Check parameter count switch (statement.Parameters.Count) @@ -94,13 +95,13 @@ private Noise CreateNoiseSimulation(string name, Control statement, IReadingCont var output = v.Elements[0].Value; var reference = v.Elements[1].Value; var input = statement.Parameters[1].Value; - noise = new Noise(name, input, output, reference, _sweep); + noise = new NoiseWithEvents(name, input, output, reference, _sweep); } else if (bracket.Parameters[0] is SingleParameter s) { var output = s.Value; var input = statement.Parameters[1].Value; - noise = new Noise(name, input, output, _sweep); + noise = new NoiseWithEvents(name, input, output, _sweep); } break; diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/OPControl.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/OPControl.cs index 918e4391..bd356287 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/OPControl.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/OPControl.cs @@ -1,4 +1,5 @@ using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.ModelReaders.Netlist.Spice.Context; using SpiceSharpParser.ModelReaders.Netlist.Spice.Mappings; using SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.Controls.Exporters; @@ -26,9 +27,9 @@ public override void Read(Control statement, IReadingContext context) CreateSimulations(statement, context, CreateOperatingPointSimulation); } - private OP CreateOperatingPointSimulation(string name, Control statement, IReadingContext context) + private ISimulationWithEvents CreateOperatingPointSimulation(string name, Control statement, IReadingContext context) { - var op = new OP(name); + var op = new OpWithEvents(name); ConfigureCommonSettings(op, context); context.Result.Simulations.Add(op); diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/SimulationControl.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/SimulationControl.cs index 7f942e9f..ab08e136 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/SimulationControl.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/SimulationControl.cs @@ -1,4 +1,5 @@ using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.ModelReaders.Netlist.Spice.Context; using SpiceSharpParser.ModelReaders.Netlist.Spice.Mappings; using SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.Controls.Exporters; @@ -25,7 +26,7 @@ protected SimulationControl(IMapper exporterMapper) /// /// Creates simulations. /// - protected void CreateSimulations(Control statement, IReadingContext context, Func createSimulation) + protected void CreateSimulations(Control statement, IReadingContext context, Func createSimulation) { _factory.Create(statement, context, createSimulation); } diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/SimulationsFactory.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/SimulationsFactory.cs index 26f876e7..6c5fdb1f 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/SimulationsFactory.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/SimulationsFactory.cs @@ -1,4 +1,5 @@ using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.ModelReaders.Netlist.Spice.Context; using SpiceSharpParser.ModelReaders.Netlist.Spice.Mappings; using SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.Controls.Common; @@ -36,7 +37,7 @@ public SimulationsFactory(IMapper exporterMapper) /// Simulation statement. /// Context. /// Simulation factory. - public void Create(Control statement, IReadingContext context, Func createSimulation) + public void Create(Control statement, IReadingContext context, Func createSimulation) { if (!IsMonteCarloEnabledForSimulation(statement, context)) { diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/TransientControl.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/TransientControl.cs index 5f78f3d3..be527bb4 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/TransientControl.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/Simulations/TransientControl.cs @@ -1,5 +1,6 @@ using SpiceSharp.Simulations; using SpiceSharp.Simulations.IntegrationMethods; +using SpiceSharpParser.Common; using SpiceSharpParser.Common.Validation; using SpiceSharpParser.ModelReaders.Netlist.Spice.Context; using SpiceSharpParser.ModelReaders.Netlist.Spice.Mappings; @@ -29,7 +30,7 @@ public override void Read(Control statement, IReadingContext context) CreateSimulations(statement, context, CreateTransientSimulation); } - private Transient CreateTransientSimulation(string name, Control statement, IReadingContext context) + private ISimulationWithEvents CreateTransientSimulation(string name, Control statement, IReadingContext context) { switch (statement.Parameters.Count) { @@ -51,7 +52,7 @@ private Transient CreateTransientSimulation(string name, Control statement, IRea clonedParameters.RemoveAt(clonedParameters.Count - 1); } - Transient tran; + TransientWithEvents tran; double? maxStep = null; double? step; @@ -90,23 +91,23 @@ private Transient CreateTransientSimulation(string name, Control statement, IRea config.MaxStep = maxStep; config.Start = start; config.UseIc = useIc; - tran = new Transient(name, factory(config)); + tran = new TransientWithEvents(name, factory(config)); } else { if (clonedParameters.Count == 2) { - tran = new Transient(name, step.Value, final.Value); + tran = new TransientWithEvents(name, step.Value, final.Value); } else { if (clonedParameters.Count == 3) { - tran = new Transient(name, step.Value, final.Value, maxStep ?? step.Value); + tran = new TransientWithEvents(name, step.Value, final.Value, maxStep ?? step.Value); } else { - tran = new Transient( + tran = new TransientWithEvents( name, new Trapezoidal() { diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/WaveControl.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/WaveControl.cs index 1d86f4f0..777be501 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/WaveControl.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Controls/WaveControl.cs @@ -3,6 +3,7 @@ using System.Linq; using SpiceSharp.Components; using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.ModelReaders.Netlist.Spice.Context; using SpiceSharpParser.ModelReaders.Netlist.Spice.Mappings; using SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.Controls.Common; @@ -34,11 +35,11 @@ public WaveControl(IMapper mapper, IExportFactory factory) /// A context to modify. public override void Read(Control statement, IReadingContext context) { - var transient = (Transient)context.Result.Simulations.FirstOrDefault(s => s is Transient); + var transient = (ISimulationWithEvents)context.Result.Simulations.FirstOrDefault(s => s is Transient); if (transient != null) { - var timeParameters = transient.TimeParameters; + var timeParameters = ((Transient)transient).TimeParameters; if (statement.Parameters.Count < 3) { throw new Exception("Too few parameters for WAV"); @@ -53,12 +54,12 @@ public override void Read(Control statement, IReadingContext context) var monoChannel = statement.Parameters[3]; var monoChannelExport = GenerateExport(monoChannel, context, transient); var pwlData = new List<(double, double)>(); - transient.ExportSimulationData += (sender, args) => + transient.EventExportData += (sender, args) => { pwlData.Add((args.Time, monoChannelExport.Extract())); }; - transient.AfterExecute += (sender, args) => + transient.EventAfterExecute += (sender, args) => { var writer = new WaveFileWriter(); writer.Write(filePath, sampleRate, 1.0, bitPerSample, pwlData.ToArray()); @@ -73,13 +74,13 @@ public override void Read(Control statement, IReadingContext context) var leftData = new List<(double, double)>(); var rightData = new List<(double, double)>(); - transient.ExportSimulationData += (sender, args) => + transient.EventExportData += (sender, args) => { leftData.Add((args.Time, leftChannelExport.Extract())); rightData.Add((args.Time, rightChannelExport.Extract())); }; - transient.AfterExecute += (sender, args) => + transient.EventAfterExecute += (sender, args) => { var writer = new WaveFileWriter(); writer.Write( diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Waveforms/Wave/WaveFileWriter.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Waveforms/Wave/WaveFileWriter.cs index 33f16d71..08c1aa67 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Waveforms/Wave/WaveFileWriter.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/Waveforms/Wave/WaveFileWriter.cs @@ -161,12 +161,12 @@ private byte[] Compute(int sampleRate, double amplitude, int bitsPerSample, (dou for (var i = 0; i < numberOfSamples; i++) { byte leftChannelValue = (byte)((Pwl(currentTime, leftChannel) / amplitude) * byte.MaxValue); - result.AddRange(BitConverter.GetBytes(leftChannelValue)); + result.AddRange(BitConverter.GetBytes((short)leftChannelValue)); if (rightChannel != null) { byte rightChannelValue = (byte)((Pwl(currentTime, rightChannel) / amplitude) * byte.MaxValue); - result.AddRange(BitConverter.GetBytes(rightChannelValue)); + result.AddRange(BitConverter.GetBytes((short)rightChannelValue)); } currentTime += step; diff --git a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/SpiceSharpModel.cs b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/SpiceSharpModel.cs index e80f7fa1..fda6e602 100644 --- a/src/SpiceSharpParser/ModelReaders/Netlist/Spice/SpiceSharpModel.cs +++ b/src/SpiceSharpParser/ModelReaders/Netlist/Spice/SpiceSharpModel.cs @@ -1,5 +1,6 @@ using SpiceSharp; using SpiceSharp.Simulations; +using SpiceSharpParser.Common; using SpiceSharpParser.Common.Validation; using SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.Controls.Exporters; using SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.Controls.Plots; @@ -33,7 +34,7 @@ public SpiceSharpModel(Circuit circuit, string title) /// /// Gets the list of simulation from the netlist. /// - public List Simulations { get; } = new List(); + public List Simulations { get; } = new List(); /// /// Gets the list of comments from the netlist. diff --git a/src/SpiceSharpParser/ModelWriters/CSharp/Events/ACWithEvents.cs b/src/SpiceSharpParser/ModelWriters/CSharp/Events/ACWithEvents.cs new file mode 100644 index 00000000..8bf5e0ce --- /dev/null +++ b/src/SpiceSharpParser/ModelWriters/CSharp/Events/ACWithEvents.cs @@ -0,0 +1,87 @@ +using SpiceSharp.Simulations; +using System; +using System.Collections.Generic; + +namespace SpiceSharpParser.Common +{ + public class ACWithEvents : AC, ISimulationWithEvents + { + protected ACWithEvents(string name) : base(name) + { + } + + public ACWithEvents(string name, IEnumerable frequencySweep): base(name, frequencySweep) + { + } + + public event OnBeforeSetup EventBeforeSetup; + + public event OnBeforeSetup EventBeforeUnSetup; + + public event OnAfterSetup EventAfterSetup; + + public event OnBeforeValidation EventBeforeValidation; + + public event OnBeforeValidation EventAfterValidation; + + public event OnBeforeTemperature EventBeforeTemperature; + + public event OnAfterTemperature EventAfterTemperature; + + public event OnBeforeExecute EventBeforeExecute; + + public event OnAfterExecute EventAfterExecute; + + public event OnExportData EventExportData; + + public IEnumerable AttachEvents(IEnumerable codes) + { + EventBeforeSetup.Invoke(this, EventArgs.Empty); + foreach (var code in codes) + { + switch (code) + { + case Simulation.BeforeValidation: + EventBeforeValidation.Invoke(this, EventArgs.Empty); + break; + + case Simulation.AfterValidation: + EventAfterValidation.Invoke(this, EventArgs.Empty); + break; + + case Simulation.BeforeSetup: + EventBeforeSetup.Invoke(this, EventArgs.Empty); + break; + case Simulation.AfterSetup: + EventAfterSetup.Invoke(this, EventArgs.Empty); + break; + case Simulation.BeforeUnsetup: + EventBeforeUnSetup.Invoke(this, EventArgs.Empty); + break; + + case Simulation.BeforeExecute: + EventBeforeExecute.Invoke(this, EventArgs.Empty); + + if (this is IBiasingSimulation) + { + EventBeforeTemperature?.Invoke(this, null); + } + + break; + + case Simulation.AfterExecute: + EventAfterExecute.Invoke(this, EventArgs.Empty); + break; + + + case AC.Exports: + + double frequency = base.Frequency; + EventExportData.Invoke(this, new ExportData { Frequency = frequency }); + break; + } + yield return code; + } + } + } +} diff --git a/src/SpiceSharpParser/ModelWriters/CSharp/Events/DcWithEvents.cs b/src/SpiceSharpParser/ModelWriters/CSharp/Events/DcWithEvents.cs new file mode 100644 index 00000000..4a1fc6dd --- /dev/null +++ b/src/SpiceSharpParser/ModelWriters/CSharp/Events/DcWithEvents.cs @@ -0,0 +1,89 @@ +using SpiceSharp; +using SpiceSharp.Simulations; +using System; +using System.Collections.Generic; + +namespace SpiceSharpParser.Common +{ + public class DcWithEvents : DC, ISimulationWithEvents + { + public DcWithEvents(string name) : base(name) + { + } + + public DcWithEvents(string name, IEnumerable sweeps) : this(name) + { + sweeps.ThrowIfNull("sweeps"); + foreach (ISweep sweep in sweeps) + { + DCParameters.Sweeps.Add(sweep); + } + } + + public event OnBeforeSetup EventBeforeSetup; + + public event OnBeforeSetup EventBeforeUnSetup; + + public event OnAfterSetup EventAfterSetup; + + public event OnBeforeValidation EventBeforeValidation; + + public event OnBeforeValidation EventAfterValidation; + + public event OnBeforeTemperature EventBeforeTemperature; + + public event OnAfterTemperature EventAfterTemperature; + + public event OnBeforeExecute EventBeforeExecute; + + public event OnAfterExecute EventAfterExecute; + + public event OnExportData EventExportData; + + public IEnumerable AttachEvents(IEnumerable codes) + { + foreach (var code in codes) + { + switch (code) + { + case DC.BeforeValidation: + EventBeforeValidation?.Invoke(this, EventArgs.Empty); + break; + + case DC.AfterValidation: + EventAfterValidation?.Invoke(this, EventArgs.Empty); + break; + + case 65536: + EventBeforeSetup?.Invoke(this, EventArgs.Empty); + break; + case DC.AfterSetup: + EventAfterSetup?.Invoke(this, EventArgs.Empty); + break; + case DC.BeforeUnsetup: + EventBeforeUnSetup?.Invoke(this, EventArgs.Empty); + break; + + case DC.BeforeExecute: + EventBeforeExecute?.Invoke(this, EventArgs.Empty); + + if (this is IBiasingSimulation) + { + EventBeforeTemperature?.Invoke(this, null); + } + + break; + + case DC.AfterExecute: + EventAfterExecute?.Invoke(this, EventArgs.Empty); + break; + + case DC.ExportSweep: + EventExportData?.Invoke(this, new ExportData { }); + break; + } + yield return code; + } + } + } +} diff --git a/src/SpiceSharpParser/ModelWriters/CSharp/Events/ISimulationWithEvents.cs b/src/SpiceSharpParser/ModelWriters/CSharp/Events/ISimulationWithEvents.cs new file mode 100644 index 00000000..ec3d2e80 --- /dev/null +++ b/src/SpiceSharpParser/ModelWriters/CSharp/Events/ISimulationWithEvents.cs @@ -0,0 +1,57 @@ +using SpiceSharp; +using SpiceSharp.Entities; +using SpiceSharp.Simulations; +using System.Collections.Generic; + +namespace SpiceSharpParser.Common +{ + public delegate void OnBeforeSetup(object sender, object argument); + + public delegate void OnBeforeUnSetup(object sender, object argument); + + public delegate void OnAfterSetup(object sender, object argument); + + public delegate void OnBeforeValidation(object sender, object argument); + + public delegate void OnBeforeTemperature(object sender, TemperatureStateEventArgs argument); + + public delegate void OnAfterTemperature(object sender, object argument); + + public delegate void OnBeforeExecute(object sender, object argument); + + public delegate void OnAfterExecute(object sender, object argument); + + public delegate void OnExportData(object sender, ExportData argument); + + public class ExportData + { + public double Time { get; set; } + public double Frequency { get; internal set; } + } + + + public interface ISimulationWithEvents : ISimulation + { + event OnAfterSetup EventAfterSetup; + + event OnAfterTemperature EventAfterTemperature; + + event OnBeforeValidation EventAfterValidation; + + event OnBeforeExecute EventBeforeExecute; + + event OnAfterExecute EventAfterExecute; + + event OnBeforeSetup EventBeforeSetup; + + event OnBeforeTemperature EventBeforeTemperature; + + event OnBeforeSetup EventBeforeUnSetup; + + event OnBeforeValidation EventBeforeValidation; + + event OnExportData EventExportData; + + IEnumerable AttachEvents(IEnumerable codes); + } +} \ No newline at end of file diff --git a/src/SpiceSharpParser/ModelWriters/CSharp/Events/NoiseWithEvents.cs b/src/SpiceSharpParser/ModelWriters/CSharp/Events/NoiseWithEvents.cs new file mode 100644 index 00000000..a824c614 --- /dev/null +++ b/src/SpiceSharpParser/ModelWriters/CSharp/Events/NoiseWithEvents.cs @@ -0,0 +1,89 @@ +using SpiceSharp.Simulations; +using System; +using System.Collections.Generic; + +namespace SpiceSharpParser.Common +{ + public class NoiseWithEvents : Noise, ISimulationWithEvents + { + public NoiseWithEvents(string name) : base(name) + { + } + + public NoiseWithEvents(string name, string input, string output, IEnumerable frequencySweep) : base(name, input, output, frequencySweep) + { + } + + public NoiseWithEvents(string name, string input, string output, string reference, IEnumerable frequencySweep) : base(name, input, output, reference, frequencySweep) + { + } + + public event OnBeforeSetup EventBeforeSetup; + + public event OnBeforeSetup EventBeforeUnSetup; + + public event OnAfterSetup EventAfterSetup; + + public event OnBeforeValidation EventBeforeValidation; + + public event OnBeforeValidation EventAfterValidation; + + public event OnBeforeTemperature EventBeforeTemperature; + + public event OnAfterTemperature EventAfterTemperature; + + public event OnBeforeExecute EventBeforeExecute; + + public event OnAfterExecute EventAfterExecute; + + public event OnExportData EventExportData; + + public IEnumerable AttachEvents(IEnumerable codes) + { + foreach (var code in codes) + { + switch (code) + { + case Noise.BeforeValidation: + EventBeforeValidation?.Invoke(this, EventArgs.Empty); + break; + + case Noise.AfterValidation: + EventAfterValidation?.Invoke(this, EventArgs.Empty); + break; + + case Noise.BeforeSetup: + EventBeforeSetup?.Invoke(this, EventArgs.Empty); + break; + case Noise.AfterSetup: + EventAfterSetup?.Invoke(this, EventArgs.Empty); + break; + case Noise.BeforeUnsetup: + EventBeforeUnSetup?.Invoke(this, EventArgs.Empty); + break; + + case Noise.BeforeExecute: + EventBeforeExecute?.Invoke(this, EventArgs.Empty); + + if (this is IBiasingSimulation) + { + EventBeforeTemperature?.Invoke(this, null); + } + + break; + + case Noise.AfterExecute: + EventAfterExecute?.Invoke(this, EventArgs.Empty); + break; + + + case Noise.ExportNoise: + + EventExportData?.Invoke(this, new ExportData { }); + break; + } + yield return code; + } + } + } +} diff --git a/src/SpiceSharpParser/ModelWriters/CSharp/Events/OpWithEvents.cs b/src/SpiceSharpParser/ModelWriters/CSharp/Events/OpWithEvents.cs new file mode 100644 index 00000000..1ec528d4 --- /dev/null +++ b/src/SpiceSharpParser/ModelWriters/CSharp/Events/OpWithEvents.cs @@ -0,0 +1,78 @@ +using SpiceSharp.Simulations; +using System; +using System.Collections.Generic; + +namespace SpiceSharpParser.Common +{ + public class OpWithEvents : OP, ISimulationWithEvents + { + public OpWithEvents(string name) : base(name) + { + } + + public event OnBeforeSetup EventBeforeSetup; + + public event OnBeforeSetup EventBeforeUnSetup; + + public event OnAfterSetup EventAfterSetup; + + public event OnBeforeValidation EventBeforeValidation; + + public event OnBeforeValidation EventAfterValidation; + + public event OnBeforeTemperature EventBeforeTemperature; + + public event OnAfterTemperature EventAfterTemperature; + + public event OnBeforeExecute EventBeforeExecute; + + public event OnAfterExecute EventAfterExecute; + + public event OnExportData EventExportData; + + public IEnumerable AttachEvents(IEnumerable codes) + { + foreach (var code in codes) + { + switch (code) + { + case OP.AfterExecute: + EventAfterExecute?.Invoke(this, EventArgs.Empty); + break; + + case OP.BeforeExecute: + EventBeforeExecute?.Invoke(this, EventArgs.Empty); + break; + + case OP.BeforeValidation: + EventBeforeValidation?.Invoke(this, EventArgs.Empty); + break; + + case OP.AfterValidation: + EventAfterValidation?.Invoke(this, EventArgs.Empty); + break; + case OP.BeforeSetup: + EventBeforeSetup?.Invoke(this, EventArgs.Empty); + break; + case OP.AfterSetup: + EventAfterSetup?.Invoke(this, EventArgs.Empty); + break; + case OP.BeforeTemperature: + var state = this.GetState(); + EventBeforeTemperature?.Invoke(this, new TemperatureStateEventArgs(state)); + break; + case OP.AfterTemperature: + EventAfterTemperature?.Invoke(this, EventArgs.Empty); + break; + case OP.BeforeUnsetup: + EventBeforeUnSetup?.Invoke(this, EventArgs.Empty); + break; + case OP.ExportOperatingPoint: + EventExportData?.Invoke(this, new ExportData() { }); + break; + } + yield return code; + } + } + } +} diff --git a/src/SpiceSharpParser/ModelWriters/CSharp/Events/TransientWithEvents.cs b/src/SpiceSharpParser/ModelWriters/CSharp/Events/TransientWithEvents.cs new file mode 100644 index 00000000..e902e497 --- /dev/null +++ b/src/SpiceSharpParser/ModelWriters/CSharp/Events/TransientWithEvents.cs @@ -0,0 +1,115 @@ +using SpiceSharp.Simulations; +using System; +using System.Collections.Generic; + +namespace SpiceSharpParser.Common +{ + public class TransientWithEvents : Transient, ISimulationWithEvents + { + public TransientWithEvents(string name) : base(name) + { + } + + public TransientWithEvents(string name, TimeParameters parameters) : base(name, parameters) + { + + } + public TransientWithEvents(string name, double step, double final) + : base(name, step, final) + { + } + + // + // Summary: + // Initializes a new instance of the SpiceSharp.Simulations.Transient class. + // + // Parameters: + // name: + // The name of the simulation. + // + // step: + // The step size. + // + // final: + // The final time. + // + // maxStep: + // The maximum step. + public TransientWithEvents(string name, double step, double final, double maxStep) + : base(name, step, final, maxStep) + { + + } + + public event OnBeforeSetup EventBeforeSetup; + + public event OnBeforeSetup EventBeforeUnSetup; + + public event OnAfterSetup EventAfterSetup; + + public event OnBeforeValidation EventBeforeValidation; + + public event OnBeforeValidation EventAfterValidation; + + public event OnBeforeTemperature EventBeforeTemperature; + + public event OnAfterTemperature EventAfterTemperature; + + public event OnBeforeExecute EventBeforeExecute; + + public event OnAfterExecute EventAfterExecute; + + public event OnExportData EventExportData; + + public IEnumerable AttachEvents(IEnumerable codes) + { + EventBeforeSetup.Invoke(this, EventArgs.Empty); + EventBeforeTemperature?.Invoke(this, null); + + foreach (var code in codes) + { + switch (code) + { + case Transient.BeforeValidation: + EventBeforeValidation?.Invoke(this, EventArgs.Empty); + break; + + case Transient.AfterValidation: + EventAfterValidation?.Invoke(this, EventArgs.Empty); + break; + + case Transient.BeforeTemperature: + var state = this.GetState(); + EventBeforeTemperature?.Invoke(this, new TemperatureStateEventArgs(state)); + break; + + case Transient.AfterTemperature: + EventAfterTemperature?.Invoke(this, EventArgs.Empty); + break; + + case Transient.BeforeSetup: + EventBeforeSetup?.Invoke(this, EventArgs.Empty); + break; + case Transient.AfterSetup: + EventAfterSetup?.Invoke(this, EventArgs.Empty); + break; + case Transient.BeforeUnsetup: + EventBeforeUnSetup?.Invoke(this, EventArgs.Empty); + break; + + case Transient.BeforeExecute: + EventBeforeExecute?.Invoke(this, EventArgs.Empty); + break; + case Simulation.AfterExecute: + EventAfterExecute?.Invoke(this, EventArgs.Empty); + break; + case Transient.ExportTransient: + + EventExportData?.Invoke(this, new ExportData { Time = this.Time }); + break; + } + yield return code; + } + } + } +} diff --git a/src/SpiceSharpParser/SpiceSharpParser.csproj b/src/SpiceSharpParser/SpiceSharpParser.csproj index 324f7b09..49d4ddce 100644 --- a/src/SpiceSharpParser/SpiceSharpParser.csproj +++ b/src/SpiceSharpParser/SpiceSharpParser.csproj @@ -2,10 +2,10 @@ {DF3DD787-71CC-4C89-9E33-DC4536A52278} - netstandard2.0;net6.0 + netstandard2.0;net6.0;net8.0 SpiceSharp https://github.com/SpiceSharp/SpiceSharpParser - Copyright 2022 + Copyright 2024 true https://github.com/SpiceSharp/SpiceSharpParser @@ -22,7 +22,7 @@ MIT latest - 3.1.5 + 3.2.0 @@ -35,9 +35,9 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive