KiCad PCB EDA Suite
Loading...
Searching...
No Matches
transline_calculation_base.h
Go to the documentation of this file.
1/*
2 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this package; see the file COPYING. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20#ifndef TRANSLINE_CALCULATIONS_TRANSLINE_CALCULATION_BASE_H
21#define TRANSLINE_CALCULATIONS_TRANSLINE_CALCULATION_BASE_H
22
23
24#include <cmath>
25#include <unordered_map>
26
27
29enum class TRANSLINE_PARAMETERS : int
30{
31 // The following parameters are accessible from the UI
32 UNKNOWN_ID = -1,
33 EPSILONR, // Dielectric constant
34 TAND, // Dielectric Loss Tangent
35 RHO, // Conductivity of conductor
36 H, // Height of substrate
37 H_T, // Height of top surface
38 T, // Height of top conductor
39 PHYS_WIDTH, // Width of trace
40 PHYS_DIAM_IN, // Inner diameter of cable
41 PHYS_S, // width of gap between line and ground
42 PHYS_DIAM_OUT, // Outer diameter of cable
43 PHYS_LEN, // Length of cable
44 ROUGH, // Surface roughness
45 MUR, // Magnetic permeability of substrate
46 MURC, // magnetic permeability of conductor
47 FREQUENCY, // Frequency of operation
48 STRIPLINE_A, // Stripline : distance from track to top plane
49 TWISTEDPAIR_TWIST, // Twists per length
50 TWISTEDPAIR_EPSILONR_ENV, // Dielectric constant of environment
51 Z0, // Characteristic impedance
52 Z0_E, // Even-mode characteristic impedance
53 Z0_O, // Odd-mode characteristic impedance
54 ANG_L, // Electrical length in angle
56
57 // The following parameters are generated by calculations
58 SIGMA, // Conductivity of the metal
59 SKIN_DEPTH, // Skin depth
60 LOSS_DIELECTRIC, // Loss in dielectric (dB)
61 LOSS_CONDUCTOR, // Loss in conductors (dB)
62 CUTOFF_FREQUENCY, // Cutoff frequency for higher order modes
63 EPSILON_EFF, // Effective dielectric constant
64 EPSILON_EFF_EVEN, // Even mode effective dielectric constant
65 EPSILON_EFF_ODD, // Odd mode effective dielectric constant
66 UNIT_PROP_DELAY, // The unit propagation delay (ps/cm)
67 UNIT_PROP_DELAY_ODD, // The odd mode unit propagation delay (ps/cm)
68 UNIT_PROP_DELAY_EVEN, // The even mode unit propagation delay (ps/cm)
69 ATTEN_COND, // The attenuation of the conductor
70 ATTEN_COND_EVEN, // The even mode attenuation of the conductor
71 ATTEN_COND_ODD, // The odd mode attenuation of the conductor
72 ATTEN_DILECTRIC, // The attenuation of the dilectric
73 ATTEN_DILECTRIC_EVEN, // The even mode attenuation of the dilectric
74 ATTEN_DILECTRIC_ODD, // The odd mode attenuation of the dilectric
75 Z_DIFF, // The differential impedance
77};
78
79
82{
83 DEFAULT, // Use the default synthesis options for the calculation
84 FIX_WIDTH, // Fixes the width of a differential pair
85 FIX_SPACING // Fixes the spacing of a differential pair
86};
87
88
91{
92 OK,
93 WARNING,
94 TS_ERROR // ERROR name is colliding with a define on Windows
95};
96
97
103{
104public:
110 TRANSLINE_CALCULATION_BASE( std::initializer_list<TRANSLINE_PARAMETERS> aParameters )
111 {
112 InitProperties( aParameters );
113 }
114
116
118 void SetParameter( const TRANSLINE_PARAMETERS aParam, const double aValue ) { m_parameters.at( aParam ) = aValue; }
119
121 double GetParameter( const TRANSLINE_PARAMETERS aParam ) const { return m_parameters.at( aParam ); }
122
124 double& GetParameterRef( const TRANSLINE_PARAMETERS aParam ) { return m_parameters[aParam]; }
125
127 std::unordered_map<TRANSLINE_PARAMETERS, std::pair<double, TRANSLINE_STATUS>>& GetAnalysisResults();
128
130 std::unordered_map<TRANSLINE_PARAMETERS, std::pair<double, TRANSLINE_STATUS>>& GetSynthesisResults();
131
133 virtual void Analyse() = 0;
134
137 virtual bool Synthesize( SYNTHESIZE_OPTS aOpts ) = 0;
138
139protected:
141 void InitProperties( const std::initializer_list<TRANSLINE_PARAMETERS>& aParams );
142
144 virtual void SetAnalysisResults() = 0;
145
147 virtual void SetSynthesisResults() = 0;
148
150 void SetAnalysisResult( TRANSLINE_PARAMETERS aParam, const double aValue,
151 const TRANSLINE_STATUS aStatus = TRANSLINE_STATUS::OK );
152
154 void SetSynthesisResult( TRANSLINE_PARAMETERS aParam, const double aValue,
155 const TRANSLINE_STATUS aStatus = TRANSLINE_STATUS::OK );
156
171
187
193 double SkinDepth() const;
194
200 static double UnitPropagationDelay( double aEpsilonEff );
201
208 static std::pair<double, double> EllipticIntegral( double arg );
209
211 static double coth( const double x ) { return ( std::exp( 2.0 * x ) + 1.0 ) / ( std::exp( 2.0 * x ) - 1.0 ); }
212
214 static double sech( const double x ) { return 2.0 / ( std::exp( x ) + std::exp( -x ) ); }
215
217 std::unordered_map<TRANSLINE_PARAMETERS, double> m_parameters;
218
220 std::unordered_map<TRANSLINE_PARAMETERS, std::pair<double, TRANSLINE_STATUS>> m_analysisStatus;
221
223 std::unordered_map<TRANSLINE_PARAMETERS, std::pair<double, TRANSLINE_STATUS>> m_synthesisStatus;
224
226 static constexpr double m_maxError{ 0.000001 };
227};
228
229#endif //TRANSLINE_CALCULATIONS_TRANSLINE_CALCULATION_BASE_H
The base class for all transmission line calculations.
static double coth(const double x)
Calculates cosh of the given argument.
virtual bool Synthesize(SYNTHESIZE_OPTS aOpts)=0
Synthesis the transmission line using the current parameter set target.
std::unordered_map< TRANSLINE_PARAMETERS, std::pair< double, TRANSLINE_STATUS > > & GetSynthesisResults()
Gets the output parameters following synthesis.
virtual void SetAnalysisResults()=0
Sets values in the output analysis results structure.
virtual void SetSynthesisResults()=0
Sets values in the output synthesis results structure.
double GetParameter(const TRANSLINE_PARAMETERS aParam) const
Gets the given calculation property.
static double sech(const double x)
Calculates sech of the given argument.
void InitProperties(const std::initializer_list< TRANSLINE_PARAMETERS > &aParams)
Initialises the properties used (as inputs or outputs) by the calculation.
static std::pair< double, double > EllipticIntegral(double arg)
Computes the complete elliptic integral of first kind K() and the second kind E() using the arithmeti...
void SetParameter(const TRANSLINE_PARAMETERS aParam, const double aValue)
Sets the given calculation property.
void SetSynthesisResult(TRANSLINE_PARAMETERS aParam, const double aValue, const TRANSLINE_STATUS aStatus=TRANSLINE_STATUS::OK)
Sets a synthesis result.
static constexpr double m_maxError
The maximum error for Z0 optimisations.
bool MinimiseZ0Error1D(TRANSLINE_PARAMETERS aOptimise, TRANSLINE_PARAMETERS aMeasure)
minimizeZ0Error1D
double SkinDepth() const
Calculate skin depth.
virtual void Analyse()=0
Analyses the transmission line using the current parameter set.
double & GetParameterRef(const TRANSLINE_PARAMETERS aParam)
Adds a constant to the given parameter.
std::unordered_map< TRANSLINE_PARAMETERS, double > m_parameters
All input and output properties used by the calculation.
void SetAnalysisResult(TRANSLINE_PARAMETERS aParam, const double aValue, const TRANSLINE_STATUS aStatus=TRANSLINE_STATUS::OK)
Sets an analysis result.
std::unordered_map< TRANSLINE_PARAMETERS, std::pair< double, TRANSLINE_STATUS > > m_synthesisStatus
Synthesis results.
TRANSLINE_CALCULATION_BASE(std::initializer_list< TRANSLINE_PARAMETERS > aParameters)
Constructs the transmission line calculation object.
static double UnitPropagationDelay(double aEpsilonEff)
Calculates the unit propagation delay (ps/cm) for the given effective permittivity.
std::unordered_map< TRANSLINE_PARAMETERS, std::pair< double, TRANSLINE_STATUS > > & GetAnalysisResults()
Gets the output parameters following analysis.
bool MinimiseZ0Error2D(TRANSLINE_PARAMETERS aParam1, TRANSLINE_PARAMETERS aParam2)
minimizeZ0Error2D
std::unordered_map< TRANSLINE_PARAMETERS, std::pair< double, TRANSLINE_STATUS > > m_analysisStatus
Analysis results.
SYNTHESIZE_OPTS
Options for specifying synthesis inputs, targets, or strategies.
TRANSLINE_STATUS
Parameter status values.
TRANSLINE_PARAMETERS
All possible parameters used (as inputs or outputs) by the transmission line calculations.