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 class SPICE_REPORTER;
37 
38 typedef std::complex<double> COMPLEX;
39 
41 {
42 public:
43  SPICE_SIMULATOR() : m_reporter( NULL ) {}
44  virtual ~SPICE_SIMULATOR() {}
45 
47  static std::shared_ptr<SPICE_SIMULATOR> CreateInstance( const std::string& aName );
48 
50  virtual void Init() = 0;
51 
52  /*
53  * @brief Loads a netlist for the simulation.
54  * @return True in case of success, false otherwise.
55  */
56  virtual bool LoadNetlist( const std::string& aNetlist ) = 0;
57 
62  virtual bool Run() = 0;
63 
68  virtual bool Stop() = 0;
69 
74  virtual bool IsRunning() = 0;
75 
80  virtual bool Command( const std::string& aCmd ) = 0;
81 
83  virtual std::string GetXAxis( SIM_TYPE aType ) const = 0;
84 
86  virtual void SetReporter( SPICE_REPORTER* aReporter )
87  {
88  m_reporter = aReporter;
89  }
90 
99  virtual std::vector<COMPLEX> GetPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
100 
109  virtual std::vector<double> GetRealPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
110 
119  virtual std::vector<double> GetImagPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
120 
128  virtual std::vector<double> GetMagPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
129 
137  virtual std::vector<double> GetPhasePlot( const std::string& aName, int aMaxLen = -1 ) = 0;
138 
143  virtual const std::string GetNetlist() const = 0;
144 
145 protected:
148 };
149 
150 #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
virtual void Init()=0
Intializes the simulator
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< 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.