Sim: Use O-devices to simulate all tlines (much faster than T-devices)

This commit is contained in:
Mikolaj Wielgus 2022-08-31 15:01:05 +02:00
parent c98ad7218a
commit 748324f4cd
4 changed files with 69 additions and 29 deletions

View File

@ -267,7 +267,8 @@ SIM_MODEL::SPICE_INFO SIM_MODEL::SpiceInfo( TYPE aType )
//case TYPE::L_ADV: return { "L", "l" };
case TYPE::L_BEHAVIORAL: return { "L", "", "", "0", false, true };
case TYPE::TLINE_Z0: return { "T" };
//case TYPE::TLINE_Z0: return { "T" };
case TYPE::TLINE_Z0: return { "O", "ltra" };
case TYPE::TLINE_RLGC: return { "O", "ltra" };
case TYPE::SW_V: return { "S", "sw" };
@ -958,26 +959,6 @@ wxString SIM_MODEL::GenerateSpiceItemName( const wxString& aRefName ) const
}
wxString SIM_MODEL::GenerateSpiceItemParamValuePair( const PARAM& aParam, bool& aIsFirst ) const
{
wxString result;
if( aIsFirst )
aIsFirst = false;
else
result << " ";
wxString name = ( aParam.info.spiceInstanceName == "" ) ?
aParam.info.name : aParam.info.spiceInstanceName;
wxString value = aParam.value->ToSpiceString();
if( value != "" )
result << name << "=" << value;
return result;
}
wxString SIM_MODEL::GenerateSpiceItemLine( const wxString& aRefName,
const wxString& aModelName ) const
{
@ -1284,6 +1265,26 @@ void SIM_MODEL::WriteInferredDataFields( std::vector<T>& aFields, const wxString
}
wxString SIM_MODEL::GenerateSpiceItemParamValuePair( const PARAM& aParam, bool& aIsFirst ) const
{
wxString result;
if( aIsFirst )
aIsFirst = false;
else
result << " ";
wxString name = ( aParam.info.spiceInstanceName == "" ) ?
aParam.info.name : aParam.info.spiceInstanceName;
wxString value = aParam.value->ToSpiceString();
if( value != "" )
result << name << "=" << value;
return result;
}
wxString SIM_MODEL::GenerateParamValuePair( const PARAM& aParam, bool& aIsFirst ) const
{
wxString result;

View File

@ -498,7 +498,6 @@ public:
virtual wxString GenerateSpiceModelLine( const wxString& aModelName ) const;
virtual wxString GenerateSpiceItemName( const wxString& aRefName ) const;
virtual wxString GenerateSpiceItemParamValuePair( const PARAM& aParam, bool& aIsFirst ) const;
wxString GenerateSpiceItemLine( const wxString& aRefName, const wxString& aModelName ) const;
wxString GenerateSpiceItemLine( const wxString& aRefName, const wxString& aModelName,
@ -574,6 +573,8 @@ protected:
template <typename T>
void WriteInferredDataFields( std::vector<T>& aFields, const wxString& aValue ) const;
virtual wxString GenerateSpiceItemParamValuePair( const PARAM& aParam, bool& aIsFirst ) const;
virtual wxString GenerateParamValuePair( const PARAM& aParam, bool& aIsFirst ) const;
wxString GenerateParamsField( const wxString& aPairSeparator ) const;

View File

@ -23,6 +23,7 @@
*/
#include <sim/sim_model_tline.h>
#include <locale_io.h>
using PARAM = SIM_MODEL::PARAM;
@ -48,6 +49,7 @@ SIM_MODEL_TLINE::SIM_MODEL_TLINE( TYPE aType )
default:
wxFAIL_MSG( "Unhandled SIM_MODEL type in SIM_MODEL_TLINE" );
break;
}
}
@ -70,6 +72,43 @@ void SIM_MODEL_TLINE::WriteDataLibFields( std::vector<LIB_FIELD>& aFields ) cons
}
wxString SIM_MODEL_TLINE::GenerateSpiceModelLine( const wxString& aModelName ) const
{
wxString r, l, g, c, len;
switch( GetType() )
{
case TYPE::TLINE_Z0:
{
auto z0 = static_cast<const SIM_VALUE_FLOAT&>( *FindParam( "z0" )->value );
auto td = static_cast<const SIM_VALUE_FLOAT&>( *FindParam( "td" )->value );
r = SIM_VALUE_FLOAT( 0 ).ToSpiceString();
l = ( td * z0 ).ToSpiceString();
g = SIM_VALUE_FLOAT( 0 ).ToSpiceString();
c = ( td / z0 ).ToSpiceString();
len = SIM_VALUE_FLOAT( 1 ).ToSpiceString();
break;
}
case TYPE::TLINE_RLGC:
r = FindParam( "r" )->value->ToSpiceString();
l = FindParam( "l" )->value->ToSpiceString();
g = FindParam( "g" )->value->ToSpiceString();
c = FindParam( "c" )->value->ToSpiceString();
len = FindParam( "len" )->value->ToSpiceString();
break;
default:
wxFAIL_MSG( "Unhandled SIM_MODEL type in SIM_MODEL_TLINE" );
return "";
}
return wxString::Format( ".model %s %s( r=%s l=%s g=%s c=%s len=%s )\n",
aModelName, "ltra", r, l, g, c, len );
}
template <typename T>
void SIM_MODEL_TLINE::inferredWriteDataFields( std::vector<T>& aFields ) const
{
@ -93,8 +132,8 @@ std::vector<PARAM::INFO> SIM_MODEL_TLINE::makeZ0ParamInfos()
paramInfo.category = PARAM::CATEGORY::PRINCIPAL;
paramInfo.defaultValue = "";
paramInfo.description = "Characteristic impedance";
paramInfo.isSpiceInstanceParam = true;
paramInfo.isInstanceParam = false;
paramInfo.isSpiceInstanceParam = false;
paramInfo.isInstanceParam = true;
paramInfos.push_back( paramInfo );
paramInfo.name = "td";
@ -103,8 +142,8 @@ std::vector<PARAM::INFO> SIM_MODEL_TLINE::makeZ0ParamInfos()
paramInfo.category = PARAM::CATEGORY::PRINCIPAL;
paramInfo.defaultValue = "";
paramInfo.description = "Transmission delay";
paramInfo.isSpiceInstanceParam = true;
paramInfo.isInstanceParam = false;
paramInfo.isSpiceInstanceParam = false;
paramInfo.isInstanceParam = true;
paramInfos.push_back( paramInfo );
return paramInfos;

View File

@ -36,6 +36,8 @@ public:
void WriteDataSchFields( std::vector<SCH_FIELD>& aFields ) const override;
void WriteDataLibFields( std::vector<LIB_FIELD>& aFields ) const override;
wxString GenerateSpiceModelLine( const wxString& aModelName ) const override;
private:
template <typename T>
void inferredReadDataFields( unsigned aSymbolPinCount, const std::vector<T>* aFields );
@ -45,9 +47,6 @@ private:
std::vector<wxString> getPinNames() const override { return { "1+", "1-", "2+", "2-" }; }
// Subcircuits require models even when they have no Spice instance parameters.
bool requiresSpiceModel() const override { return GetType() == TYPE::TLINE_RLGC; }
static std::vector<PARAM::INFO> makeZ0ParamInfos();
static std::vector<PARAM::INFO> makeRlgcParamInfos();