KiCad PCB EDA Suite
spice_simulator.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2016 CERN
5  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * https://www.gnu.org/licenses/gpl-3.0.html
20  * or you may search the http://www.gnu.org website for the version 3 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef SPICE_SIMULATOR_H
26 #define SPICE_SIMULATOR_H
27 
28 #include "sim_types.h"
29 
30 #include <string>
31 #include <vector>
32 #include <complex>
33 #include <memory>
34 
35 #include <wx/string.h>
36 
37 class SPICE_REPORTER;
39 
40 typedef std::complex<double> COMPLEX;
41 
43 {
44 public:
46  virtual ~SPICE_SIMULATOR() {}
47 
49  static std::shared_ptr<SPICE_SIMULATOR> CreateInstance( const std::string& aName );
50 
52  virtual void Init() = 0;
53 
54  /*
55  * @brief Loads a netlist for the simulation.
56  * @return True in case of success, false otherwise.
57  */
58  virtual bool LoadNetlist( const std::string& aNetlist ) = 0;
59 
64  virtual bool Run() = 0;
65 
70  virtual bool Stop() = 0;
71 
76  virtual bool IsRunning() = 0;
77 
82  virtual bool Command( const std::string& aCmd ) = 0;
83 
85  virtual std::string GetXAxis( SIM_TYPE aType ) const = 0;
86 
88  virtual void SetReporter( SPICE_REPORTER* aReporter )
89  {
90  m_reporter = aReporter;
91  }
92 
98  virtual std::vector<std::string> AllPlots() = 0;
99 
108  virtual std::vector<COMPLEX> GetPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
109 
118  virtual std::vector<double> GetRealPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
119 
128  virtual std::vector<double> GetImagPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
129 
137  virtual std::vector<double> GetMagPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
138 
146  virtual std::vector<double> GetPhasePlot( const std::string& aName, int aMaxLen = -1 ) = 0;
147 
152  virtual const std::string GetNetlist() const = 0;
153 
161  static wxString TypeToName( SIM_TYPE aType, bool aShortName );
162 
163 protected:
166 };
167 
168 #endif /* SPICE_SIMULATOR_H */
virtual std::string GetXAxis(SIM_TYPE aType) const =0
Returns X axis name for a given simulation type
virtual bool IsRunning()=0
Checks if simulation is running at the moment.
virtual std::vector< double > GetPhasePlot(const std::string &aName, int aMaxLen=-1)=0
Returns a requested vector with phase values.
virtual void SetReporter(SPICE_REPORTER *aReporter)
Sets a SPICE_REPORTER object to receive the simulation log.
virtual std::vector< COMPLEX > GetPlot(const std::string &aName, int aMaxLen=-1)=0
Returns a requested vector with complex values.
virtual std::vector< double > GetRealPlot(const std::string &aName, int aMaxLen=-1)=0
Returns a requested vector with real values.
std::complex< double > COMPLEX
virtual const std::string GetNetlist() const =0
Returns current SPICE netlist used by the simulator.
SPICE_REPORTER * m_reporter
Reporter object to receive simulation log
static wxString TypeToName(SIM_TYPE aType, bool aShortName)
Returns a string with simulation name based on enum.
virtual void Init()=0
Initializes the simulator
#define NULL
SIM_TYPE
Possible simulation types
Definition: sim_types.h:29
Interface to receive simulation updates from SPICE_SIMULATOR class.
virtual bool Command(const std::string &aCmd)=0
Executes a Spice command as if it was typed into console.
static std::shared_ptr< SPICE_SIMULATOR > CreateInstance(const std::string &aName)
Creates a simulator instance of particular type (currently only ngspice is handled)
virtual bool LoadNetlist(const std::string &aNetlist)=0
virtual bool Run()=0
Executes the simulation with currently loaded netlist.
virtual std::vector< std::string > AllPlots()=0
Returns a list with all vectors generated in current simulation.
virtual std::vector< double > GetImagPlot(const std::string &aName, int aMaxLen=-1)=0
Returns a requested vector with imaginary values.
virtual bool Stop()=0
Halts the simulation.
virtual ~SPICE_SIMULATOR()
virtual std::vector< double > GetMagPlot(const std::string &aName, int aMaxLen=-1)=0
Returns a requested vector with magnitude values.