2016-08-11 12:41:30 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-12-05 20:01:36 +00:00
|
|
|
* Copyright (C) 2016-2022 CERN
|
2023-01-19 12:59:18 +00:00
|
|
|
* Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-10-06 18:07:43 +00:00
|
|
|
*
|
2016-08-11 12:41:30 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
2016-08-11 12:41:43 +00:00
|
|
|
* as published by the Free Software Foundation; either version 3
|
2016-08-11 12:41:30 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
2016-08-11 12:41:43 +00:00
|
|
|
* https://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 3 license,
|
2016-08-11 12:41:30 +00:00
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2022-12-07 00:23:18 +00:00
|
|
|
#ifndef NGSPICE_CIRCUIT_MODEL_H
|
|
|
|
#define NGSPICE_CIRCUIT_MODEL_H
|
2016-08-11 12:41:30 +00:00
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
#include <netlist_exporters/netlist_exporter_spice.h>
|
2016-08-11 12:41:52 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2016-08-11 12:41:34 +00:00
|
|
|
#include "sim_types.h"
|
2022-03-05 23:49:25 +00:00
|
|
|
#include "spice_simulator.h"
|
2019-05-27 22:13:00 +00:00
|
|
|
#include "spice_value.h"
|
|
|
|
|
|
|
|
|
|
|
|
struct SPICE_DC_PARAMS
|
|
|
|
{
|
|
|
|
wxString m_source;
|
|
|
|
SPICE_VALUE m_vstart;
|
|
|
|
SPICE_VALUE m_vend;
|
|
|
|
SPICE_VALUE m_vincrement;
|
|
|
|
};
|
2016-08-11 12:41:30 +00:00
|
|
|
|
2023-07-13 15:04:06 +00:00
|
|
|
|
|
|
|
struct SPICE_PZ_ANALYSES
|
|
|
|
{
|
|
|
|
bool m_Poles;
|
|
|
|
bool m_Zeros;
|
|
|
|
};
|
|
|
|
|
2018-07-08 12:12:38 +00:00
|
|
|
/// Special netlist exporter flavor that allows one to override simulation commands
|
2022-04-12 14:37:06 +00:00
|
|
|
class NGSPICE_CIRCUIT_MODEL : public NETLIST_EXPORTER_SPICE, public SIMULATION_MODEL
|
2016-08-11 12:41:30 +00:00
|
|
|
{
|
|
|
|
public:
|
2023-01-19 12:59:18 +00:00
|
|
|
NGSPICE_CIRCUIT_MODEL( SCHEMATIC_IFACE* aSchematic, wxWindow* aDialogParent = nullptr ) :
|
2023-07-05 17:25:52 +00:00
|
|
|
NETLIST_EXPORTER_SPICE( aSchematic, aDialogParent )
|
2023-01-14 00:17:33 +00:00
|
|
|
{}
|
|
|
|
|
2022-03-05 23:49:25 +00:00
|
|
|
virtual ~NGSPICE_CIRCUIT_MODEL() {}
|
2016-08-11 12:41:30 +00:00
|
|
|
|
2020-04-15 01:51:58 +00:00
|
|
|
/**
|
2023-01-29 16:01:03 +00:00
|
|
|
* Return name of Spice dataset for a specific trace.
|
2021-01-26 15:23:37 +00:00
|
|
|
*
|
2020-04-15 01:51:58 +00:00
|
|
|
* @param aVector is name of the vector produced by ngspice
|
|
|
|
* @param [out] aSignal is output in form: V(R1), Ib(Q2), I(L8)
|
2023-01-29 16:01:03 +00:00
|
|
|
* @return [SPT_VOLTAGE, SPT_CURRENT]. Otherwise SPT_UNKNOWN if vector is of different,
|
|
|
|
* unsupported type.
|
2020-04-15 01:51:58 +00:00
|
|
|
*/
|
2023-01-29 16:01:03 +00:00
|
|
|
SIM_TRACE_TYPE VectorToSignal( const std::string& aVector, wxString& aSignal ) const;
|
2020-04-15 01:51:58 +00:00
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
bool GetNetlist( const wxString& aSimCommand, unsigned aSimOptions,
|
|
|
|
OUTPUTFORMATTER* aFormatter, REPORTER& aReporter )
|
2016-08-11 12:41:30 +00:00
|
|
|
{
|
2023-07-05 17:25:52 +00:00
|
|
|
return NGSPICE_CIRCUIT_MODEL::DoWriteNetlist( aSimCommand, aSimOptions, *aFormatter,
|
|
|
|
aReporter );
|
2016-08-11 12:41:30 +00:00
|
|
|
}
|
|
|
|
|
2016-08-11 12:42:17 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Return simulation command directives placed in schematic sheets (if any).
|
2016-08-11 12:42:17 +00:00
|
|
|
*/
|
2023-02-11 23:25:32 +00:00
|
|
|
wxString GetSchTextSimCommand();
|
2016-08-11 12:41:30 +00:00
|
|
|
|
2019-05-27 22:13:00 +00:00
|
|
|
/**
|
2021-06-14 18:00:08 +00:00
|
|
|
* Parse a two-source .dc command directive into its symbols.
|
2019-05-27 22:13:00 +00:00
|
|
|
*
|
|
|
|
* @param aCmd is the input command string
|
|
|
|
* @return true if the command was parsed successfully
|
|
|
|
*/
|
|
|
|
bool ParseDCCommand( const wxString& aCmd, SPICE_DC_PARAMS* aSource1,
|
|
|
|
SPICE_DC_PARAMS* aSource2 );
|
|
|
|
|
2023-07-13 15:04:06 +00:00
|
|
|
bool ParsePZCommand( const wxString& aCmd, wxString* transferFunction, wxString* input,
|
|
|
|
wxString* inputRef, wxString* output, wxString* outputRef,
|
|
|
|
SPICE_PZ_ANALYSES* analyses );
|
|
|
|
|
2023-07-03 14:45:58 +00:00
|
|
|
bool ParseNoiseCommand( const wxString& aCmd, wxString* aOutput, wxString* aRef,
|
|
|
|
wxString* aSource, wxString* aScale, SPICE_VALUE* aPts,
|
2023-07-04 10:04:20 +00:00
|
|
|
SPICE_VALUE* aFStart, SPICE_VALUE* aFStop, bool* aSaveAll );
|
2023-07-03 14:45:58 +00:00
|
|
|
|
2016-08-11 12:42:17 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Determine if a directive is a simulation command.
|
2016-08-11 12:42:17 +00:00
|
|
|
*/
|
2016-08-11 12:41:34 +00:00
|
|
|
static bool IsSimCommand( const wxString& aCmd )
|
|
|
|
{
|
|
|
|
return CommandToSimType( aCmd ) != ST_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:42:17 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Return simulation type basing on a simulation command directive.
|
2016-08-11 12:42:17 +00:00
|
|
|
*/
|
2016-08-11 12:41:34 +00:00
|
|
|
static SIM_TYPE CommandToSimType( const wxString& aCmd );
|
|
|
|
|
2022-05-31 02:55:48 +00:00
|
|
|
protected:
|
2023-07-05 17:25:52 +00:00
|
|
|
void WriteDirectives( const wxString& aSimCommand, unsigned aSimOptions,
|
|
|
|
OUTPUTFORMATTER& aFormatter ) const override;
|
2016-08-11 12:41:30 +00:00
|
|
|
};
|
|
|
|
|
2022-12-07 00:23:18 +00:00
|
|
|
#endif /* NGSPICE_CIRCUIT_MODEL_H */
|