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  * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 3
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * https://www.gnu.org/licenses/gpl-3.0.html
22  * or you may search the http://www.gnu.org website for the version 3 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
27 #ifndef SPICE_SIMULATOR_H
28 #define SPICE_SIMULATOR_H
29 
30 #include "sim_types.h"
31 #include "spice_settings.h"
32 
33 #include <string>
34 #include <vector>
35 #include <complex>
36 #include <memory>
37 
38 #include <wx/string.h>
39 
41 
42 typedef std::complex<double> COMPLEX;
43 
44 
46 {
47 public:
49  m_reporter( nullptr ),
50  m_settings( nullptr )
51  {}
52 
53  virtual ~SPICE_SIMULATOR() {}
54 
56  static std::shared_ptr<SPICE_SIMULATOR> CreateInstance( const std::string& aName );
57 
58  /*
59  * Initialize the simulator using the optional \a aSettings.
60  *
61  * @param aSettings [in] are the simulator specific settings. Can be null if no settings need
62  * to be initialized.
63  */
64  virtual void Init( const SPICE_SIMULATOR_SETTINGS* aSettings = nullptr ) = 0;
65 
71  virtual bool LoadNetlist( const std::string& aNetlist ) = 0;
72 
78  virtual bool Run() = 0;
79 
85  virtual bool Stop() = 0;
86 
92  virtual bool IsRunning() = 0;
93 
99  virtual bool Command( const std::string& aCmd ) = 0;
100 
102  virtual std::string GetXAxis( SIM_TYPE aType ) const = 0;
103 
105  virtual void SetReporter( SPICE_REPORTER* aReporter )
106  {
107  m_reporter = aReporter;
108  }
109 
115  virtual std::vector<std::string> AllPlots() const = 0;
116 
126  virtual std::vector<COMPLEX> GetPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
127 
137  virtual std::vector<double> GetRealPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
138 
148  virtual std::vector<double> GetImagPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
149 
158  virtual std::vector<double> GetMagPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
159 
168  virtual std::vector<double> GetPhasePlot( const std::string& aName, int aMaxLen = -1 ) = 0;
169 
175  virtual const std::string GetNetlist() const = 0;
176 
180  virtual std::vector<std::string> GetSettingCommands() const = 0;
181 
187  std::shared_ptr<SPICE_SIMULATOR_SETTINGS>& Settings() { return m_settings; }
188 
189  const std::shared_ptr<SPICE_SIMULATOR_SETTINGS>& Settings() const { return m_settings; }
190 
199  static wxString TypeToName( SIM_TYPE aType, bool aShortName );
200 
201 protected:
204 
206  std::shared_ptr<SPICE_SIMULATOR_SETTINGS> m_settings;
207 };
208 
209 #endif /* SPICE_SIMULATOR_H */
virtual std::string GetXAxis(SIM_TYPE aType) const =0
Set a SPICE_REPORTER object to receive the simulation log.
virtual bool IsRunning()=0
Check if simulation is running at the moment.
virtual std::vector< double > GetPhasePlot(const std::string &aName, int aMaxLen=-1)=0
Return a requested vector with phase values.
virtual void SetReporter(SPICE_REPORTER *aReporter)
virtual std::vector< COMPLEX > GetPlot(const std::string &aName, int aMaxLen=-1)=0
Return a requested vector with complex values.
virtual std::vector< double > GetRealPlot(const std::string &aName, int aMaxLen=-1)=0
Return a requested vector with real values.
virtual std::vector< std::string > AllPlots() const =0
Return a list with all vectors generated in current simulation.
std::complex< double > COMPLEX
virtual const std::string GetNetlist() const =0
Return current SPICE netlist used by the simulator.
SPICE_REPORTER * m_reporter
< Reporter object to receive simulation log.
std::shared_ptr< SPICE_SIMULATOR_SETTINGS > & Settings()
Return the simulator configuration settings.
static wxString TypeToName(SIM_TYPE aType, bool aShortName)
Return a string with simulation name based on enum.
const std::shared_ptr< SPICE_SIMULATOR_SETTINGS > & Settings() const
SIM_TYPE
< Possible simulation types
Definition: sim_types.h:31
std::shared_ptr< SPICE_SIMULATOR_SETTINGS > m_settings
Interface to receive simulation updates from SPICE_SIMULATOR class.
virtual bool Command(const std::string &aCmd)=0
Execute a Spice command as if it was typed into console.
static std::shared_ptr< SPICE_SIMULATOR > CreateInstance(const std::string &aName)
virtual bool LoadNetlist(const std::string &aNetlist)=0
Load a netlist for the simulation.
virtual bool Run()=0
Execute the simulation with currently loaded netlist.
virtual std::vector< std::string > GetSettingCommands() const =0
virtual void Init(const SPICE_SIMULATOR_SETTINGS *aSettings=nullptr)=0
virtual std::vector< double > GetImagPlot(const std::string &aName, int aMaxLen=-1)=0
Return a requested vector with imaginary values.
virtual bool Stop()=0
Halt the simulation.
virtual ~SPICE_SIMULATOR()
Create a simulator instance of particular type (currently only ngspice is handled)
virtual std::vector< double > GetMagPlot(const std::string &aName, int aMaxLen=-1)=0
Return a requested vector with magnitude values.
Storage for simulator specific settings.