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. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#ifndef TRANSLINE_CALCULATIONS_TRANSLINE_CALCULATION_BASE_H
19#define TRANSLINE_CALCULATIONS_TRANSLINE_CALCULATION_BASE_H
20
21
22#include <cmath>
23#include <optional>
24#include <unordered_map>
25
27
28
30enum class TRANSLINE_PARAMETERS : int
31{
32 // The following parameters are accessible from the UI
34 EPSILONR, // Dielectric constant
35 TAND, // Dielectric Loss Tangent
36 RHO, // Conductivity of conductor
37 H, // Height of substrate
38 H_T, // Height of top surface
39 T, // Height of top conductor
40 PHYS_WIDTH, // Width of trace
41 PHYS_DIAM_IN, // Inner diameter of cable
42 PHYS_S, // width of gap between line and ground
43 PHYS_DIAM_OUT, // Outer diameter of cable
44 PHYS_LEN, // Length of cable
45 ROUGH, // Surface roughness
46 MUR, // Magnetic permeability of substrate
47 MURC, // magnetic permeability of conductor
48 FREQUENCY, // Frequency of operation
49 STRIPLINE_A, // Stripline : distance from track to top plane
50 TWISTEDPAIR_TWIST, // Twists per length
51 TWISTEDPAIR_EPSILONR_ENV, // Dielectric constant of environment
52 Z0, // Characteristic impedance
53 Z0_E, // Even-mode characteristic impedance
54 Z0_O, // Odd-mode characteristic impedance
55 ANG_L, // Electrical length in angle
57
58 // The following parameters are generated by calculations
59 SIGMA, // Conductivity of the metal
60 SKIN_DEPTH, // Skin depth
61 LOSS_DIELECTRIC, // Loss in dielectric (dB)
62 LOSS_CONDUCTOR, // Loss in conductors (dB)
63 CUTOFF_FREQUENCY, // Cutoff frequency for higher order modes
64 EPSILON_EFF, // Effective dielectric constant
65 EPSILON_EFF_EVEN, // Even mode effective dielectric constant
66 EPSILON_EFF_ODD, // Odd mode effective dielectric constant
67 UNIT_PROP_DELAY, // The unit propagation delay (ps/cm)
68 UNIT_PROP_DELAY_ODD, // The odd mode unit propagation delay (ps/cm)
69 UNIT_PROP_DELAY_EVEN, // The even mode unit propagation delay (ps/cm)
70 ATTEN_COND, // The attenuation of the conductor
71 ATTEN_COND_EVEN, // The even mode attenuation of the conductor
72 ATTEN_COND_ODD, // The odd mode attenuation of the conductor
73 ATTEN_DILECTRIC, // The attenuation of the dilectric
74 ATTEN_DILECTRIC_EVEN, // The even mode attenuation of the dilectric
75 ATTEN_DILECTRIC_ODD, // The odd mode attenuation of the dilectric
76 Z_DIFF, // The differential impedance
77
78 // Common-mode characteristic impedance for a symmetric coupled line, Z_comm = Z0e / 2.
79 // The two strips driven at equal potential present Z0e to ground in parallel. Derived
80 // from Pozar, "Microwave Engineering" 4th ed., Sec. 7.6 Eqs. 7.68-7.69.
82
83 // Coupling coefficient k_c = (Z0e - Z0o) / (Z0e + Z0o). Dimensionless, bounded in
84 // [0, 1) for physically realisable passive geometries. Pozar, "Microwave Engineering"
85 // 4th ed., Sec. 7.6 Eq. 7.81 (voltage coupling coefficient C).
87
88 // Coplanar waveguide back-metal flag. A value of 0.0 means ungrounded CPW; a value of 1.0
89 // means grounded (CBCPW). Exposed as a parameter rather than a C++ member so a single
90 // COPLANAR class can drive both UI entry points without ad-hoc subclassing.
92
93 DIELECTRIC_MODEL_SEL, // 0 = CONSTANT, 1 = DJORDJEVIC_SARKAR (double for parameter-map compatibility)
94 EPSILONR_SPEC_FREQ, // Frequency at which EPSILONR and TAND are specified (Hz).
95 // Used only when DIELECTRIC_MODEL_SEL == DJORDJEVIC_SARKAR.
96
97 SOLDERMASK_PRESENT, // 1.0 = mask enabled, 0.0 = disabled. A zero here must leave the
98 // un-coated Analyse() path bit-identical so every pre-mask regression
99 // test continues to pass without tolerance widening.
100 SOLDERMASK_THICKNESS, // Mask layer thickness C, metres. Zero also produces a bit-identical
101 // un-coated result because tanh(0) = 0 kills the correction Q.
102 SOLDERMASK_EPSILONR, // Mask relative permittivity. Typical LPI 3.3 - 3.8.
103 SOLDERMASK_TAND, // Mask loss tangent. Typical LPI 0.025 - 0.035.
104 SOLDERMASK_FILLS_GAPS, // CPW / CBCPW only. 1.0 = mask fills the coplanar slots (default),
105 // 0.0 = mask over traces only, slots left air-filled.
106
108};
109
110
113{
114 DEFAULT, // Use the default synthesis options for the calculation
115 FIX_WIDTH, // Fixes the width of a differential pair
116 FIX_SPACING, // Fixes the spacing of a differential pair
117 FROM_ZDIFF_ZCOMM // Read Z_DIFF / Z_COMM as the design target instead of Z0_E / Z0_O.
118 // Translates to (Z0_E, Z0_O) and runs the DEFAULT 2-D solver. Only
119 // honoured by calculators that can jointly optimise both modes.
120};
121
122
124enum class DIELECTRIC_MODEL : int
125{
126 CONSTANT, // Classic behaviour, epsR and tan delta are frequency-independent.
127 DJORDJEVIC_SARKAR, // Causal wideband Debye. See Djordjevic et al. 2001 IEEE TEMC 43(4).
128};
129
130
133{
136 TS_ERROR // ERROR name is colliding with a define on Windows
137};
138
139
145{
146public:
152 TRANSLINE_CALCULATION_BASE( std::initializer_list<TRANSLINE_PARAMETERS> aParameters )
153 {
154 InitProperties( aParameters );
155 }
156
158
160 void SetParameter( const TRANSLINE_PARAMETERS aParam, const double aValue ) { m_parameters.at( aParam ) = aValue; }
161
163 double GetParameter( const TRANSLINE_PARAMETERS aParam ) const { return m_parameters.at( aParam ); }
164
166 double& GetParameterRef( const TRANSLINE_PARAMETERS aParam ) { return m_parameters[aParam]; }
167
169 std::unordered_map<TRANSLINE_PARAMETERS, std::pair<double, TRANSLINE_STATUS>>& GetAnalysisResults();
170
172 std::unordered_map<TRANSLINE_PARAMETERS, std::pair<double, TRANSLINE_STATUS>>& GetSynthesisResults();
173
175 virtual void Analyse() = 0;
176
179 virtual bool Synthesize( SYNTHESIZE_OPTS aOpts ) = 0;
180
187 virtual void SetSynthesizeTarget( TRANSLINE_PARAMETERS aTarget ) { m_synthesizeTarget = aTarget; }
188
191
198
200 double GetDispersedEpsilonR( double aF ) const;
201
203 double GetDispersedTanDelta( double aF ) const;
204
214 virtual double GetSoldermaskDeltaQ( double /*aWOverH*/, double /*aCOverH*/ ) const
215 {
216 return 0.0;
217 }
218
236 std::pair<double, double> ApplySoldermaskCorrection( double aEpsEffUncoated,
237 double aTanDeltaSubstrate,
238 double aEpsRSubstrate,
239 double aWOverH,
240 double aF ) const;
241
250 static double WanHoorfarQ2( double aU, double aHBarTop );
251
252protected:
254 void InitProperties( const std::initializer_list<TRANSLINE_PARAMETERS>& aParams );
255
257 virtual void SetAnalysisResults() = 0;
258
260 virtual void SetSynthesisResults() = 0;
261
263 void SetAnalysisResult( TRANSLINE_PARAMETERS aParam, const double aValue,
264 const TRANSLINE_STATUS aStatus = TRANSLINE_STATUS::OK );
265
267 void SetSynthesisResult( TRANSLINE_PARAMETERS aParam, const double aValue,
268 const TRANSLINE_STATUS aStatus = TRANSLINE_STATUS::OK );
269
285 bool aRecalculateLength = false );
286
302
308 double SkinDepth() const;
309
315 static double UnitPropagationDelay( double aEpsilonEff );
316
323 static std::pair<double, double> EllipticIntegral( double arg );
324
326 static double coth( const double x ) { return ( std::exp( 2.0 * x ) + 1.0 ) / ( std::exp( 2.0 * x ) - 1.0 ); }
327
329 static double sech( const double x ) { return 2.0 / ( std::exp( x ) + std::exp( -x ) ); }
330
332 std::unordered_map<TRANSLINE_PARAMETERS, double> m_parameters;
333
335 std::unordered_map<TRANSLINE_PARAMETERS, std::pair<double, TRANSLINE_STATUS>> m_analysisStatus;
336
338 std::unordered_map<TRANSLINE_PARAMETERS, std::pair<double, TRANSLINE_STATUS>> m_synthesisStatus;
339
341 static constexpr double m_maxError{ 0.000001 };
342
345
347 std::optional<DIELECTRIC_DJORDJEVIC_SARKAR> m_dsModel;
348};
349
350#endif //TRANSLINE_CALCULATIONS_TRANSLINE_CALCULATION_BASE_H
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.
double GetDispersedEpsilonR(double aF) const
Dispersed permittivity at aF. Returns raw EPSILONR when the model is inactive.
TRANSLINE_PARAMETERS m_synthesizeTarget
Which geometry parameter is the unknown during synthesis (set by the UI)
double GetDispersedTanDelta(double aF) const
Dispersed loss tangent at aF. Returns raw TAND when the model is inactive.
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 SetSynthesizeTarget(TRANSLINE_PARAMETERS aTarget)
Hint from UI picking which geometry parameter is the unknown when Synthesize is called.
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.
std::optional< DIELECTRIC_DJORDJEVIC_SARKAR > m_dsModel
Fitted Djordjevic-Sarkar model. Empty unless DIELECTRIC_MODEL_SEL selects it.
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.
void UpdateDielectricModel()
Refit the Djordjevic-Sarkar model from the current parameter map.
static constexpr double m_maxError
The maximum error for Z0 optimisations.
std::pair< double, double > ApplySoldermaskCorrection(double aEpsEffUncoated, double aTanDeltaSubstrate, double aEpsRSubstrate, double aWOverH, double aF) const
Apply a three-layer (substrate / soldermask / air) correction to an un-coated (eps_eff,...
double SkinDepth() const
Calculate skin depth.
static double WanHoorfarQ2(double aU, double aHBarTop)
Wan-Hoorfar 2000 eq.
virtual void Analyse()=0
Analyses the transmission line using the current parameter set.
virtual double GetSoldermaskDeltaQ(double, double) const
Incremental filling factor Delta q_mask representing the fraction of the un-coated above-trace air re...
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.
bool MinimiseZ0Error1D(TRANSLINE_PARAMETERS aOptimise, TRANSLINE_PARAMETERS aMeasure, bool aRecalculateLength=false)
minimizeZ0Error1D
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.
TRANSLINE_PARAMETERS GetSynthesizeTarget() const
Returns the parameter that will be solved for during synthesis.
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.
#define OK
#define H(x, y, z)
Definition md5_hash.cpp:17
@ UNKNOWN_ID
Definition transline.h:38
@ DUMMY_PRM
Definition transline.h:61
SYNTHESIZE_OPTS
Options for specifying synthesis inputs, targets, or strategies.
DIELECTRIC_MODEL
Frequency-domain model used for the substrate dielectric properties.
TRANSLINE_STATUS
Parameter status values.
TRANSLINE_PARAMETERS
All possible parameters used (as inputs or outputs) by the transmission line calculations.