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
93 virtual void SetReporter( SIMULATOR_REPORTER* aReporter )
94 {
95 std::lock_guard<std::mutex> lock( m_reporterMutex );
96 m_reporter.store( aReporter, std::memory_order_release );
97 }
98
102 virtual wxString CurrentPlotName() const = 0;
103
107 virtual std::vector<std::string> AllVectors() const = 0;
108
118 virtual std::vector<COMPLEX> GetComplexVector( const std::string& aName, int aMaxLen = -1 ) = 0;
119
129 virtual std::vector<double> GetRealVector( const std::string& aName, int aMaxLen = -1 ) = 0;
130
140 virtual std::vector<double> GetImaginaryVector( const std::string& aName, int aMaxLen = -1 ) = 0;
141
150 virtual std::vector<double> GetGainVector( const std::string& aName, int aMaxLen = -1 ) = 0;
151
160 virtual std::vector<double> GetPhaseVector( const std::string& aName, int aMaxLen = -1 ) = 0;
161
167 virtual const std::string GetNetlist() const = 0;
168
172 virtual std::vector<std::string> GetSettingCommands() const = 0;
173
179 std::shared_ptr<SPICE_SETTINGS>& Settings() { return m_settings; }
180
181 const std::shared_ptr<SPICE_SETTINGS>& Settings() const { return m_settings; }
182
191 static wxString TypeToName( SIM_TYPE aType, bool aShortName );
192
193protected:
195 std::atomic<SIMULATOR_REPORTER*> m_reporter;
196
200 std::mutex m_reporterMutex;
201
203 std::shared_ptr<SPICE_SETTINGS> m_settings;
204};
205
206#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:32
std::complex< double > COMPLEX