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 <optional>
26#include <unordered_map>
27
29
30
32enum class TRANSLINE_PARAMETERS : int
33{
34 // The following parameters are accessible from the UI
36 EPSILONR, // Dielectric constant
37 TAND, // Dielectric Loss Tangent
38 RHO, // Conductivity of conductor
39 H, // Height of substrate
40 H_T, // Height of top surface
41 T, // Height of top conductor
42 PHYS_WIDTH, // Width of trace
43 PHYS_DIAM_IN, // Inner diameter of cable
44 PHYS_S, // width of gap between line and ground
45 PHYS_DIAM_OUT, // Outer diameter of cable
46 PHYS_LEN, // Length of cable
47 ROUGH, // Surface roughness
48 MUR, // Magnetic permeability of substrate
49 MURC, // magnetic permeability of conductor
50 FREQUENCY, // Frequency of operation
51 STRIPLINE_A, // Stripline : distance from track to top plane
52 TWISTEDPAIR_TWIST, // Twists per length
53 TWISTEDPAIR_EPSILONR_ENV, // Dielectric constant of environment
54 Z0, // Characteristic impedance
55 Z0_E, // Even-mode characteristic impedance
56 Z0_O, // Odd-mode characteristic impedance
57 ANG_L, // Electrical length in angle
59
60 // The following parameters are generated by calculations
61 SIGMA, // Conductivity of the metal
62 SKIN_DEPTH, // Skin depth
63 LOSS_DIELECTRIC, // Loss in dielectric (dB)
64 LOSS_CONDUCTOR, // Loss in conductors (dB)
65 CUTOFF_FREQUENCY, // Cutoff frequency for higher order modes
66 EPSILON_EFF, // Effective dielectric constant
67 EPSILON_EFF_EVEN, // Even mode effective dielectric constant
68 EPSILON_EFF_ODD, // Odd mode effective dielectric constant
69 UNIT_PROP_DELAY, // The unit propagation delay (ps/cm)
70 UNIT_PROP_DELAY_ODD, // The odd mode unit propagation delay (ps/cm)
71 UNIT_PROP_DELAY_EVEN, // The even mode unit propagation delay (ps/cm)
72 ATTEN_COND, // The attenuation of the conductor
73 ATTEN_COND_EVEN, // The even mode attenuation of the conductor
74 ATTEN_COND_ODD, // The odd mode attenuation of the conductor
75 ATTEN_DILECTRIC, // The attenuation of the dilectric
76 ATTEN_DILECTRIC_EVEN, // The even mode attenuation of the dilectric
77 ATTEN_DILECTRIC_ODD, // The odd mode attenuation of the dilectric
78 Z_DIFF, // The differential impedance
79
80 // Common-mode characteristic impedance for a symmetric coupled line, Z_comm = Z0e / 2.
81 // The two strips driven at equal potential present Z0e to ground in parallel. Derived
82 // from Pozar, "Microwave Engineering" 4th ed., Sec. 7.6 Eqs. 7.68-7.69.
84
85 // Coupling coefficient k_c = (Z0e - Z0o) / (Z0e + Z0o). Dimensionless, bounded in
86 // [0, 1) for physically realisable passive geometries. Pozar, "Microwave Engineering"
87 // 4th ed., Sec. 7.6 Eq. 7.81 (voltage coupling coefficient C).
89
90 // Coplanar waveguide back-metal flag. A value of 0.0 means ungrounded CPW; a value of 1.0
91 // means grounded (CBCPW). Exposed as a parameter rather than a C++ member so a single
92 // COPLANAR class can drive both UI entry points without ad-hoc subclassing.
94
95 DIELECTRIC_MODEL_SEL, // 0 = CONSTANT, 1 = DJORDJEVIC_SARKAR (double for parameter-map compatibility)
96 EPSILONR_SPEC_FREQ, // Frequency at which EPSILONR and TAND are specified (Hz).
97 // Used only when DIELECTRIC_MODEL_SEL == DJORDJEVIC_SARKAR.
98
99 SOLDERMASK_PRESENT, // 1.0 = mask enabled, 0.0 = disabled. A zero here must leave the
100 // un-coated Analyse() path bit-identical so every pre-mask regression
101 // test continues to pass without tolerance widening.
102 SOLDERMASK_THICKNESS, // Mask layer thickness C, metres. Zero also produces a bit-identical
103 // un-coated result because tanh(0) = 0 kills the correction Q.
104 SOLDERMASK_EPSILONR, // Mask relative permittivity. Typical LPI 3.3 - 3.8.
105 SOLDERMASK_TAND, // Mask loss tangent. Typical LPI 0.025 - 0.035.
106 SOLDERMASK_FILLS_GAPS, // CPW / CBCPW only. 1.0 = mask fills the coplanar slots (default),
107 // 0.0 = mask over traces only, slots left air-filled.
108
110};
111
112
115{
116 DEFAULT, // Use the default synthesis options for the calculation
117 FIX_WIDTH, // Fixes the width of a differential pair
118 FIX_SPACING, // Fixes the spacing of a differential pair
119 FROM_ZDIFF_ZCOMM // Read Z_DIFF / Z_COMM as the design target instead of Z0_E / Z0_O.
120 // Translates to (Z0_E, Z0_O) and runs the DEFAULT 2-D solver. Only
121 // honoured by calculators that can jointly optimise both modes.
122};
123
124
126enum class DIELECTRIC_MODEL : int
127{
128 CONSTANT, // Classic behaviour, epsR and tan delta are frequency-independent.
129 DJORDJEVIC_SARKAR, // Causal wideband Debye. See Djordjevic et al. 2001 IEEE TEMC 43(4).
130};
131
132
135{
138 TS_ERROR // ERROR name is colliding with a define on Windows
139};
140
141
147{
148public:
154 TRANSLINE_CALCULATION_BASE( std::initializer_list<TRANSLINE_PARAMETERS> aParameters )
155 {
156 InitProperties( aParameters );
157 }
158
160
162 void SetParameter( const TRANSLINE_PARAMETERS aParam, const double aValue ) { m_parameters.at( aParam ) = aValue; }
163
165 double GetParameter( const TRANSLINE_PARAMETERS aParam ) const { return m_parameters.at( aParam ); }
166
168 double& GetParameterRef( const TRANSLINE_PARAMETERS aParam ) { return m_parameters[aParam]; }
169
171 std::unordered_map<TRANSLINE_PARAMETERS, std::pair<double, TRANSLINE_STATUS>>& GetAnalysisResults();
172
174 std::unordered_map<TRANSLINE_PARAMETERS, std::pair<double, TRANSLINE_STATUS>>& GetSynthesisResults();
175
177 virtual void Analyse() = 0;
178
181 virtual bool Synthesize( SYNTHESIZE_OPTS aOpts ) = 0;
182
189 virtual void SetSynthesizeTarget( TRANSLINE_PARAMETERS aTarget ) { m_synthesizeTarget = aTarget; }
190
193
200
202 double GetDispersedEpsilonR( double aF ) const;
203
205 double GetDispersedTanDelta( double aF ) const;
206
216 virtual double GetSoldermaskDeltaQ( double /*aWOverH*/, double /*aCOverH*/ ) const
217 {
218 return 0.0;
219 }
220
238 std::pair<double, double> ApplySoldermaskCorrection( double aEpsEffUncoated,
239 double aTanDeltaSubstrate,
240 double aEpsRSubstrate,
241 double aWOverH,
242 double aF ) const;
243
252 static double WanHoorfarQ2( double aU, double aHBarTop );
253
254protected:
256 void InitProperties( const std::initializer_list<TRANSLINE_PARAMETERS>& aParams );
257
259 virtual void SetAnalysisResults() = 0;
260
262 virtual void SetSynthesisResults() = 0;
263
265 void SetAnalysisResult( TRANSLINE_PARAMETERS aParam, const double aValue,
266 const TRANSLINE_STATUS aStatus = TRANSLINE_STATUS::OK );
267
269 void SetSynthesisResult( TRANSLINE_PARAMETERS aParam, const double aValue,
270 const TRANSLINE_STATUS aStatus = TRANSLINE_STATUS::OK );
271
287 bool aRecalculateLength = false );
288
304
310 double SkinDepth() const;
311
317 static double UnitPropagationDelay( double aEpsilonEff );
318
325 static std::pair<double, double> EllipticIntegral( double arg );
326
328 static double coth( const double x ) { return ( std::exp( 2.0 * x ) + 1.0 ) / ( std::exp( 2.0 * x ) - 1.0 ); }
329
331 static double sech( const double x ) { return 2.0 / ( std::exp( x ) + std::exp( -x ) ); }
332
334 std::unordered_map<TRANSLINE_PARAMETERS, double> m_parameters;
335
337 std::unordered_map<TRANSLINE_PARAMETERS, std::pair<double, TRANSLINE_STATUS>> m_analysisStatus;
338
340 std::unordered_map<TRANSLINE_PARAMETERS, std::pair<double, TRANSLINE_STATUS>> m_synthesisStatus;
341
343 static constexpr double m_maxError{ 0.000001 };
344
347
349 std::optional<DIELECTRIC_DJORDJEVIC_SARKAR> m_dsModel;
350};
351
352#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:40
@ DUMMY_PRM
Definition transline.h:63
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.