KiCad PCB EDA Suite
SPICE_SIMULATOR Class Referenceabstract

#include <spice_simulator.h>

Inheritance diagram for SPICE_SIMULATOR:
NGSPICE

Public Member Functions

 SPICE_SIMULATOR ()
 
virtual ~SPICE_SIMULATOR ()
 Create a simulator instance of particular type (currently only ngspice is handled) More...
 
virtual void Init (const SPICE_SIMULATOR_SETTINGS *aSettings=nullptr)=0
 
virtual bool LoadNetlist (const std::string &aNetlist)=0
 Load a netlist for the simulation. More...
 
virtual bool Run ()=0
 Execute the simulation with currently loaded netlist. More...
 
virtual bool Stop ()=0
 Halt the simulation. More...
 
virtual bool IsRunning ()=0
 Check if simulation is running at the moment. More...
 
virtual bool Command (const std::string &aCmd)=0
 Execute a Spice command as if it was typed into console. More...
 
virtual std::string GetXAxis (SIM_TYPE aType) const =0
 Set a SPICE_REPORTER object to receive the simulation log. More...
 
virtual void SetReporter (SPICE_REPORTER *aReporter)
 
virtual std::vector< std::string > AllPlots () const =0
 Return a list with all vectors generated in current simulation. More...
 
virtual std::vector< COMPLEXGetPlot (const std::string &aName, int aMaxLen=-1)=0
 Return a requested vector with complex values. More...
 
virtual std::vector< double > GetRealPlot (const std::string &aName, int aMaxLen=-1)=0
 Return a requested vector with real values. More...
 
virtual std::vector< double > GetImagPlot (const std::string &aName, int aMaxLen=-1)=0
 Return a requested vector with imaginary values. More...
 
virtual std::vector< double > GetMagPlot (const std::string &aName, int aMaxLen=-1)=0
 Return a requested vector with magnitude values. More...
 
virtual std::vector< double > GetPhasePlot (const std::string &aName, int aMaxLen=-1)=0
 Return a requested vector with phase values. More...
 
virtual const std::string GetNetlist () const =0
 Return current SPICE netlist used by the simulator. More...
 
virtual std::vector< std::string > GetSettingCommands () const =0
 
std::shared_ptr< SPICE_SIMULATOR_SETTINGS > & Settings ()
 Return the simulator configuration settings. More...
 
const std::shared_ptr< SPICE_SIMULATOR_SETTINGS > & Settings () const
 

Static Public Member Functions

static std::shared_ptr< SPICE_SIMULATORCreateInstance (const std::string &aName)
 
static wxString TypeToName (SIM_TYPE aType, bool aShortName)
 Return a string with simulation name based on enum. More...
 

Protected Attributes

SPICE_REPORTERm_reporter
 < Reporter object to receive simulation log. More...
 
std::shared_ptr< SPICE_SIMULATOR_SETTINGSm_settings
 

Detailed Description

Definition at line 45 of file spice_simulator.h.

Constructor & Destructor Documentation

◆ SPICE_SIMULATOR()

SPICE_SIMULATOR::SPICE_SIMULATOR ( )
inline

Definition at line 48 of file spice_simulator.h.

48  :
49  m_reporter( nullptr ),
50  m_settings( nullptr )
51  {}
SPICE_REPORTER * m_reporter
< Reporter object to receive simulation log.
std::shared_ptr< SPICE_SIMULATOR_SETTINGS > m_settings

◆ ~SPICE_SIMULATOR()

virtual SPICE_SIMULATOR::~SPICE_SIMULATOR ( )
inlinevirtual

Create a simulator instance of particular type (currently only ngspice is handled)

Definition at line 53 of file spice_simulator.h.

Member Function Documentation

◆ AllPlots()

virtual std::vector<std::string> SPICE_SIMULATOR::AllPlots ( ) const
pure virtual

Return a list with all vectors generated in current simulation.

Returns
List of vector names. ?May not match to the net name elements.

Implemented in NGSPICE.

◆ Command()

virtual bool SPICE_SIMULATOR::Command ( const std::string &  aCmd)
pure virtual

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

Implemented in NGSPICE.

◆ CreateInstance()

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

Definition at line 30 of file spice_simulator.cpp.

31 {
32  try
33  {
34  static std::shared_ptr<SPICE_SIMULATOR> ngspiceInstance;
35 
36  if( !ngspiceInstance )
37  ngspiceInstance = std::make_shared<NGSPICE>();
38 
39  return ngspiceInstance;
40  }
41  catch( std::exception& e )
42  {
43  DisplayError( nullptr, e.what() );
44  }
45 
46  return nullptr;
47 }
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:279

References DisplayError().

Referenced by SIM_PLOT_FRAME::SIM_PLOT_FRAME().

◆ GetImagPlot()

virtual std::vector<double> SPICE_SIMULATOR::GetImagPlot ( const std::string &  aName,
int  aMaxLen = -1 
)
pure virtual

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.

Implemented in NGSPICE.

◆ GetMagPlot()

virtual std::vector<double> SPICE_SIMULATOR::GetMagPlot ( const std::string &  aName,
int  aMaxLen = -1 
)
pure virtual

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.

Implemented in NGSPICE.

◆ GetNetlist()

virtual const std::string SPICE_SIMULATOR::GetNetlist ( ) const
pure virtual

Return current SPICE netlist used by the simulator.

Returns
The netlist.

Implemented in NGSPICE.

◆ GetPhasePlot()

virtual std::vector<double> SPICE_SIMULATOR::GetPhasePlot ( const std::string &  aName,
int  aMaxLen = -1 
)
pure virtual

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.

Implemented in NGSPICE.

◆ GetPlot()

virtual std::vector<COMPLEX> SPICE_SIMULATOR::GetPlot ( const std::string &  aName,
int  aMaxLen = -1 
)
pure virtual

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.

Implemented in NGSPICE.

◆ GetRealPlot()

virtual std::vector<double> SPICE_SIMULATOR::GetRealPlot ( const std::string &  aName,
int  aMaxLen = -1 
)
pure virtual

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.

Implemented in NGSPICE.

◆ GetSettingCommands()

virtual std::vector<std::string> SPICE_SIMULATOR::GetSettingCommands ( ) const
pure virtual
Returns
a list of simulator setting command strings.

Implemented in NGSPICE.

◆ GetXAxis()

virtual std::string SPICE_SIMULATOR::GetXAxis ( SIM_TYPE  aType) const
pure virtual

Set a SPICE_REPORTER object to receive the simulation log.

Implemented in NGSPICE.

◆ Init()

virtual void SPICE_SIMULATOR::Init ( const SPICE_SIMULATOR_SETTINGS aSettings = nullptr)
pure virtual

Implemented in NGSPICE.

◆ IsRunning()

virtual bool SPICE_SIMULATOR::IsRunning ( )
pure virtual

Check if simulation is running at the moment.

Returns
True if simulation is currently executed.

Implemented in NGSPICE.

◆ LoadNetlist()

virtual bool SPICE_SIMULATOR::LoadNetlist ( const std::string &  aNetlist)
pure virtual

Load a netlist for the simulation.

Returns
True in case of success, false otherwise.

Implemented in NGSPICE.

◆ Run()

virtual bool SPICE_SIMULATOR::Run ( )
pure virtual

Execute the simulation with currently loaded netlist.

Returns
True in case of success, false otherwise.

Implemented in NGSPICE.

◆ SetReporter()

virtual void SPICE_SIMULATOR::SetReporter ( SPICE_REPORTER aReporter)
inlinevirtual

Definition at line 105 of file spice_simulator.h.

106  {
107  m_reporter = aReporter;
108  }
SPICE_REPORTER * m_reporter
< Reporter object to receive simulation log.

References m_reporter.

◆ Settings() [1/2]

std::shared_ptr<SPICE_SIMULATOR_SETTINGS>& SPICE_SIMULATOR::Settings ( )
inline

Return the simulator configuration settings.

Returns
the simulator specific settings.

Definition at line 187 of file spice_simulator.h.

187 { return m_settings; }
std::shared_ptr< SPICE_SIMULATOR_SETTINGS > m_settings

References m_settings.

Referenced by NGSPICE::GetSettingCommands().

◆ Settings() [2/2]

const std::shared_ptr<SPICE_SIMULATOR_SETTINGS>& SPICE_SIMULATOR::Settings ( ) const
inline

Definition at line 189 of file spice_simulator.h.

189 { return m_settings; }
std::shared_ptr< SPICE_SIMULATOR_SETTINGS > m_settings

References m_settings.

◆ Stop()

virtual bool SPICE_SIMULATOR::Stop ( )
pure virtual

Halt the simulation.

Returns
True in case of success, false otherwise.

Implemented in NGSPICE.

◆ TypeToName()

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

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 50 of file spice_simulator.cpp.

51 {
52  switch( aType )
53  {
54  case ST_OP:
55  return aShortName ? wxT( "OP" ) : _( "Operating Point" );
56 
57  case ST_AC:
58  return "AC";
59 
60  case ST_DC:
61  return aShortName ? wxT( "DC" ) : _( "DC Sweep" );
62 
63  case ST_TRANSIENT:
64  return aShortName ? wxT( "TRAN" ) : _( "Transient" );
65 
66  case ST_DISTORTION:
67  return aShortName ? wxT( "DISTO" ) : _( "Distortion" );
68 
69  case ST_NOISE:
70  return aShortName ? wxT( "NOISE" ) : _( "Noise" );
71 
72  case ST_POLE_ZERO:
73  return aShortName ? wxT( "PZ" ) : _( "Pole-zero" );
74 
75  case ST_SENSITIVITY:
76  return aShortName ? wxT( "SENS" ) : _( "Sensitivity" );
77 
78  case ST_TRANS_FUNC:
79  return aShortName ? wxT( "TF" ) : _( "Transfer function" );
80 
81  default:
82  case ST_UNKNOWN:
83  return aShortName ? _( "UNKNOWN!" ) : _( "Unknown" );
84  }
85 }
#define _(s)

References _, ST_AC, ST_DC, ST_DISTORTION, ST_NOISE, ST_OP, ST_POLE_ZERO, ST_SENSITIVITY, ST_TRANS_FUNC, ST_TRANSIENT, and ST_UNKNOWN.

Member Data Documentation

◆ m_reporter

SPICE_REPORTER* SPICE_SIMULATOR::m_reporter
protected

< Reporter object to receive simulation log.

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

Definition at line 203 of file spice_simulator.h.

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

◆ m_settings

std::shared_ptr<SPICE_SIMULATOR_SETTINGS> SPICE_SIMULATOR::m_settings
protected

Definition at line 206 of file spice_simulator.h.

Referenced by Settings().


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