KiCad PCB EDA Suite
Loading...
Searching...
No Matches
NGSPICE Class Reference

#include <ngspice.h>

Inheritance diagram for NGSPICE:
SPICE_SIMULATOR SIMULATOR

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. More...
 
bool Attach (const std::shared_ptr< SIMULATION_MODEL > &aModel, const wxString &aSimCommand, unsigned aSimOptions, REPORTER &aReporter) override final
 Load a netlist for the simulation. More...
 
bool LoadNetlist (const std::string &aNetlist) override final
 Execute the simulation with currently loaded netlist. More...
 
bool Run () override final
 Halt the simulation. More...
 
bool Stop () override final
 Check if simulation is running at the moment. More...
 
bool IsRunning () override final
 Execute a Spice command as if it was typed into console. More...
 
bool Command (const std::string &aCmd) override final
 Set a SIMULATOR_REPORTER object to receive the simulation log. More...
 
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. More...
 
std::vector< COMPLEXGetComplexVector (const std::string &aName, int aMaxLen=-1) override final
 Return a requested vector with real values. More...
 
std::vector< double > GetRealVector (const std::string &aName, int aMaxLen=-1) override final
 Return a requested vector with imaginary values. More...
 
std::vector< double > GetImaginaryVector (const std::string &aName, int aMaxLen=-1) override final
 Return a requested vector with magnitude values. More...
 
std::vector< double > GetGainVector (const std::string &aName, int aMaxLen=-1) override final
 Return a requested vector with phase values. More...
 
std::vector< double > GetPhaseVector (const std::string &aName, int aMaxLen=-1) override final
 Return a requested vector with phase values. More...
 
std::vector< std::string > GetSettingCommands () const override final
 Return current SPICE netlist used by the simulator. More...
 
virtual const std::string GetNetlist () const override final
 Cleans simulation data (i.e. More...
 
void Clean () override final
 Cleans simulation data (i.e. More...
 
virtual void SetReporter (SIMULATOR_REPORTER *aReporter)
 
std::shared_ptr< SPICE_SETTINGS > & Settings ()
 Return the simulator configuration settings. More...
 
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. More...
 
static std::shared_ptr< SPICE_SIMULATORCreateInstance (const std::string &aName)
 

Protected Attributes

SIMULATOR_REPORTERm_reporter
 < Reporter object to receive simulation log. More...
 
std::shared_ptr< SPICE_SETTINGSm_settings
 
std::shared_ptr< SIMULATION_MODELm_simModel
 < Model that should be simulated. More...
 

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 *(* 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. More...
 

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. More...
 
std::string findCmPath () const
 Load codemodel files from a directory. More...
 
bool loadCodemodels (const std::string &aPath)
 
void validate ()
 

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)
 

Private Attributes

ngSpice_Init m_ngSpice_Init
 
ngSpice_Circ m_ngSpice_Circ
 
ngSpice_Command m_ngSpice_Command
 
ngGet_Vec_Info m_ngGet_Vec_Info
 
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. More...
 
std::string m_netlist
 Current netlist. More...
 
std::mutex m_mutex
 < For interprocess synchronisation. More...
 

Static Private Attributes

static bool m_initialized = false
 Ngspice should be initialized only once. More...
 

Detailed Description

Definition at line 52 of file ngspice.h.

Member Typedef Documentation

◆ ngGet_Vec_Info

typedef pvector_info(* NGSPICE::ngGet_Vec_Info) (char *vecname)
private

Definition at line 121 of file ngspice.h.

◆ ngSpice_AllPlots

typedef char **(* NGSPICE::ngSpice_AllPlots) (void)
private

Definition at line 123 of file ngspice.h.

◆ ngSpice_AllVecs

typedef char **(* NGSPICE::ngSpice_AllVecs) (char *plotname)
private

Definition at line 124 of file ngspice.h.

◆ ngSpice_Circ

typedef int(* NGSPICE::ngSpice_Circ) (char **circarray)
private

Definition at line 119 of file ngspice.h.

◆ ngSpice_Command

typedef int(* NGSPICE::ngSpice_Command) (char *command)
private

Definition at line 120 of file ngspice.h.

◆ ngSpice_CurPlot

typedef char *(* NGSPICE::ngSpice_CurPlot) (void)
private

Definition at line 122 of file ngspice.h.

◆ ngSpice_Init

typedef void(* NGSPICE::ngSpice_Init) (SendChar *, SendStat *, ControlledExit *, SendData *, SendInitData *, BGThreadRunning *, void *)
private

Definition at line 117 of file ngspice.h.

◆ ngSpice_LockRealloc

typedef int(* NGSPICE::ngSpice_LockRealloc) (void)
private

Definition at line 126 of file ngspice.h.

◆ ngSpice_Running

typedef bool(* NGSPICE::ngSpice_Running) (void)
private

Definition at line 125 of file ngspice.h.

◆ ngSpice_UnlockRealloc

typedef int(* NGSPICE::ngSpice_UnlockRealloc) (void)
private

Handle to DLL functions.

Definition at line 127 of file ngspice.h.

Constructor & Destructor Documentation

◆ NGSPICE()

NGSPICE::NGSPICE ( )

Definition at line 57 of file ngspice.cpp.

References init_dll().

◆ ~NGSPICE()

NGSPICE::~NGSPICE ( )
virtualdefault

Member Function Documentation

◆ AllVectors()

std::vector< std::string > NGSPICE::AllVectors ( ) const
finaloverridevirtual

Return a requested vector with complex values.

If the vector is real, then the imaginary part is set to 0 in all values.

Parameters
aNameis the vector named in Spice convention (e.g. V(3), I(R1)).
aMaxLenis max count of returned values. if -1 (default) all available values are returned.
Returns
Requested vector. It might be empty if there is no vector with requested name.

Implements SPICE_SIMULATOR.

Definition at line 100 of file ngspice.cpp.

References m_ngSpice_AllVecs, m_ngSpice_CurPlot, and plot.

Referenced by GetXAxis().

◆ Attach()

bool NGSPICE::Attach ( const std::shared_ptr< SIMULATION_MODEL > &  aModel,
const wxString &  aSimCommand,
unsigned  aSimOptions,
REPORTER aReporter 
)
finaloverridevirtual

Load a netlist for the simulation.

Reimplemented from SIMULATOR.

Definition at line 276 of file ngspice.cpp.

References SIMULATOR::Attach(), SPICE_CIRCUIT_MODEL::GetNetlist(), STRING_FORMATTER::GetString(), LoadNetlist(), and updateNgspiceSettings().

◆ cbBGThreadRunning()

int NGSPICE::cbBGThreadRunning ( NG_BOOL  aFinished,
int  aId,
void *  aUser 
)
staticprivate

◆ cbControlledExit()

int NGSPICE::cbControlledExit ( int  aStatus,
NG_BOOL  aImmediate,
NG_BOOL  aExitOnQuit,
int  aId,
void *  aUser 
)
staticprivate

Definition at line 686 of file ngspice.cpp.

References m_error.

Referenced by init_dll().

◆ cbSendChar()

int NGSPICE::cbSendChar ( char *  what,
int  aId,
void *  aUser 
)
staticprivate

Definition at line 649 of file ngspice.cpp.

References SPICE_SIMULATOR::m_reporter, and REPORTER::Report().

Referenced by init_dll().

◆ cbSendStat()

int NGSPICE::cbSendStat ( char *  what,
int  aId,
void *  aUser 
)
staticprivate

Definition at line 669 of file ngspice.cpp.

Referenced by init_dll().

◆ Clean()

void NGSPICE::Clean ( )
finaloverridevirtual

Cleans simulation data (i.e.

all vectors)

Implements SIMULATOR.

Definition at line 707 of file ngspice.cpp.

References Command().

◆ Command()

bool NGSPICE::Command ( const std::string &  aCmd)
finaloverridevirtual

◆ CreateInstance()

std::shared_ptr< SPICE_SIMULATOR > SIMULATOR::CreateInstance ( const std::string &  aName)
staticinherited

Definition at line 33 of file spice_simulator.cpp.

References DisplayError().

Referenced by KIBIS_PIN::getKuKdFromFile(), and SIMULATOR_FRAME::SIMULATOR_FRAME().

◆ CurrentPlotName()

wxString NGSPICE::CurrentPlotName ( ) const
finaloverridevirtual

Returns
list of simulation vector (signal) names.

Implements SPICE_SIMULATOR.

Definition at line 94 of file ngspice.cpp.

References m_ngSpice_CurPlot.

◆ findCmPath()

std::string NGSPICE::findCmPath ( ) const
private

Load codemodel files from a directory.

Definition at line 603 of file ngspice.cpp.

References path, and traceNgspice.

Referenced by init_dll().

◆ GetComplexVector()

std::vector< COMPLEX > NGSPICE::GetComplexVector ( const std::string &  aName,
int  aMaxLen = -1 
)
finaloverridevirtual

Return a requested vector with real values.

If the vector is complex, then the real part is returned.

Parameters
aNameis the vector named in Spice convention (e.g. V(3), I(R1)).
aMaxLenis max count of returned values. if -1 (default) all available values are returned.
Returns
Requested vector. It might be empty if there is no vector with requested name.

Implements SPICE_SIMULATOR.

Definition at line 128 of file ngspice.cpp.

References m_ngGet_Vec_Info.

◆ GetGainVector()

std::vector< double > NGSPICE::GetGainVector ( const std::string &  aName,
int  aMaxLen = -1 
)
finaloverridevirtual

Return a requested vector with phase values.

Parameters
aNameis the vector named in Spice convention (e.g. V(3), I(R1)).
aMaxLenis max count of returned values. if -1 (default) all available values are returned.
Returns
Requested vector. It might be empty if there is no vector with requested name.

Implements SPICE_SIMULATOR.

Definition at line 216 of file ngspice.cpp.

References m_ngGet_Vec_Info.

Referenced by TEST_NETLIST_EXPORTER_SPICE_FIXTURE::TestPoint().

◆ GetImaginaryVector()

std::vector< double > NGSPICE::GetImaginaryVector ( const std::string &  aName,
int  aMaxLen = -1 
)
finaloverridevirtual

Return a requested vector with magnitude values.

Parameters
aNameis the vector named in Spice convention (e.g. V(3), I(R1)).
aMaxLenis max count of returned values. if -1 (default) all available values are returned.
Returns
Requested vector. It might be empty if there is no vector with requested name.

Implements SPICE_SIMULATOR.

Definition at line 191 of file ngspice.cpp.

References m_ngGet_Vec_Info.

◆ GetMutex()

std::mutex & SIMULATOR::GetMutex ( )
inlineinherited

Definition at line 51 of file simulator.h.

References SIMULATOR::m_mutex.

◆ GetNetlist()

const std::string NGSPICE::GetNetlist ( ) const
finaloverridevirtual

Cleans simulation data (i.e.

all vectors)

Implements SPICE_SIMULATOR.

Definition at line 407 of file ngspice.cpp.

References m_netlist.

◆ GetPhaseVector()

std::vector< double > NGSPICE::GetPhaseVector ( const std::string &  aName,
int  aMaxLen = -1 
)
finaloverridevirtual

Return a requested vector with phase values.

Parameters
aNameis the vector named in Spice convention (e.g. V(3), I(R1)).
aMaxLenis max count of returned values. if -1 (default) all available values are returned.
Returns
Requested vector. It might be empty if there is no vector with requested name.

Implements SPICE_SIMULATOR.

Definition at line 246 of file ngspice.cpp.

References m_ngGet_Vec_Info.

◆ GetRealVector()

std::vector< double > NGSPICE::GetRealVector ( const std::string &  aName,
int  aMaxLen = -1 
)
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.

Parameters
aNameis the vector named in Spice convention (e.g. V(3), I(R1)).
aMaxLenis max count of returned values. if -1 (default) all available values are returned.
Returns
Requested vector. It might be empty if there is no vector with requested name.

Implements SPICE_SIMULATOR.

Definition at line 158 of file ngspice.cpp.

References m_ngGet_Vec_Info.

Referenced by TEST_NETLIST_EXPORTER_SPICE_FIXTURE::TestOpPoint(), and TEST_NETLIST_EXPORTER_SPICE_FIXTURE::TestPoint().

◆ GetSettingCommands()

std::vector< std::string > NGSPICE::GetSettingCommands ( ) const
finaloverridevirtual

Return current SPICE netlist used by the simulator.

Returns
The netlist.

Implements SPICE_SIMULATOR.

Definition at line 383 of file ngspice.cpp.

References NGSPICE_SETTINGS::GetCompatibilityMode(), and SPICE_SIMULATOR::Settings().

Referenced by updateNgspiceSettings().

◆ GetXAxis()

wxString NGSPICE::GetXAxis ( SIM_TYPE  aType) const
finaloverridevirtual

Returns
the current simulation plot name (tran1, tran2, etc.)

Implements SPICE_SIMULATOR.

Definition at line 354 of file ngspice.cpp.

References AllVectors(), ST_AC, ST_DC, ST_FFT, ST_NOISE, ST_SP, and ST_TRAN.

◆ Init()

void NGSPICE::Init ( const SPICE_SETTINGS aSettings = nullptr)
finaloverridevirtual

Point out the model that will be used in future simulations.

Returns
True in case of success, false otherwise.

Implements SPICE_SIMULATOR.

Definition at line 87 of file ngspice.cpp.

References Command(), and updateNgspiceSettings().

◆ init_dll()

◆ IsRunning()

bool NGSPICE::IsRunning ( )
finaloverridevirtual

Execute a Spice command as if it was typed into console.

Parameters
aCmdis the command to be issued. Return X axis name for a given simulation type

Implements SIMULATOR.

Definition at line 339 of file ngspice.cpp.

References m_ngSpice_Running.

Referenced by TEST_NETLIST_EXPORTER_SPICE_FIXTURE::CompareNetlists().

◆ loadCodemodels()

bool NGSPICE::loadCodemodels ( const std::string &  aPath)
private

Definition at line 637 of file ngspice.cpp.

References Command().

Referenced by init_dll().

◆ LoadNetlist()

bool NGSPICE::LoadNetlist ( const std::string &  aNetlist)
finaloverridevirtual

Execute the simulation with currently loaded netlist.

Returns
True in case of success, false otherwise.

Implements SPICE_SIMULATOR.

Definition at line 297 of file ngspice.cpp.

References Command(), m_netlist, and m_ngSpice_Circ.

Referenced by Attach(), and TEST_NETLIST_EXPORTER_SPICE_FIXTURE::CompareNetlists().

◆ loadSpinit()

bool NGSPICE::loadSpinit ( const std::string &  aFileName)
private

Definition at line 586 of file ngspice.cpp.

References Command().

Referenced by init_dll().

◆ Run()

bool NGSPICE::Run ( )
finaloverridevirtual

Halt the simulation.

Returns
True in case of success, false otherwise.

Implements SIMULATOR.

Definition at line 325 of file ngspice.cpp.

References Command().

Referenced by TEST_NETLIST_EXPORTER_SPICE_FIXTURE::CompareNetlists().

◆ SetReporter()

virtual void SPICE_SIMULATOR::SetReporter ( SIMULATOR_REPORTER aReporter)
inlinevirtualinherited

◆ Settings() [1/2]

std::shared_ptr< SPICE_SETTINGS > & SPICE_SIMULATOR::Settings ( )
inlineinherited

Return the simulator configuration settings.

Returns
the simulator specific settings.

Definition at line 169 of file spice_simulator.h.

References SPICE_SIMULATOR::m_settings.

Referenced by GetSettingCommands().

◆ Settings() [2/2]

const std::shared_ptr< SPICE_SETTINGS > & SPICE_SIMULATOR::Settings ( ) const
inlineinherited

Definition at line 171 of file spice_simulator.h.

References SPICE_SIMULATOR::m_settings.

◆ Stop()

bool NGSPICE::Stop ( )
finaloverridevirtual

Check if simulation is running at the moment.

Returns
True if simulation is currently executed.

Implements SIMULATOR.

Definition at line 332 of file ngspice.cpp.

References Command().

◆ TypeToName()

wxString SPICE_SIMULATOR::TypeToName ( SIM_TYPE  aType,
bool  aShortName 
)
staticinherited

Return a string with simulation name based on enum.

Parameters
aTypeis the enum describing simulation type
aShortNameif true - return is in format "TRAN", "OP". if false - return is in format "Transient", "Operating Point".
Returns
String with requested name as described above.

Definition at line 53 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 DIALOG_SIM_COMMAND::OnCommandType(), DIALOG_SIM_COMMAND::parseCommand(), and SIMULATOR_FRAME_UI::SaveWorkbook().

◆ updateNgspiceSettings()

void NGSPICE::updateNgspiceSettings ( )
private

Check a few different locations for codemodel files and returns one if it exists.

Definition at line 77 of file ngspice.cpp.

References Command(), GetSettingCommands(), and traceNgspice.

Referenced by Attach(), and Init().

◆ validate()

void NGSPICE::validate ( )
private

Definition at line 697 of file ngspice.cpp.

References init_dll(), m_error, and m_initialized.

Referenced by Command().

Member Data Documentation

◆ m_dll

wxDynamicLibrary NGSPICE::m_dll
private

Definition at line 141 of file ngspice.h.

Referenced by init_dll().

◆ m_error

bool NGSPICE::m_error
private

Error flag indicating that ngspice needs to be reloaded.

Definition at line 185 of file ngspice.h.

Referenced by cbControlledExit(), init_dll(), and validate().

◆ m_initialized

bool NGSPICE::m_initialized = false
staticprivate

Ngspice should be initialized only once.

Definition at line 187 of file ngspice.h.

Referenced by init_dll(), and validate().

◆ m_mutex

std::mutex SIMULATOR::m_mutex
privateinherited

< For interprocess synchronisation.

Definition at line 101 of file simulator.h.

Referenced by SIMULATOR::GetMutex().

◆ m_netlist

std::string NGSPICE::m_netlist
private

Current netlist.

Definition at line 189 of file ngspice.h.

Referenced by GetNetlist(), and LoadNetlist().

◆ m_ngGet_Vec_Info

ngGet_Vec_Info NGSPICE::m_ngGet_Vec_Info
private

◆ m_ngSpice_AllPlots

ngSpice_AllPlots NGSPICE::m_ngSpice_AllPlots
private

Definition at line 135 of file ngspice.h.

Referenced by init_dll().

◆ m_ngSpice_AllVecs

ngSpice_AllVecs NGSPICE::m_ngSpice_AllVecs
private

Definition at line 136 of file ngspice.h.

Referenced by AllVectors(), and init_dll().

◆ m_ngSpice_Circ

ngSpice_Circ NGSPICE::m_ngSpice_Circ
private

Definition at line 131 of file ngspice.h.

Referenced by init_dll(), and LoadNetlist().

◆ m_ngSpice_Command

ngSpice_Command NGSPICE::m_ngSpice_Command
private

Definition at line 132 of file ngspice.h.

Referenced by Command(), and init_dll().

◆ m_ngSpice_CurPlot

ngSpice_CurPlot NGSPICE::m_ngSpice_CurPlot
private

Definition at line 134 of file ngspice.h.

Referenced by AllVectors(), CurrentPlotName(), and init_dll().

◆ m_ngSpice_Init

ngSpice_Init NGSPICE::m_ngSpice_Init
private

Definition at line 130 of file ngspice.h.

Referenced by init_dll().

◆ m_ngSpice_LockRealloc

ngSpice_LockRealloc NGSPICE::m_ngSpice_LockRealloc
private

Definition at line 138 of file ngspice.h.

Referenced by init_dll().

◆ m_ngSpice_Running

ngSpice_Running NGSPICE::m_ngSpice_Running
private

Definition at line 137 of file ngspice.h.

Referenced by init_dll(), and IsRunning().

◆ m_ngSpice_UnlockRealloc

ngSpice_UnlockRealloc NGSPICE::m_ngSpice_UnlockRealloc
private

Definition at line 139 of file ngspice.h.

Referenced by init_dll().

◆ m_reporter

SIMULATOR_REPORTER* SPICE_SIMULATOR::m_reporter
protectedinherited

< Reporter object to receive simulation log.

We don't own this. We are just borrowing it from the SCHEMATIC_SETTINGS.

Definition at line 185 of file spice_simulator.h.

Referenced by cbBGThreadRunning(), cbSendChar(), and SPICE_SIMULATOR::SetReporter().

◆ m_settings

std::shared_ptr<SPICE_SETTINGS> SPICE_SIMULATOR::m_settings
protectedinherited

Definition at line 188 of file spice_simulator.h.

Referenced by SPICE_SIMULATOR::Settings().

◆ m_simModel

std::shared_ptr<SIMULATION_MODEL> SIMULATOR::m_simModel
protectedinherited

< Model that should be simulated.

Definition at line 97 of file simulator.h.

Referenced by SIMULATOR::Attach().


The documentation for this class was generated from the following files: