2022-05-31 02:55:48 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2022 Mikolaj Wielgus
|
|
|
|
* Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 3
|
|
|
|
* 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:
|
|
|
|
* https://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 3 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sim/sim_model_tline.h>
|
2022-09-22 05:38:45 +00:00
|
|
|
|
|
|
|
#include <fmt/core.h>
|
2022-05-31 02:55:48 +00:00
|
|
|
|
|
|
|
using PARAM = SIM_MODEL::PARAM;
|
|
|
|
|
|
|
|
|
2022-10-10 23:23:00 +00:00
|
|
|
std::string SPICE_GENERATOR_TLINE::ModelLine( const SPICE_ITEM& aItem ) const
|
2022-09-14 07:19:25 +00:00
|
|
|
{
|
2023-02-22 09:10:06 +00:00
|
|
|
std::string r="0", l="0", g="0", c="0", len="1";
|
2022-09-14 07:19:25 +00:00
|
|
|
|
|
|
|
switch( m_model.GetType() )
|
|
|
|
{
|
2022-09-15 03:25:57 +00:00
|
|
|
case SIM_MODEL::TYPE::TLINE_Z0:
|
2022-09-14 07:19:25 +00:00
|
|
|
{
|
2023-02-22 09:10:06 +00:00
|
|
|
double z0 = SIM_VALUE::ToDouble( m_model.FindParam( "z0" )->value );
|
|
|
|
double td = SIM_VALUE::ToDouble( m_model.FindParam( "td" )->value );
|
2022-09-14 07:19:25 +00:00
|
|
|
|
2023-07-13 12:55:58 +00:00
|
|
|
if( std::isnan( z0 ) || std::isnan( td ) )
|
2022-10-10 23:23:00 +00:00
|
|
|
return fmt::format( ".model {} LTRA()\n", aItem.modelName );
|
2022-09-14 07:19:25 +00:00
|
|
|
|
2023-02-22 09:10:06 +00:00
|
|
|
l = fmt::format( "{:g}", td * z0 );
|
|
|
|
c = fmt::format( "{:g}", td / z0 );
|
2022-09-14 07:19:25 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-09-15 03:25:57 +00:00
|
|
|
case SIM_MODEL::TYPE::TLINE_RLGC:
|
2023-02-18 11:54:55 +00:00
|
|
|
{
|
|
|
|
if( m_model.FindParam( "r" ) )
|
2023-02-22 09:10:06 +00:00
|
|
|
r = SIM_VALUE::ToSpice( m_model.FindParam( "r" )->value );
|
2023-02-18 11:54:55 +00:00
|
|
|
if( m_model.FindParam( "l" ) )
|
2023-02-22 09:10:06 +00:00
|
|
|
l = SIM_VALUE::ToSpice( m_model.FindParam( "l" )->value );
|
2023-02-18 11:54:55 +00:00
|
|
|
if( m_model.FindParam( "g" ) )
|
2023-02-22 09:10:06 +00:00
|
|
|
g = SIM_VALUE::ToSpice( m_model.FindParam( "g" )->value );
|
2023-02-18 11:54:55 +00:00
|
|
|
if( m_model.FindParam( "c" ) )
|
2023-02-22 09:10:06 +00:00
|
|
|
c = SIM_VALUE::ToSpice( m_model.FindParam( "c" )->value );
|
2023-02-18 11:54:55 +00:00
|
|
|
if( m_model.FindParam( "len" ) )
|
2023-02-22 09:10:06 +00:00
|
|
|
len = SIM_VALUE::ToSpice( m_model.FindParam( "len" )->value );
|
2022-09-14 07:19:25 +00:00
|
|
|
break;
|
2023-02-18 11:54:55 +00:00
|
|
|
}
|
2022-09-14 07:19:25 +00:00
|
|
|
default:
|
|
|
|
wxFAIL_MSG( "Unhandled SIM_MODEL type in SIM_MODEL_TLINE" );
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2022-09-22 05:38:45 +00:00
|
|
|
return fmt::format( ".model {} LTRA( r={} l={} g={} c={} len={} )\n",
|
2022-10-10 23:23:00 +00:00
|
|
|
aItem.modelName, r, l, g, c, len );
|
2022-09-14 07:19:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SIM_MODEL_TLINE::SIM_MODEL_TLINE( TYPE aType ) :
|
2022-10-25 05:49:09 +00:00
|
|
|
SIM_MODEL( aType, std::make_unique<SPICE_GENERATOR_TLINE>( *this ) )
|
2022-05-31 02:55:48 +00:00
|
|
|
{
|
2022-08-28 12:51:03 +00:00
|
|
|
static std::vector<PARAM::INFO> z0 = makeZ0ParamInfos();
|
|
|
|
static std::vector<PARAM::INFO> rlgc = makeRlgcParamInfos();
|
2022-05-31 02:55:48 +00:00
|
|
|
|
|
|
|
switch( aType )
|
|
|
|
{
|
|
|
|
case TYPE::TLINE_Z0:
|
|
|
|
for( const PARAM::INFO& paramInfo : z0 )
|
|
|
|
AddParam( paramInfo );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TYPE::TLINE_RLGC:
|
|
|
|
for( const PARAM::INFO& paramInfo : rlgc )
|
|
|
|
AddParam( paramInfo );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxFAIL_MSG( "Unhandled SIM_MODEL type in SIM_MODEL_TLINE" );
|
2022-08-31 13:01:05 +00:00
|
|
|
break;
|
2022-05-31 02:55:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-28 12:51:03 +00:00
|
|
|
std::vector<PARAM::INFO> SIM_MODEL_TLINE::makeZ0ParamInfos()
|
2022-05-31 02:55:48 +00:00
|
|
|
{
|
|
|
|
std::vector<PARAM::INFO> paramInfos;
|
|
|
|
PARAM::INFO paramInfo = {};
|
|
|
|
|
|
|
|
paramInfo.name = "z0";
|
2022-06-21 02:22:52 +00:00
|
|
|
paramInfo.type = SIM_VALUE::TYPE_FLOAT;
|
2022-05-31 02:55:48 +00:00
|
|
|
paramInfo.unit = "Ω";
|
|
|
|
paramInfo.category = PARAM::CATEGORY::PRINCIPAL;
|
|
|
|
paramInfo.defaultValue = "";
|
|
|
|
paramInfo.description = "Characteristic impedance";
|
2022-08-31 13:01:05 +00:00
|
|
|
paramInfo.isSpiceInstanceParam = false;
|
|
|
|
paramInfo.isInstanceParam = true;
|
2022-05-31 02:55:48 +00:00
|
|
|
paramInfos.push_back( paramInfo );
|
|
|
|
|
|
|
|
paramInfo.name = "td";
|
2022-06-21 02:22:52 +00:00
|
|
|
paramInfo.type = SIM_VALUE::TYPE_FLOAT;
|
2022-05-31 02:55:48 +00:00
|
|
|
paramInfo.unit = "s";
|
|
|
|
paramInfo.category = PARAM::CATEGORY::PRINCIPAL;
|
|
|
|
paramInfo.defaultValue = "";
|
|
|
|
paramInfo.description = "Transmission delay";
|
2022-08-31 13:01:05 +00:00
|
|
|
paramInfo.isSpiceInstanceParam = false;
|
|
|
|
paramInfo.isInstanceParam = true;
|
2022-05-31 02:55:48 +00:00
|
|
|
paramInfos.push_back( paramInfo );
|
|
|
|
|
|
|
|
return paramInfos;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-28 12:51:03 +00:00
|
|
|
std::vector<PARAM::INFO> SIM_MODEL_TLINE::makeRlgcParamInfos()
|
2022-05-31 02:55:48 +00:00
|
|
|
{
|
|
|
|
std::vector<PARAM::INFO> paramInfos;
|
|
|
|
PARAM::INFO paramInfo = {};
|
|
|
|
|
|
|
|
paramInfo.name = "len";
|
2022-06-21 02:22:52 +00:00
|
|
|
paramInfo.type = SIM_VALUE::TYPE_FLOAT;
|
2022-05-31 02:55:48 +00:00
|
|
|
paramInfo.unit = "m";
|
|
|
|
paramInfo.category = PARAM::CATEGORY::PRINCIPAL;
|
|
|
|
paramInfo.defaultValue = "";
|
|
|
|
paramInfo.description = "Length";
|
|
|
|
paramInfo.isSpiceInstanceParam = false;
|
2022-06-21 02:22:52 +00:00
|
|
|
paramInfo.isInstanceParam = true;
|
2022-05-31 02:55:48 +00:00
|
|
|
paramInfos.push_back( paramInfo );
|
|
|
|
|
|
|
|
paramInfo.name = "r";
|
2022-06-21 02:22:52 +00:00
|
|
|
paramInfo.type = SIM_VALUE::TYPE_FLOAT;
|
2022-05-31 02:55:48 +00:00
|
|
|
paramInfo.unit = "Ω/m";
|
|
|
|
paramInfo.category = PARAM::CATEGORY::PRINCIPAL;
|
|
|
|
paramInfo.defaultValue = "0";
|
|
|
|
paramInfo.description = "Resistance per length";
|
|
|
|
paramInfo.isSpiceInstanceParam = false;
|
2022-06-21 02:22:52 +00:00
|
|
|
paramInfo.isInstanceParam = false;
|
2022-05-31 02:55:48 +00:00
|
|
|
paramInfos.push_back( paramInfo );
|
|
|
|
|
|
|
|
paramInfo.name = "l";
|
2022-06-21 02:22:52 +00:00
|
|
|
paramInfo.type = SIM_VALUE::TYPE_FLOAT;
|
2022-05-31 02:55:48 +00:00
|
|
|
paramInfo.unit = "H/m";
|
|
|
|
paramInfo.category = PARAM::CATEGORY::PRINCIPAL;
|
|
|
|
paramInfo.defaultValue = "0";
|
|
|
|
paramInfo.description = "Inductance per length";
|
|
|
|
paramInfo.isSpiceInstanceParam = false;
|
2022-06-21 02:22:52 +00:00
|
|
|
paramInfo.isInstanceParam = false;
|
2022-05-31 02:55:48 +00:00
|
|
|
paramInfos.push_back( paramInfo );
|
|
|
|
|
|
|
|
paramInfo.name = "g";
|
2022-06-21 02:22:52 +00:00
|
|
|
paramInfo.type = SIM_VALUE::TYPE_FLOAT;
|
2022-05-31 02:55:48 +00:00
|
|
|
paramInfo.unit = "1/(Ω m)";
|
|
|
|
paramInfo.category = PARAM::CATEGORY::PRINCIPAL;
|
|
|
|
paramInfo.defaultValue = "0";
|
|
|
|
paramInfo.description = "Conductance per length";
|
|
|
|
paramInfo.isSpiceInstanceParam = false;
|
2022-06-21 02:22:52 +00:00
|
|
|
paramInfo.isInstanceParam = false;
|
2022-05-31 02:55:48 +00:00
|
|
|
paramInfos.push_back( paramInfo );
|
|
|
|
|
|
|
|
paramInfo.name = "c";
|
2022-06-21 02:22:52 +00:00
|
|
|
paramInfo.type = SIM_VALUE::TYPE_FLOAT;
|
2023-03-01 22:20:58 +00:00
|
|
|
paramInfo.unit = "F/m";
|
2022-05-31 02:55:48 +00:00
|
|
|
paramInfo.category = PARAM::CATEGORY::PRINCIPAL;
|
|
|
|
paramInfo.defaultValue = "0";
|
|
|
|
paramInfo.description = "Capacitance per length";
|
|
|
|
paramInfo.isSpiceInstanceParam = false;
|
2022-06-21 02:22:52 +00:00
|
|
|
paramInfo.isInstanceParam = false;
|
2022-05-31 02:55:48 +00:00
|
|
|
paramInfos.push_back( paramInfo );
|
|
|
|
|
|
|
|
return paramInfos;
|
|
|
|
}
|