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, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifndef SPICE_SIMULATOR_H
24#define SPICE_SIMULATOR_H
25
26#include "sim_types.h"
27#include "spice_settings.h"
28#include "simulator.h"
29
30#include <atomic>
31#include <mutex>
32#include <string>
33#include <vector>
34#include <complex>
35#include <memory>
36
37#include <wx/string.h>
38
40
41typedef std::complex<double> COMPLEX;
42
43
45{
46public:
48 SIMULATOR(),
49 m_reporter( nullptr ),
50 m_settings( nullptr )
51 {}
52
53 virtual ~SPICE_SIMULATOR() {}
54
55 /*
56 * Initialize the simulator using the optional \a aSettings.
57 *
58 * @param aSettings [in] are the simulator specific settings. Can be null if no settings need
59 * to be initialized.
60 */
61 virtual void Init( const SPICE_SETTINGS* aSettings = nullptr ) = 0;
62
68 virtual bool LoadNetlist( const std::string& aNetlist ) = 0;
69
75 virtual bool Command( const std::string& aCmd ) = 0;
76
78 virtual wxString GetXAxis( SIM_TYPE aType ) const = 0;
79
89 virtual void SetReporter( SIMULATOR_REPORTER* aReporter )
90 {
91 std::lock_guard<std::mutex> lock( m_reporterMutex );
92 m_reporter.store( aReporter, std::memory_order_release );
93 }
94
98 virtual wxString CurrentPlotName() const = 0;
99
103 virtual std::vector<std::string> AllVectors() const = 0;
104
114 virtual std::vector<COMPLEX> GetComplexVector( const std::string& aName, int aMaxLen = -1 ) = 0;
115
125 virtual std::vector<double> GetRealVector( const std::string& aName, int aMaxLen = -1 ) = 0;
126
136 virtual std::vector<double> GetImaginaryVector( const std::string& aName, int aMaxLen = -1 ) = 0;
137
146 virtual std::vector<double> GetGainVector( const std::string& aName, int aMaxLen = -1 ) = 0;
147
156 virtual std::vector<double> GetPhaseVector( const std::string& aName, int aMaxLen = -1 ) = 0;
157
163 virtual const std::string GetNetlist() const = 0;
164
168 virtual std::vector<std::string> GetSettingCommands() const = 0;
169
175 std::shared_ptr<SPICE_SETTINGS>& Settings() { return m_settings; }
176
177 const std::shared_ptr<SPICE_SETTINGS>& Settings() const { return m_settings; }
178
187 static wxString TypeToName( SIM_TYPE aType, bool aShortName );
188
189protected:
191 std::atomic<SIMULATOR_REPORTER*> m_reporter;
192
196 std::mutex m_reporterMutex;
197
199 std::shared_ptr<SPICE_SETTINGS> m_settings;
200};
201
202#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.
std::mutex m_reporterMutex
We don't own this. We are just borrowing it from the SCHEMATIC_SETTINGS.
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:28
std::complex< double > COMPLEX