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 
35 
36 typedef std::complex<double> COMPLEX;
37 
39 {
40 public:
41  SPICE_SIMULATOR() : m_reporter( NULL ) {}
42  virtual ~SPICE_SIMULATOR() {}
43 
45  static SPICE_SIMULATOR* CreateInstance( const std::string& aName );
46 
48  virtual void Init() = 0;
49 
50  /*
51  * @brief Loads a netlist for the simulation.
52  * @return True in case of success, false otherwise.
53  */
54  virtual bool LoadNetlist( const std::string& aNetlist ) = 0;
55 
60  virtual bool Run() = 0;
61 
66  virtual bool Stop() = 0;
67 
72  virtual bool IsRunning() = 0;
73 
78  virtual bool Command( const std::string& aCmd ) = 0;
79 
81  virtual std::string GetXAxis( SIM_TYPE aType ) const = 0;
82 
84  virtual void SetReporter( SPICE_REPORTER* aReporter )
85  {
86  m_reporter = aReporter;
87  }
88 
97  virtual std::vector<COMPLEX> GetPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
98 
107  virtual std::vector<double> GetRealPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
108 
117  virtual std::vector<double> GetImagPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
118 
126  virtual std::vector<double> GetMagPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
127 
135  virtual std::vector<double> GetPhasePlot( const std::string& aName, int aMaxLen = -1 ) = 0;
136 
137 protected:
140 };
141 
142 #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
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.
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.
static SPICE_SIMULATOR * CreateInstance(const std::string &aName)
Creates a simulator instance of particular type (currently only ngspice is handled) ...
virtual ~SPICE_SIMULATOR()
virtual std::vector< double > GetMagPlot(const std::string &aName, int aMaxLen=-1)=0
Returns a requested vector with magnitude values.