KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Tomasz Wlostowski <[email protected]>
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#include "simulator.h"
33
34#include <atomic>
35#include <mutex>
36#include <string>
37#include <vector>
38#include <complex>
39#include <memory>
40
41#include <wx/string.h>
42
44
45typedef std::complex<double> COMPLEX;
46
47
49{
50public:
52 SIMULATOR(),
53 m_reporter( nullptr ),
54 m_settings( nullptr )
55 {}
56
57 virtual ~SPICE_SIMULATOR() {}
58
59 /*
60 * Initialize the simulator using the optional \a aSettings.
61 *
62 * @param aSettings [in] are the simulator specific settings. Can be null if no settings need
63 * to be initialized.
64 */
65 virtual void Init( const SPICE_SETTINGS* aSettings = nullptr ) = 0;
66
72 virtual bool LoadNetlist( const std::string& aNetlist ) = 0;
73
79 virtual bool Command( const std::string& aCmd ) = 0;
80
82 virtual wxString GetXAxis( SIM_TYPE aType ) const = 0;
83
91 virtual void SetReporter( SIMULATOR_REPORTER* aReporter )
92 {
93 m_reporter.store( aReporter, std::memory_order_release );
94 }
95
99 virtual wxString CurrentPlotName() const = 0;
100
104 virtual std::vector<std::string> AllVectors() const = 0;
105
115 virtual std::vector<COMPLEX> GetComplexVector( const std::string& aName, int aMaxLen = -1 ) = 0;
116
126 virtual std::vector<double> GetRealVector( const std::string& aName, int aMaxLen = -1 ) = 0;
127
137 virtual std::vector<double> GetImaginaryVector( const std::string& aName, int aMaxLen = -1 ) = 0;
138
147 virtual std::vector<double> GetGainVector( const std::string& aName, int aMaxLen = -1 ) = 0;
148
157 virtual std::vector<double> GetPhaseVector( const std::string& aName, int aMaxLen = -1 ) = 0;
158
164 virtual const std::string GetNetlist() const = 0;
165
169 virtual std::vector<std::string> GetSettingCommands() const = 0;
170
176 std::shared_ptr<SPICE_SETTINGS>& Settings() { return m_settings; }
177
178 const std::shared_ptr<SPICE_SETTINGS>& Settings() const { return m_settings; }
179
188 static wxString TypeToName( SIM_TYPE aType, bool aShortName );
189
190protected:
192 std::atomic<SIMULATOR_REPORTER*> m_reporter;
193
195 std::shared_ptr<SPICE_SETTINGS> m_settings;
196};
197
198#endif /* SPICE_SIMULATOR_H */
Interface to receive simulation updates from SPICE_SIMULATOR class.
Storage for simulator specific settings.
virtual std::vector< double > GetImaginaryVector(const std::string &aName, int aMaxLen=-1)=0
Return a requested vector with imaginary values.
virtual void Init(const SPICE_SETTINGS *aSettings=nullptr)=0
virtual bool Command(const std::string &aCmd)=0
Execute a Spice command as if it was typed into console.
virtual bool LoadNetlist(const std::string &aNetlist)=0
Load a netlist for the simulation.
static wxString TypeToName(SIM_TYPE aType, bool aShortName)
Return a string with simulation name based on enum.
virtual wxString GetXAxis(SIM_TYPE aType) const =0
virtual std::vector< COMPLEX > GetComplexVector(const std::string &aName, int aMaxLen=-1)=0
Return a requested vector with complex values.
std::shared_ptr< SPICE_SETTINGS > & Settings()
Return the simulator configuration settings.
const std::shared_ptr< SPICE_SETTINGS > & Settings() const
virtual wxString CurrentPlotName() const =0
virtual const std::string GetNetlist() const =0
Return current SPICE netlist used by the simulator.
virtual std::vector< std::string > AllVectors() const =0
virtual std::vector< std::string > GetSettingCommands() const =0
std::atomic< SIMULATOR_REPORTER * > m_reporter
< Reporter object to receive simulation log (not owned, accessed from BG threads).
virtual std::vector< double > GetRealVector(const std::string &aName, int aMaxLen=-1)=0
Return a requested vector with real values.
virtual void SetReporter(SIMULATOR_REPORTER *aReporter)
Set a SIMULATOR_REPORTER object to receive the simulation log.
virtual std::vector< double > GetGainVector(const std::string &aName, int aMaxLen=-1)=0
Return a requested vector with magnitude values.
virtual ~SPICE_SIMULATOR()
std::shared_ptr< SPICE_SETTINGS > m_settings
virtual std::vector< double > GetPhaseVector(const std::string &aName, int aMaxLen=-1)=0
Return a requested vector with phase values.
SIM_TYPE
< Possible simulation types
Definition sim_types.h:32
std::complex< double > COMPLEX