|
KiCad PCB EDA Suite
|
#include <ngspice.h>
Classes | |
| class | NGSPICE_LOCK_REALLOC |
| Execute commands from a file. More... | |
Public Member Functions | |
| NGSPICE () | |
| virtual | ~NGSPICE () |
| void | Init (const SPICE_SETTINGS *aSettings=nullptr) override final |
| Point out the model that will be used in future simulations. | |
| bool | Attach (const std::shared_ptr< SIMULATION_MODEL > &aModel, const wxString &aSimCommand, unsigned aSimOptions, const wxString &aInputPath, REPORTER &aReporter) override final |
| Load a netlist for the simulation. | |
| bool | LoadNetlist (const std::string &aNetlist) override final |
| Execute the simulation with currently loaded netlist. | |
| bool | Run () override final |
| Halt the simulation. | |
| bool | Stop () override final |
| Check if simulation is running at the moment. | |
| bool | IsRunning () override final |
| Execute a Spice command as if it was typed into console. | |
| bool | Command (const std::string &aCmd) override final |
| wxString | GetXAxis (SIM_TYPE aType) const override final |
| wxString | CurrentPlotName () const override final |
| std::vector< std::string > | AllVectors () const override final |
| Return a requested vector with complex values. | |
| std::vector< COMPLEX > | GetComplexVector (const std::string &aName, int aMaxLen=-1) override final |
| Return a requested vector with real values. | |
| std::vector< double > | GetRealVector (const std::string &aName, int aMaxLen=-1) override final |
| Return a requested vector with imaginary values. | |
| std::vector< double > | GetImaginaryVector (const std::string &aName, int aMaxLen=-1) override final |
| Return a requested vector with magnitude values. | |
| std::vector< double > | GetGainVector (const std::string &aName, int aMaxLen=-1) override final |
| Return a requested vector with phase values. | |
| std::vector< double > | GetPhaseVector (const std::string &aName, int aMaxLen=-1) override final |
| Return a requested vector with phase values. | |
| std::vector< std::string > | GetSettingCommands () const override final |
| Return current SPICE netlist used by the simulator. | |
| virtual const std::string | GetNetlist () const override final |
| Cleans simulation data (i.e. | |
| void | Clean () override final |
| Cleans simulation data (i.e. | |
| virtual void | SetReporter (SIMULATOR_REPORTER *aReporter) |
| Set a SIMULATOR_REPORTER object to receive the simulation log. | |
| std::shared_ptr< SPICE_SETTINGS > & | Settings () |
| Return the simulator configuration settings. | |
| const std::shared_ptr< SPICE_SETTINGS > & | Settings () const |
| std::mutex & | GetMutex () |
Static Public Member Functions | |
| static wxString | TypeToName (SIM_TYPE aType, bool aShortName) |
| Return a string with simulation name based on enum. | |
| static std::shared_ptr< SPICE_SIMULATOR > | CreateInstance (const std::string &aName) |
Protected Attributes | |
| std::atomic< SIMULATOR_REPORTER * > | m_reporter |
| < Reporter object to receive simulation log (not owned, accessed from BG threads). | |
| std::mutex | m_reporterMutex |
| We don't own this. We are just borrowing it from the SCHEMATIC_SETTINGS. | |
| std::shared_ptr< SPICE_SETTINGS > | m_settings |
| std::shared_ptr< SIMULATION_MODEL > | m_simModel |
| < Model that should be simulated. | |
Private Types | |
| typedef void(* | ngSpice_Init) (SendChar *, SendStat *, ControlledExit *, SendData *, SendInitData *, BGThreadRunning *, void *) |
| typedef int(* | ngSpice_Circ) (char **circarray) |
| typedef int(* | ngSpice_Command) (char *command) |
| typedef pvector_info(* | ngGet_Vec_Info) (char *vecname) |
| typedef char *(* | ngCM_Input_Path) (const char *path) |
| typedef char *(* | ngSpice_CurPlot) (void) |
| typedef char **(* | ngSpice_AllPlots) (void) |
| typedef char **(* | ngSpice_AllVecs) (char *plotname) |
| typedef bool(* | ngSpice_Running) (void) |
| typedef int(* | ngSpice_LockRealloc) (void) |
| typedef int(* | ngSpice_UnlockRealloc) (void) |
| Handle to DLL functions. | |
Private Member Functions | |
| void | init_dll () |
| bool | loadSpinit (const std::string &aFileName) |
| void | updateNgspiceSettings () |
| Check a few different locations for codemodel files and returns one if it exists. | |
| std::string | findCmPath () const |
| Send additional search path for codemodels to ngspice. | |
| bool | setCodemodelsInputPath (const std::string &aPath) |
| Load codemodel files from a directory. | |
| bool | loadCodemodels (const std::string &aPath) |
| void | validate () |
| void | installSignalHandlers () |
| void | restoreSignalHandlers () |
Static Private Member Functions | |
| static int | cbSendChar (char *what, int aId, void *aUser) |
| static int | cbSendStat (char *what, int aId, void *aUser) |
| static int | cbBGThreadRunning (NG_BOOL aFinished, int aId, void *aUser) |
| static int | cbControlledExit (int aStatus, NG_BOOL aImmediate, NG_BOOL aExitOnQuit, int aId, void *aUser) |
| static void | signalHandler (int aSignal) |
Private Attributes | |
| ngSpice_Init | m_ngSpice_Init |
| ngSpice_Circ | m_ngSpice_Circ |
| ngSpice_Command | m_ngSpice_Command |
| ngGet_Vec_Info | m_ngGet_Vec_Info |
| ngCM_Input_Path | m_ngCM_Input_Path |
| ngSpice_CurPlot | m_ngSpice_CurPlot |
| ngSpice_AllPlots | m_ngSpice_AllPlots |
| ngSpice_AllVecs | m_ngSpice_AllVecs |
| ngSpice_Running | m_ngSpice_Running |
| ngSpice_LockRealloc | m_ngSpice_LockRealloc |
| ngSpice_UnlockRealloc | m_ngSpice_UnlockRealloc |
| wxDynamicLibrary | m_dll |
| bool | m_error |
| Error flag indicating that ngspice needs to be reloaded. | |
| std::string | m_netlist |
| Current netlist. | |
| std::mutex | m_mutex |
| < For interprocess synchronisation. | |
Static Private Attributes | |
| static bool | m_initialized = false |
| Ngspice should be initialized only once. | |
| static std::atomic< bool > | s_crashed |
| Set by signal handler when ngspice crashes. | |
| static std::atomic< int > | s_crashSignal |
| Signal that caused the crash. | |
| static NGSPICE * | s_currentInstance = nullptr |
| Instance that is currently running ngspice. | |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
| NGSPICE::NGSPICE | ( | ) |
Definition at line 65 of file ngspice.cpp.
References init_dll(), m_error, m_ngCM_Input_Path, m_ngGet_Vec_Info, m_ngSpice_AllPlots, m_ngSpice_AllVecs, m_ngSpice_Circ, m_ngSpice_Command, m_ngSpice_CurPlot, m_ngSpice_Init, m_ngSpice_LockRealloc, m_ngSpice_Running, and m_ngSpice_UnlockRealloc.
Referenced by cbBGThreadRunning(), cbControlledExit(), cbSendChar(), and NGSPICE::NGSPICE_LOCK_REALLOC::NGSPICE_LOCK_REALLOC().
|
virtualdefault |
|
finaloverridevirtual |
Return a requested vector with complex values.
If the vector is real, then the imaginary part is set to 0 in all values.
| aName | is the vector named in Spice convention (e.g. V(3), I(R1)). |
| aMaxLen | is max count of returned values. if -1 (default) all available values are returned. |
Implements SPICE_SIMULATOR.
Definition at line 109 of file ngspice.cpp.
References m_ngSpice_AllVecs, m_ngSpice_CurPlot, and plot.
Referenced by GetXAxis(), and ~NGSPICE().
|
finaloverridevirtual |
Load a netlist for the simulation.
Reimplemented from SIMULATOR.
Definition at line 282 of file ngspice.cpp.
References SIMULATOR::Attach(), Command(), STRING_FORMATTER::GetString(), LoadNetlist(), model, NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_EVENTS, setCodemodelsInputPath(), and updateNgspiceSettings().
Referenced by ~NGSPICE().
|
staticprivate |
Definition at line 761 of file ngspice.cpp.
References NGSPICE(), reporter, sim, SIM_IDLE, and SIM_RUNNING.
Referenced by init_dll().
|
staticprivate |
Definition at line 780 of file ngspice.cpp.
References _, NGSPICE(), reporter, sim, and SIM_IDLE.
Referenced by init_dll().
|
staticprivate |
Definition at line 732 of file ngspice.cpp.
References NGSPICE(), reporter, and sim.
Referenced by init_dll().
|
staticprivate |
Definition at line 755 of file ngspice.cpp.
Referenced by init_dll().
|
finaloverridevirtual |
Cleans simulation data (i.e.
all vectors)
Implements SIMULATOR.
Definition at line 815 of file ngspice.cpp.
References Command().
Referenced by TEST_NETLIST_EXPORTER_SPICE_FIXTURE::CompareNetlists(), and ~NGSPICE().
|
finaloverridevirtual |
Implements SPICE_SIMULATOR.
Definition at line 412 of file ngspice.cpp.
References m_ngSpice_Command, and validate().
Referenced by Attach(), Clean(), TEST_NETLIST_EXPORTER_SPICE_FIXTURE::CompareNetlists(), Init(), init_dll(), loadCodemodels(), LoadNetlist(), loadSpinit(), Run(), Stop(), updateNgspiceSettings(), and ~NGSPICE().
|
staticinherited |
Definition at line 29 of file spice_simulator.cpp.
References DisplayError().
Referenced by KIBIS_PIN::getKuKdFromFile(), and SIMULATOR_FRAME::SIMULATOR_FRAME().
|
finaloverridevirtual |
Implements SPICE_SIMULATOR.
Definition at line 103 of file ngspice.cpp.
References m_ngSpice_CurPlot.
Referenced by ~NGSPICE().
|
private |
Send additional search path for codemodels to ngspice.
Definition at line 673 of file ngspice.cpp.
References path, and traceNgspice.
Referenced by init_dll().
|
finaloverridevirtual |
Return a requested vector with real values.
If the vector is complex, then the real part is returned.
| aName | is the vector named in Spice convention (e.g. V(3), I(R1)). |
| aMaxLen | is max count of returned values. if -1 (default) all available values are returned. |
Implements SPICE_SIMULATOR.
Definition at line 137 of file ngspice.cpp.
References m_ngGet_Vec_Info.
Referenced by ~NGSPICE().
|
finaloverridevirtual |
Return a requested vector with phase values.
| aName | is the vector named in Spice convention (e.g. V(3), I(R1)). |
| aMaxLen | is max count of returned values. if -1 (default) all available values are returned. |
Implements SPICE_SIMULATOR.
Definition at line 222 of file ngspice.cpp.
References m_ngGet_Vec_Info.
Referenced by TEST_NETLIST_EXPORTER_SPICE_FIXTURE::TestPoint(), and ~NGSPICE().
|
finaloverridevirtual |
Return a requested vector with magnitude values.
| aName | is the vector named in Spice convention (e.g. V(3), I(R1)). |
| aMaxLen | is max count of returned values. if -1 (default) all available values are returned. |
Implements SPICE_SIMULATOR.
Definition at line 197 of file ngspice.cpp.
References m_ngGet_Vec_Info.
Referenced by ~NGSPICE().
|
inlineinherited |
Definition at line 51 of file simulator.h.
References m_mutex.
|
finaloverridevirtual |
Cleans simulation data (i.e.
all vectors)
Implements SPICE_SIMULATOR.
Definition at line 473 of file ngspice.cpp.
References m_netlist.
Referenced by ~NGSPICE().
|
finaloverridevirtual |
Return a requested vector with phase values.
| aName | is the vector named in Spice convention (e.g. V(3), I(R1)). |
| aMaxLen | is max count of returned values. if -1 (default) all available values are returned. |
Implements SPICE_SIMULATOR.
Definition at line 252 of file ngspice.cpp.
References m_ngGet_Vec_Info.
Referenced by ~NGSPICE().
|
finaloverridevirtual |
Return a requested vector with imaginary values.
If the vector is complex, then the imaginary part is returned. If the vector is reql, then only zeroes are returned.
| aName | is the vector named in Spice convention (e.g. V(3), I(R1)). |
| aMaxLen | is max count of returned values. if -1 (default) all available values are returned. |
Implements SPICE_SIMULATOR.
Definition at line 167 of file ngspice.cpp.
References m_ngGet_Vec_Info.
Referenced by TEST_NETLIST_EXPORTER_SPICE_FIXTURE::TestOpPoint(), TEST_NETLIST_EXPORTER_SPICE_FIXTURE::TestPoint(), and ~NGSPICE().
|
finaloverridevirtual |
Return current SPICE netlist used by the simulator.
Implements SPICE_SIMULATOR.
Definition at line 449 of file ngspice.cpp.
References NGSPICE_SETTINGS::GetCompatibilityMode(), HSPICE, LT_PSPICE, LTSPICE, NGSPICE, PSPICE, SPICE_SIMULATOR::Settings(), and USER_CONFIG.
Referenced by updateNgspiceSettings(), and ~NGSPICE().
|
finaloverridevirtual |
Implements SPICE_SIMULATOR.
Definition at line 420 of file ngspice.cpp.
References AllVectors(), ST_AC, ST_DC, ST_FFT, ST_NOISE, ST_SP, and ST_TRAN.
Referenced by ~NGSPICE().
|
finaloverridevirtual |
Point out the model that will be used in future simulations.
Implements SPICE_SIMULATOR.
Definition at line 96 of file ngspice.cpp.
References Command(), and updateNgspiceSettings().
|
private |
Definition at line 479 of file ngspice.cpp.
References _, cbBGThreadRunning(), cbControlledExit(), cbSendChar(), cbSendStat(), Command(), findCmPath(), loadCodemodels(), loadSpinit(), m_dll, m_error, m_initialized, m_ngCM_Input_Path, m_ngGet_Vec_Info, m_ngSpice_AllPlots, m_ngSpice_AllVecs, m_ngSpice_Circ, m_ngSpice_Command, m_ngSpice_CurPlot, m_ngSpice_Init, m_ngSpice_LockRealloc, m_ngSpice_Running, m_ngSpice_UnlockRealloc, path, and traceNgspice.
Referenced by NGSPICE(), validate(), and ~NGSPICE().
|
private |
Definition at line 882 of file ngspice.cpp.
References s_crashed, s_crashSignal, s_currentInstance, s_mainThread, s_oldSigAbrt, s_oldSigFpe, s_oldSigSegv, s_signalHandlersInstalled, and signalHandler().
Referenced by Run().
|
finaloverridevirtual |
Execute a Spice command as if it was typed into console.
| aCmd | is the command to be issued. Return X axis name for a given simulation type |
Implements SIMULATOR.
Definition at line 369 of file ngspice.cpp.
References _, m_error, m_ngSpice_Running, SPICE_SIMULATOR::m_reporter, SPICE_SIMULATOR::m_reporterMutex, reporter, restoreSignalHandlers(), s_crashed, and s_crashSignal.
Referenced by TEST_NETLIST_EXPORTER_SPICE_FIXTURE::CompareNetlists(), and ~NGSPICE().
|
private |
|
finaloverridevirtual |
Execute the simulation with currently loaded netlist.
Implements SPICE_SIMULATOR.
Definition at line 312 of file ngspice.cpp.
References Command(), m_netlist, m_ngSpice_Circ, and netlist.
Referenced by Attach(), TEST_NETLIST_EXPORTER_SPICE_FIXTURE::CompareNetlists(), and ~NGSPICE().
|
private |
|
private |
Definition at line 905 of file ngspice.cpp.
References s_currentInstance, s_oldSigAbrt, s_oldSigFpe, s_oldSigSegv, and s_signalHandlersInstalled.
Referenced by IsRunning(), and Stop().
|
finaloverridevirtual |
Halt the simulation.
Implements SIMULATOR.
Definition at line 346 of file ngspice.cpp.
References Command(), and installSignalHandlers().
Referenced by TEST_NETLIST_EXPORTER_SPICE_FIXTURE::CompareNetlists(), and ~NGSPICE().
|
private |
Load codemodel files from a directory.
Definition at line 707 of file ngspice.cpp.
References m_ngCM_Input_Path.
Referenced by Attach().
|
inlinevirtualinherited |
Set a SIMULATOR_REPORTER object to receive the simulation log.
The reporter is accessed from ngspice background threads via atomic snapshot. Callers must ensure the reporter outlives any running simulation, or call SetReporter(nullptr) and stop the simulation before destroying the reporter. SetReporter blocks until any in-flight reporter callback has returned, so the caller can safely destroy the reporter once SetReporter(nullptr) has returned.
Definition at line 89 of file spice_simulator.h.
References m_reporter, and m_reporterMutex.
Referenced by TEST_NETLIST_EXPORTER_SPICE_FIXTURE::CompareNetlists().
|
inlineinherited |
Return the simulator configuration settings.
Definition at line 175 of file spice_simulator.h.
References m_settings.
Referenced by NGSPICE::GetSettingCommands(), SIMULATOR_FRAME_UI::InitWorkbook(), SIMULATOR_FRAME_UI::LoadWorkbook(), and SIMULATOR_FRAME_UI::SaveWorkbook().
|
inlineinherited |
Definition at line 177 of file spice_simulator.h.
References m_settings.
|
staticprivate |
Definition at line 835 of file ngspice.cpp.
References s_crashed, s_crashSignal, s_currentInstance, s_mainThread, s_oldSigAbrt, s_oldSigFpe, and s_oldSigSegv.
Referenced by installSignalHandlers().
|
finaloverridevirtual |
Check if simulation is running at the moment.
Implements SIMULATOR.
Definition at line 357 of file ngspice.cpp.
References Command(), restoreSignalHandlers(), and result.
Referenced by ~NGSPICE().
|
staticinherited |
Return a string with simulation name based on enum.
| aType | is the enum describing simulation type |
| aShortName | if true - return is in format "TRAN", "OP". if false - return is in format "Transient", "Operating Point". |
Definition at line 49 of file spice_simulator.cpp.
References _, ST_AC, ST_DC, ST_DISTO, ST_FFT, ST_NOISE, ST_OP, ST_PZ, ST_SENS, ST_SP, ST_TF, ST_TRAN, and ST_UNKNOWN.
Referenced by BOOST_AUTO_TEST_CASE(), DIALOG_SIM_COMMAND::OnCommandType(), DIALOG_SIM_COMMAND::parseCommand(), SIMULATOR_FRAME_UI::SaveWorkbook(), and SIMULATOR_FRAME_UI::UpdateMeasurement().
|
private |
Check a few different locations for codemodel files and returns one if it exists.
Definition at line 86 of file ngspice.cpp.
References Command(), GetSettingCommands(), and traceNgspice.
|
private |
Definition at line 805 of file ngspice.cpp.
References init_dll(), m_error, and m_initialized.
Referenced by Command().
|
private |
Definition at line 147 of file ngspice.h.
Referenced by init_dll().
|
private |
Error flag indicating that ngspice needs to be reloaded.
Definition at line 208 of file ngspice.h.
Referenced by init_dll(), IsRunning(), NGSPICE(), and validate().
|
staticprivate |
Ngspice should be initialized only once.
Definition at line 210 of file ngspice.h.
Referenced by init_dll(), and validate().
|
privateinherited |
< For interprocess synchronisation.
Definition at line 102 of file simulator.h.
Referenced by GetMutex().
|
private |
Current netlist.
Definition at line 212 of file ngspice.h.
Referenced by GetNetlist(), and LoadNetlist().
|
private |
Definition at line 139 of file ngspice.h.
Referenced by init_dll(), NGSPICE(), and setCodemodelsInputPath().
|
private |
Definition at line 138 of file ngspice.h.
Referenced by GetComplexVector(), GetGainVector(), GetImaginaryVector(), GetPhaseVector(), GetRealVector(), init_dll(), and NGSPICE().
|
private |
Definition at line 141 of file ngspice.h.
Referenced by init_dll(), and NGSPICE().
|
private |
Definition at line 142 of file ngspice.h.
Referenced by AllVectors(), init_dll(), and NGSPICE().
|
private |
Definition at line 136 of file ngspice.h.
Referenced by init_dll(), LoadNetlist(), and NGSPICE().
|
private |
Definition at line 137 of file ngspice.h.
Referenced by Command(), init_dll(), and NGSPICE().
|
private |
Definition at line 140 of file ngspice.h.
Referenced by AllVectors(), CurrentPlotName(), init_dll(), and NGSPICE().
|
private |
Definition at line 135 of file ngspice.h.
Referenced by init_dll(), and NGSPICE().
|
private |
Definition at line 144 of file ngspice.h.
Referenced by init_dll(), and NGSPICE().
|
private |
Definition at line 143 of file ngspice.h.
Referenced by init_dll(), IsRunning(), and NGSPICE().
|
private |
Definition at line 145 of file ngspice.h.
Referenced by init_dll(), and NGSPICE().
|
protectedinherited |
< Reporter object to receive simulation log (not owned, accessed from BG threads).
Held by BG threads while invoking the reporter and by SetReporter while swapping the pointer, so SetReporter(nullptr) can serve as a barrier before the caller destroys the reporter.
Definition at line 191 of file spice_simulator.h.
Referenced by NGSPICE::IsRunning(), SetReporter(), and SPICE_SIMULATOR().
|
protectedinherited |
We don't own this. We are just borrowing it from the SCHEMATIC_SETTINGS.
Definition at line 196 of file spice_simulator.h.
Referenced by NGSPICE::IsRunning(), and SetReporter().
|
protectedinherited |
Definition at line 199 of file spice_simulator.h.
Referenced by Settings(), Settings(), and SPICE_SIMULATOR().
|
protectedinherited |
< Model that should be simulated.
Definition at line 98 of file simulator.h.
Referenced by Attach(), and SIMULATOR().
|
staticprivate |
Set by signal handler when ngspice crashes.
Definition at line 214 of file ngspice.h.
Referenced by installSignalHandlers(), IsRunning(), and signalHandler().
|
staticprivate |
Signal that caused the crash.
Definition at line 215 of file ngspice.h.
Referenced by installSignalHandlers(), IsRunning(), and signalHandler().
|
staticprivate |
Instance that is currently running ngspice.
Definition at line 216 of file ngspice.h.
Referenced by installSignalHandlers(), restoreSignalHandlers(), and signalHandler().