xgulism1 / UE_Spice_Demo

A demo project for the Spice plugin for Unreal Engine.
3 stars 0 forks source link

UE_Spice_Demo

This is a demo project for the Spice plugin for Unreal Engine available on the marketplace. The plugin utilizes ngspice - the spice simulator for electric and electronic circuits.

Table of contents

Demo project tutorial

Video demonstration

The demo project is made using Widget Blueprints.

The main widget is divided into 5 panels:

  1. examples
  2. netlist
  3. alter
  4. output
  5. graph

image

Click on any button from the example circuits to set the netlist or type the netlist in the netlist panel.

image

Leave the checkbox unchecked to run the analysis until finished or check the checkbox and enter a number to run only a fixed number of time-points and then pause.

image

Start the analysis with the start button.

image

The output text from ngspice is set in the output panel and the graph is displayed in the graph panel.

image

If the analysis is paused, type the instructions in the alter panel to change the device or model parameters of the circuit.

image

Leave the checkbox unchecked to run the analysis until finished or check the checkbox and enter a number to run only a fixed number of time-points and then pause again.

image

Click the resume button to apply the changes and continue the analysis.

image

To control the graph panel, click and drag to move and scroll to zoom to the mouse position. Hover over the graph to inspect specific values of the analysis.

image

Use comboboxes to change the vectors for the X and Y axes and checkboxes to display the real and imaginary values.

image

The clear button clears the analysis data.

image

Blueprints tutorial

To communicate with ngspice, construct an NgspiceCircuit.

image

To start an analysis, use the StartAnalysis function and provide a netlist. StepCount can be set to run only a fixed number of time-points and then pause or set (StepCount <= 0) to run until finish. The analysis starts in the background thread of ngspice.

image

To request a pause or resume of an analysis, use the SetAnalysisShouldPause function.

image

The state of the pause request is indicated by the ShouldPause function.

image

To stop an analysis, use the StopAnalysis function.

image

The IsAnalysing function indicates the analysis of the circuit is in progress. Ngspice can solve only one circuit at a time. In case more than one circuit starts the analysis, they are scheduled for ngspice to start one by one. Beware of paused analyses, the analysis of the next circuit cannot start while the previous one is paused.

image

AnalysisStartedDelegate fires when the background thread starts. AnalysisPausedDelegate fires when the background thread pauses. AnalysisFinishedDelegate fires when the background thread finishes.

image

The state of the background thread visible from the Game Thread can be obtained using the IsRunning function. There is no event to be fired when new data is calculated by ngspice, because it would fire too many times per tick and slow down the Game Thread. To get data during the analysis up to that point, the tick event together with the IsRunning function should be used.

image

To update an analysis, use the UpdateAnalysisWithAlter, UpdateAnalysisWithAltermod or UpdateAnalysisWithStepCount function. The changes will be processed when the analysis starts or resumes. To apply the changes if the analysis is running, restart it by pausing it with the SetAnalysisShouldPause and resuming it with the SetAnalysisShouldPause after the AnalysisPausedDelegate is called.

image

Output from ngspice consists of StdOutput (an Array of Strings) and Analysis Values (a Map of Vector2D Arrays). StdOutput can be retrieved using the GetStdOutput function. Keys to the map of Analysis Values can be retrieved using the GetAnalysisValueKeys function. Each key is an input to the GetAnalysisValues function to get the array of values for the particular vector. Each value is a Vector2D to represent the real and imaginary parts.

image

Output from ngspice can be removed or cleared using the ClearStdOutput, RemoveRangeStdOutput, ClearAnalysisValues and RemoveRangeAnalysisValues functions. All outputs are also cleared at the start of the analysis.

image

Additional C++ functions are exposed for Blueprints to allow more performant manipulation with arrays and to simplify data for displaying on graphs.

image

License

Ngspice is open source under the 3-clause BSD license.