KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_coax.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.TXT for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
25
26#include <cmath>
27
31
32
33namespace TC = TRANSLINE_CALCULATIONS;
35
36
37namespace
38{
39// Loads a COAX instance with defaults common to all fixtures.
40// Callers override geometry / material / frequency as required.
41void SetDefaults( COAX& aCalc )
42{
43 aCalc.SetParameter( TCP::MUR, 1.0 );
44 aCalc.SetParameter( TCP::MURC, 1.0 );
45 aCalc.SetParameter( TCP::SIGMA, 5.8e7 );
46 aCalc.SetParameter( TCP::TAND, 0.0 );
47 aCalc.SetParameter( TCP::PHYS_LEN, 100.0 * TC::UNIT_MM );
48 aCalc.SetParameter( TCP::FREQUENCY, 1.0e9 );
49 aCalc.SetParameter( TCP::ANG_L, 0.0 );
50}
51} // namespace
52
53
54BOOST_AUTO_TEST_SUITE( CoaxCalculations )
55
56
57// Air-filled 50 Ω coax. Din = 1.63 mm, Dout = 3.75 mm, εr = 1.
58// Analytical Z0 = 60 * ln(Dout/Din) ≈ 49.96 Ω.
59BOOST_AUTO_TEST_CASE( AirFilled50OhmImpedance )
60{
61 COAX calc;
62 SetDefaults( calc );
63 calc.SetParameter( TCP::EPSILONR, 1.0 );
66 calc.SetParameter( TCP::FREQUENCY, 1.0e9 );
67
68 calc.Analyse();
69
70 const double Z0 = calc.GetAnalysisResults()[TCP::Z0].first;
71 BOOST_TEST( Z0 == 50.0, boost::test_tools::tolerance( 0.5 / 50.0 ) );
72}
73
74
75// TE11 cutoff for the air-filled 50 Ω cable above.
76// f_c,TE11 = 2*c / (pi * (Din + Dout)) ≈ 35.4 GHz.
77BOOST_AUTO_TEST_CASE( AirFilledTE11Cutoff )
78{
79 COAX calc;
80 SetDefaults( calc );
81 calc.SetParameter( TCP::EPSILONR, 1.0 );
84 calc.SetParameter( TCP::FREQUENCY, 1.0e9 );
85
86 calc.Analyse();
87
88 const double fc = calc.GetAnalysisResults()[TCP::CUTOFF_FREQUENCY].first;
89 BOOST_TEST( fc == 35.4e9, boost::test_tools::tolerance( 1.0 / 35.4 ) );
90}
91
92
93// Teflon-filled 50 Ω (RG-142 family geometry).
94// εr = 2.04, Din = 0.91 mm, Dout = 2.95 mm. Z0 = 60/√εr * ln(Dout/Din) ≈ 49.37 Ω.
95BOOST_AUTO_TEST_CASE( TeflonFilled50OhmImpedance )
96{
97 COAX calc;
98 SetDefaults( calc );
99 calc.SetParameter( TCP::EPSILONR, 2.04 );
102 calc.SetParameter( TCP::FREQUENCY, 1.0e9 );
103
104 calc.Analyse();
105
106 const double Z0 = calc.GetAnalysisResults()[TCP::Z0].first;
107 BOOST_TEST( Z0 == 50.0, boost::test_tools::tolerance( 1.0 / 50.0 ) );
108}
109
110
111// Dielectric loss is finite and positive for a lossy dielectric.
112// εr ≈ 4.3, tan δ = 0.02 at 1 GHz, 100 mm length.
113BOOST_AUTO_TEST_CASE( DielectricLossIsFiniteAndPositive )
114{
115 COAX calc;
116 SetDefaults( calc );
117 calc.SetParameter( TCP::EPSILONR, 4.3 );
118 calc.SetParameter( TCP::TAND, 0.02 );
121 calc.SetParameter( TCP::PHYS_LEN, 100.0 * TC::UNIT_MM );
122 calc.SetParameter( TCP::FREQUENCY, 1.0e9 );
123
124 calc.Analyse();
125
126 const double loss_d = calc.GetAnalysisResults()[TCP::LOSS_DIELECTRIC].first;
127
128 BOOST_TEST( std::isfinite( loss_d ) );
129 BOOST_TEST( loss_d > 0.0 );
130
131 // α_d = π · f · √εr · tan δ / c (Np/m); convert to dB/m via LOG2DB.
132 const double alpha_d = ( M_PI * 1.0e9 * std::sqrt( 4.3 ) * 0.02 ) / TC::C0;
133 const double expected_dB = alpha_d * ( 100.0 * TC::UNIT_MM ) * TC::LOG2DB;
134
135 BOOST_TEST( loss_d == expected_dB, boost::test_tools::tolerance( 0.01 ) );
136}
137
138
139// Round-trip synthesis. Given Z0 = 50 Ω, Dout = 3.75 mm, εr = 1, solve for Din,
140// then re-analyse and confirm Z0 matches within 0.1 Ω.
141BOOST_AUTO_TEST_CASE( SynthesisRoundTripSolveForDin )
142{
143 COAX calc;
144 SetDefaults( calc );
145 calc.SetParameter( TCP::EPSILONR, 1.0 );
148 calc.SetParameter( TCP::Z0, 50.0 );
149 calc.SetParameter( TCP::ANG_L, M_PI / 2.0 );
150 calc.SetParameter( TCP::FREQUENCY, 1.0e9 );
151
154
155 const double Din_synth = calc.GetParameter( TCP::PHYS_DIAM_IN );
156 BOOST_TEST( std::isfinite( Din_synth ) );
157 BOOST_TEST( Din_synth > 0.0 );
158 BOOST_TEST( Din_synth < 3.75 * TC::UNIT_MM );
159
160 // Now analyse with the synthesized Din and confirm the Z0 target is met.
161 calc.Analyse();
162 const double Z0_check = calc.GetAnalysisResults()[TCP::Z0].first;
163 BOOST_TEST( Z0_check == 50.0, boost::test_tools::tolerance( 0.1 / 50.0 ) );
164}
165
166
167// TE11 mode string correctly reports "H(1,1) " above cutoff and is empty below.
168BOOST_AUTO_TEST_CASE( TE11ModeString )
169{
170 COAX calc;
171 SetDefaults( calc );
172 calc.SetParameter( TCP::EPSILONR, 1.0 );
175
176 // Below TE11 cutoff (f ≈ 35.4 GHz) the TE string is empty.
177 calc.SetParameter( TCP::FREQUENCY, 10.0e9 );
178 calc.Analyse();
179 BOOST_TEST( calc.GetTEModes() == std::string( "" ) );
180
181 // Above TE11 cutoff the string begins with "H(1,1) ".
182 calc.SetParameter( TCP::FREQUENCY, 50.0e9 );
183 calc.Analyse();
184 const std::string teModes = calc.GetTEModes();
185 BOOST_TEST( teModes.rfind( "H(1,1) ", 0 ) == 0u );
186}
187
188
Coaxial transmission line calculation (TEM mode).
std::string GetTEModes() const
Returns a UI-friendly string enumerating propagating TE_1m modes at the current frequency.
void SetSynthesizeTarget(TRANSLINE_PARAMETERS aTarget) override
Choose which geometry parameter will be solved for during synthesis.
bool Synthesize(SYNTHESIZE_OPTS aOpts) override
Synthesize the cable geometry to match the given Z0 target.
void Analyse() override
Analyse cable geometry parameters to output Z0, electrical length, losses and cutoffs.
double GetParameter(const TRANSLINE_PARAMETERS aParam) const
Gets the given calculation property.
void SetParameter(const TRANSLINE_PARAMETERS aParam, const double aValue)
Sets the given calculation property.
std::unordered_map< TRANSLINE_PARAMETERS, std::pair< double, TRANSLINE_STATUS > > & GetAnalysisResults()
Gets the output parameters following analysis.
TRANSLINE_PARAMETERS TCP
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(AirFilled50OhmImpedance)
Definition test_coax.cpp:59
BOOST_TEST(contains==c.ExpectedContains)
BOOST_AUTO_TEST_SUITE_END()
#define M_PI
TRANSLINE_PARAMETERS
All possible parameters used (as inputs or outputs) by the transmission line calculations.