KiCad PCB EDA Suite
SPICE_SIMULATOR Class Referenceabstract

#include <spice_simulator.h>

Inheritance diagram for SPICE_SIMULATOR:
SIMULATOR NGSPICE

Public Member Functions

 SPICE_SIMULATOR ()
 
virtual ~SPICE_SIMULATOR ()
 
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 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
 
std::mutex & GetMutex ()
 
virtual bool Attach (const std::shared_ptr< SIMULATION_MODEL > &aModel)
 Point out the model that will be used in future simulations. 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 void Clean ()=0
 Cleans simulation data (i.e. More...
 

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

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

Private Attributes

std::mutex m_mutex
 < For interprocess synchronisation. More...
 

Detailed Description

Definition at line 47 of file spice_simulator.h.

Constructor & Destructor Documentation

◆ SPICE_SIMULATOR()

SPICE_SIMULATOR::SPICE_SIMULATOR ( )
inline

Definition at line 50 of file spice_simulator.h.

50 :
51 SIMULATOR(),
52 m_reporter( nullptr ),
53 m_settings( nullptr )
54 {}
SIMULATOR()
Definition: simulator.h: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

Definition at line 56 of file spice_simulator.h.

56{}

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.

◆ Attach()

virtual bool SIMULATOR::Attach ( const std::shared_ptr< SIMULATION_MODEL > &  aModel)
inlinevirtualinherited

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

Returns
True in case of success, false otherwise.

Reimplemented in NGSPICE.

Definition at line 73 of file simulator.h.

74 {
75 m_simModel = aModel;
76 return true;
77 }
std::shared_ptr< SIMULATION_MODEL > m_simModel
< Model that should be simulated.
Definition: simulator.h:110

References SIMULATOR::m_simModel.

Referenced by NGSPICE::Attach().

◆ Clean()

virtual void SIMULATOR::Clean ( )
pure virtualinherited

Cleans simulation data (i.e.

all vectors)

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 > SIMULATOR::CreateInstance ( const std::string &  aName)
staticinherited

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:280

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.

◆ GetMutex()

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

Definition at line 63 of file simulator.h.

64 {
65 return m_mutex;
66 }
std::mutex m_mutex
< For interprocess synchronisation.
Definition: simulator.h:114

References SIMULATOR::m_mutex.

◆ 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 SIMULATOR::IsRunning ( )
pure virtualinherited

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 SIMULATOR::Run ( )
pure virtualinherited

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 84 of file spice_simulator.h.

85 {
86 m_reporter = aReporter;
87 }

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 166 of file spice_simulator.h.

166{ return 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 168 of file spice_simulator.h.

168{ return m_settings; }

References m_settings.

◆ Stop()

virtual bool SIMULATOR::Stop ( )
pure virtualinherited

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)
@ ST_TRANS_FUNC
Definition: sim_types.h:41
@ ST_TRANSIENT
Definition: sim_types.h:42
@ ST_DISTORTION
Definition: sim_types.h:36
@ ST_UNKNOWN
Definition: sim_types.h:33
@ ST_NOISE
Definition: sim_types.h:37
@ ST_AC
Definition: sim_types.h:34
@ ST_POLE_ZERO
Definition: sim_types.h:39
@ ST_DC
Definition: sim_types.h:35
@ ST_OP
Definition: sim_types.h:38
@ ST_SENSITIVITY
Definition: sim_types.h:40

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_mutex

std::mutex SIMULATOR::m_mutex
privateinherited

< For interprocess synchronisation.

Definition at line 114 of file simulator.h.

Referenced by SIMULATOR::GetMutex().

◆ 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 182 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 185 of file spice_simulator.h.

Referenced by Settings().

◆ m_simModel

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

< Model that should be simulated.

Definition at line 110 of file simulator.h.

Referenced by SIMULATOR::Attach().


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