Ngspice as a Shared Library

As a new option ngspice may be compiled as a shared library (*.so in LINUX, *.dll in MS Windows).

A controlling application may acquire complete control over ngspice after loading the shared lib either during compilation/linking or dynamically at runtime.

The shared module offers an interface which exports functions controlling the simulator and callback functions for feedback.

So you may send an input "file" with a netlist to ngspice, start the simulation in a separate thread, read back simulation data at each time point, stop the simulator depending on some condition, alter device or model parameters and then resume the simulation.

The calling process may offer a graphical user interface which you may develop and optimize without a need to alter the ngspice source code.

Details of the shared ngspice API are documented in chapter 19 of the actual manual. A short description of the interface functions and the data structures used is given in the header file sharedspice.h, to be found in /src/include/ngspice. You may also have a look at the file /src/sharedspice.c, containing the function definitions.

Three executables (coming with source code) serve as examples for controlling ngspice. These are not meant to be "productive" programs, but just give some commented example usages of the interface.

ng_start.exe is a MS Windows application loading ngspice.dll dynamically. All functions and callbacks of the interface are assessed. The source code, generated with Turbo Delphi 2006, may be found here, the binaries compiled for 32 Bit are here.

Two console applications, compilable with LINUX, CYGWIN, MINGW or MS Visual Studio, are available here, demonstrating either statical linking or linking shared ngspice at runtime. A simple feedback loop is shown in tests 3 and 4, where a device parameter is changed upon having an output vector value crossing a limit.

The next steps in developing this option will be to receive your comments, and if time allows, a GUI written in Qt (maybe you do this and give a feedback).