SPICE_SIMULATOR interface allows to obtain different types of plots (mag, phase, real, imag)

This commit is contained in:
Maciej Suminski 2016-08-11 14:41:31 +02:00
parent 183fb24112
commit 0da13052dd
3 changed files with 135 additions and 17 deletions

View File

@ -62,18 +62,132 @@ void NGSPICE::Init()
}
const vector<double> NGSPICE::GetPlot( const string& aName, int aMaxLen )
vector<COMPLEX> NGSPICE::GetPlot( const string& aName, int aMaxLen )
{
vector<double> data;
vector<COMPLEX> data;
vector_info* vi = m_ngGet_Vec_Info( (char*) aName.c_str() );
if( vi && vi->v_realdata )
if( vi )
{
data.reserve( vi->v_length );
int length = aMaxLen < 0 ? vi->v_length : std::min( aMaxLen, vi->v_length );
data.reserve( length );
for( int i = 0; i < vi->v_length; i++ )
data.push_back( vi->v_realdata[i] );
if( vi->v_realdata )
{
for( int i = 0; i < length; i++ )
data.push_back( COMPLEX( vi->v_realdata[i], 0.0 ) );
}
else if( vi->v_compdata )
{
for( int i = 0; i < length; i++ )
data.push_back( COMPLEX( vi->v_compdata[i].cx_real, vi->v_compdata[i].cx_imag ) );
}
}
return data;
}
vector<double> NGSPICE::GetRealPlot( const string& aName, int aMaxLen )
{
vector<double> data;
vector_info* vi = m_ngGet_Vec_Info( (char*) aName.c_str() );
if( vi )
{
int length = aMaxLen < 0 ? vi->v_length : std::min( aMaxLen, vi->v_length );
data.reserve( length );
if( vi->v_realdata )
{
for( int i = 0; i < length; i++ )
{
data.push_back( vi->v_realdata[i] );
}
}
else if( vi->v_compdata )
{
for( int i = 0; i < length; i++ )
{
assert( vi->v_compdata[i].cx_imag == 0.0 );
data.push_back( vi->v_compdata[i].cx_real );
}
}
}
return data;
}
vector<double> NGSPICE::GetImagPlot( const string& aName, int aMaxLen )
{
vector<double> data;
vector_info* vi = m_ngGet_Vec_Info( (char*) aName.c_str() );
if( vi )
{
int length = aMaxLen < 0 ? vi->v_length : std::min( aMaxLen, vi->v_length );
data.reserve( length );
if( vi->v_compdata )
{
for( int i = 0; i < length; i++ )
{
data.push_back( vi->v_compdata[i].cx_imag );
}
}
}
return data;
}
vector<double> NGSPICE::GetMagPlot( const string& aName, int aMaxLen )
{
vector<double> data;
vector_info* vi = m_ngGet_Vec_Info( (char*) aName.c_str() );
if( vi )
{
int length = aMaxLen < 0 ? vi->v_length : std::min( aMaxLen, vi->v_length );
data.reserve( length );
if( vi->v_realdata )
{
for( int i = 0; i < length; i++ )
data.push_back( vi->v_realdata[i] );
}
else if( vi->v_compdata )
{
for( int i = 0; i < length; i++ )
data.push_back( hypot( vi->v_compdata[i].cx_real, vi->v_compdata[i].cx_imag ) );
}
}
return data;
}
vector<double> NGSPICE::GetPhasePlot( const string& aName, int aMaxLen )
{
vector<double> data;
vector_info* vi = m_ngGet_Vec_Info( (char*) aName.c_str() );
if( vi )
{
int length = aMaxLen < 0 ? vi->v_length : std::min( aMaxLen, vi->v_length );
data.reserve( length );
if( vi->v_realdata )
{
for( int i = 0; i < length; i++ )
data.push_back( 0.0 ); // well, that's life
}
else if( vi->v_compdata )
{
for( int i = 0; i < length; i++ )
data.push_back( atan2( vi->v_compdata[i].cx_imag, vi->v_compdata[i].cx_real ) );
}
}
return data;

View File

@ -42,7 +42,12 @@ public:
bool Stop() override;
bool IsRunning() override;
bool Command( const std::string& aCmd ) override;
const std::vector<double> GetPlot( const std::string& aName, int aMaxLen = -1 ) override;
std::vector<COMPLEX> GetPlot( const std::string& aName, int aMaxLen = -1 ) override;
std::vector<double> GetRealPlot( const std::string& aName, int aMaxLen = -1 ) override;
std::vector<double> GetImagPlot( const std::string& aName, int aMaxLen = -1 ) override;
std::vector<double> GetMagPlot( const std::string& aName, int aMaxLen = -1 ) override;
std::vector<double> GetPhasePlot( const std::string& aName, int aMaxLen = -1 ) override;
private:
typedef void (*ngSpice_Init)( SendChar*, SendStat*, ControlledExit*,

View File

@ -27,17 +27,11 @@
#include <string>
#include <vector>
#include <complex>
class SPICE_REPORTER;
enum SIM_TRACE_TYPE
{
SIM_AC_MAG = 0x1,
SIM_AC_PHASE = 0x2,
SIM_TR_VOLTAGE = 0x4,
SIM_TR_CURRENT = 0x8,
SIM_TR_FFT = 0x10
};
typedef std::complex<double> COMPLEX;
class SPICE_SIMULATOR
{
@ -59,7 +53,12 @@ public:
m_reporter = aReporter;
}
virtual const std::vector<double> GetPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
virtual std::vector<COMPLEX> GetPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
virtual std::vector<double> GetRealPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
virtual std::vector<double> GetImagPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
virtual std::vector<double> GetMagPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
virtual std::vector<double> GetPhasePlot( const std::string& aName, int aMaxLen = -1 ) = 0;
protected:
SPICE_REPORTER* m_reporter;