private void Parse(object obj) { try { var model = SpiceHelper.GetSpiceSharpNetlist(Netlist, (SpiceSharpParser.ModelReaders.Netlist.Spice.Evaluation.SpiceExpressionMode)SelectedMode, RandomSeed, HasTitle); MessageBox.Show("Parsing was successful", "SpiceSharpGUI", MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception ex) { MessageBox.Show("Parsing failed: " + ex, "SpiceSharpGUI", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void Parse(object obj) { try { var model = SpiceHelper.GetSpiceSharpNetlist(Netlist, RandomSeed, HasTitle, MainWindowViewModel.GetEncoding(SelectedEncoding)); MessageBox.Show("Parsing was successful", "SpiceSharpGUI", MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception ex) { MessageBox.Show("Parsing failed: " + ex, "SpiceSharpGUI", MessageBoxButton.OK, MessageBoxImage.Error); } }
static int Main(string[] args) { var app = ShellHelper.CreateConsoleApp("cv4pve-pepper", "Launching SPICE on Proxmox VE"); var optVmId = app.VmIdOrNameOption().DependOn(app, CommandOptionExtension.HOST_OPTION_NAME); var optRemoteViewer = app.Option("--viewer", "Executable SPICE client remote viewer", CommandOptionType.SingleValue) .DependOn(app, CommandOptionExtension.HOST_OPTION_NAME); optRemoteViewer.Accepts().ExistingFile(); app.OnExecute(() => { var fileName = Path.GetTempFileName().Replace(".tmp", ".vv"); var ret = SpiceHelper.CreateFileSpaceClient(app.ClientTryLogin(), optVmId.Value(), fileName); if (ret) { var process = new Process { StartInfo = new ProcessStartInfo() { UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = false, FileName = StringHelper.Quote(optRemoteViewer.Value()), Arguments = StringHelper.Quote(fileName) } }; if (app.DebugIsActive()) { app.Out.WriteLine($"Run FileName: {process.StartInfo.FileName}"); app.Out.WriteLine($"Run Arguments: {process.StartInfo.Arguments}"); } if (!app.DryRunIsActive()) { process.Start(); ret = process.HasExited ? process.ExitCode == 0 : true; } } return(ret ? 0 : 1); }); return(app.ExecuteConsoleApp(args)); }
public XyPlotViewModel(XyPlot plot) { rand = new Random(Environment.TickCount); Series = new Series[plot.Series.Count]; for (var i = 0; i < Series.Length; i++) { Series[i] = new Series() { Name = plot.Series[i].Name, Selected = true }; } YScaleLogEnabled = SpiceHelper.IsPlotPositive(plot); OxyPlotModel = CreateOxyPlotModel(plot); }
private void RunSimulations() { try { Status = "Status: Running simulations"; PlotsEnabled = false; Internals = new TreeViewModel(); Plots = new TabsViewModel(); Prints = new ObservableCollection <UIElement>(); var parseResult = SpiceHelper.GetSpiceSharpNetlist(Netlist, RandomSeed, HasTitle, Encoding); if (parseResult != null) { var model = new SpiceSharpParser.SpiceSharpReader().Read(parseResult.FinalModel); if (model == null) { Logs += $"Errors in lexing: {parseResult.ValidationResult.HasError}\n"; } else { SaveExportsToFile(model); Logs += $"Simulations found: {model.Simulations.Count}\n"; Logs += "Errors and warnings: \n"; foreach (var log in model.ValidationResult) { Logs += log.Message + ", line =" + log.LineInfo.LineNumber + "\n"; } int simulationNo = 0; Stopwatch simulationsWatch = new Stopwatch(); simulationsWatch.Start(); System.Threading.Tasks.Parallel.ForEach <Simulation>( model.Simulations, new ParallelOptions() { MaxDegreeOfParallelism = MaxDegreeOfParallelism }, simulation => RunSimulation(model, (Simulation)simulation, Interlocked.Increment(ref simulationNo))); simulationsWatch.Stop(); // Generate summary statistics Dispatcher.Invoke(() => { var summary = new SummarySimulationStatistics(); foreach (var stat in Stats) { summary.BehaviorCreationTime += stat.BehaviorCreationTime; summary.FinishTime += stat.FinishTime; summary.ExecutionTime += stat.ExecutionTime; summary.SetupTime += stat.SetupTime; summary.ValidationTime += stat.ValidationTime; } summary.TotalSimulationsTime = simulationsWatch.ElapsedMilliseconds; SummaryStats.Add(summary); }); // Generate plots if (model.XyPlots.Count > 0) { PlotsEnabled = true; Logs += $"Creating plots: {model.XyPlots.Count}\n"; if (model.XyPlots.Count > 0) { foreach (var plot in model.XyPlots) { Dispatcher.Invoke(() => { Plots.Items.Add(new TabItem() { Header = plot.Name, Content = new XyPlotControl() { Plot = plot } }); }); } } } // Generate plots if (model.MonteCarloResult.Enabled) { PlotsEnabled = true; Logs += $"Creating monte carlo plot\n"; Dispatcher.Invoke(() => { var plot = new HistogramPlotControl() { Data = model.MonteCarloResult }; plot.DataBind(); Plots.Items.Add(new TabItem() { Header = "Monte Carlo", Content = plot }); }); } Logs += $"Prints found: {model.Prints.Count}\n"; if (model.Prints.Count > 0) { foreach (var print in model.Prints) { Dispatcher.Invoke(() => { PrintControl control = new PrintControl(print); control.DataBind(); Prints.Add(control); }); } } } Status = "Status: Finished"; } } catch (Exception ex) { Logs += ex.ToString(); Status = "Status: Error"; } }
static int Main(string[] args) { var app = ShellHelper.CreateConsoleApp("cv4pve-pepper", "Launching SPICE on Proxmox VE"); var optVmId = app.VmIdOrNameOption().DependOn(app, CommandOptionExtension.HOST_OPTION_NAME); var optRemoteViewer = app.Option("--viewer", "Executable SPICE client remote viewer", CommandOptionType.SingleValue) .DependOn(app, CommandOptionExtension.HOST_OPTION_NAME); optRemoteViewer.Accepts().ExistingFile(); app.OnExecute(() => { var fileName = Path.GetTempFileName().Replace(".tmp", ".vv"); var client = app.ClientTryLogin(); var ret = SpiceHelper.CreateFileSpaceClient(client, optVmId.Value(), fileName); if (ret) { var startInfo = new ProcessStartInfo { UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = false, }; if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { startInfo.FileName = "/bin/bash"; startInfo.Arguments = $"-c \"{optRemoteViewer.Value()} {fileName}\""; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { startInfo.FileName = StringHelper.Quote(optRemoteViewer.Value()); startInfo.Arguments = StringHelper.Quote(fileName); } var process = new Process { StartInfo = startInfo }; if (app.DebugIsActive()) { app.Out.WriteLine($"Run FileName: {process.StartInfo.FileName}"); app.Out.WriteLine($"Run Arguments: {process.StartInfo.Arguments}"); } if (!app.DryRunIsActive()) { process.Start(); ret = !process.HasExited || process.ExitCode == 0; } } else { if (!client.LastResult.IsSuccessStatusCode) { app.Out.WriteLine($"Error: {client.LastResult.ReasonPhrase}"); } } return(ret ? 0 : 1); }); return(app.ExecuteConsoleApp(args)); }
private void RunSimulations() { try { Status = "Status: Running simulations"; PlotsEnabled = false; Internals = new TreeViewModel(); Plots = new TabsViewModel(); Prints = new ObservableCollection <UIElement>(); var model = SpiceHelper.GetSpiceSharpNetlist(Netlist, Mode, RandomSeed, HasTitle); SaveExportsToFile(model); Logs += $"Simulations found: {model.Simulations.Count}\n"; int simulationNo = 0; Stopwatch simulationsWatch = new Stopwatch(); simulationsWatch.Start(); Parallel.ForEach <Simulation>( model.Simulations, new ParallelOptions() { MaxDegreeOfParallelism = MaxDegreeOfParallelism }, simulation => RunSimulation(model, (BaseSimulation)simulation, Interlocked.Increment(ref simulationNo))); simulationsWatch.Stop(); // Generate summary statistics Dispatcher.Invoke(() => { var summary = new SummarySimulationStatistics(); foreach (var stat in Stats) { summary.Iterations += stat.Iterations; summary.SolveTime += stat.SolveTime; summary.LoadTime += stat.LoadTime; summary.ReorderTime += stat.ReorderTime; summary.BehaviorCreationTime += stat.BehaviorCreationTime; summary.Timepoints += stat.Timepoints; summary.TransientIterations += stat.TransientIterations; summary.TransientTime += stat.TransientTime; summary.AcceptedTimepoints += stat.AcceptedTimepoints; summary.RejectedTimepoints += stat.RejectedTimepoints; } summary.TotalSimulationsTime = simulationsWatch.ElapsedMilliseconds; SummaryStats.Add(summary); }); // Generate plots if (model.XyPlots.Count > 0) { PlotsEnabled = true; Logs += $"Creating plots: {model.XyPlots.Count}\n"; if (model.XyPlots.Count > 0) { foreach (var plot in model.XyPlots) { Dispatcher.Invoke(() => { Plots.Items.Add(new TabItem() { Header = plot.Name, Content = new XyPlotControl() { Plot = plot } }); }); } } } // Generate plots if (model.MonteCarloResult.Enabled) { PlotsEnabled = true; Logs += $"Creating monte carlo plot\n"; Dispatcher.Invoke(() => { var plot = new HistogramPlotControl() { Data = model.MonteCarloResult }; plot.DataBind(); Plots.Items.Add(new TabItem() { Header = "Monte Carlo", Content = plot }); }); } Logs += $"Prints found: {model.Prints.Count}\n"; if (model.Prints.Count > 0) { foreach (var print in model.Prints) { Dispatcher.Invoke(() => { PrintControl control = new PrintControl(print); control.DataBind(); Prints.Add(control); }); } } foreach (var warning in model.Warnings) { Dispatcher.Invoke(() => { Logs += "Warning: " + warning + "\n"; }); } Status = "Status: Finished"; } catch (Exception ex) { Logs += ex.ToString(); Status = "Status: Error"; } }