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, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <cmath>
23
27
28
29namespace TC = TRANSLINE_CALCULATIONS;
31
32
33namespace
34{
35// Loads a COAX instance with defaults common to all fixtures.
36// Callers override geometry / material / frequency as required.
37void SetDefaults( COAX& aCalc )
38{
39 aCalc.SetParameter( TCP::MUR, 1.0 );
40 aCalc.SetParameter( TCP::MURC, 1.0 );
41 aCalc.SetParameter( TCP::SIGMA, 5.8e7 );
42 aCalc.SetParameter( TCP::TAND, 0.0 );
43 aCalc.SetParameter( TCP::PHYS_LEN, 100.0 * TC::UNIT_MM );
44 aCalc.SetParameter( TCP::FREQUENCY, 1.0e9 );
45 aCalc.SetParameter( TCP::ANG_L, 0.0 );
46}
47} // namespace
48
49
50BOOST_AUTO_TEST_SUITE( CoaxCalculations )
51
52
53// Air-filled 50 Ω coax. Din = 1.63 mm, Dout = 3.75 mm, εr = 1.
54// Analytical Z0 = 60 * ln(Dout/Din) ≈ 49.96 Ω.
55BOOST_AUTO_TEST_CASE( AirFilled50OhmImpedance )
56{
57 COAX calc;
58 SetDefaults( calc );
59 calc.SetParameter( TCP::EPSILONR, 1.0 );
62 calc.SetParameter( TCP::FREQUENCY, 1.0e9 );
63
64 calc.Analyse();
65
66 const double Z0 = calc.GetAnalysisResults()[TCP::Z0].first;
67 BOOST_TEST( Z0 == 50.0, boost::test_tools::tolerance( 0.5 / 50.0 ) );
68}
69
70
71// TE11 cutoff for the air-filled 50 Ω cable above.
72// f_c,TE11 = 2*c / (pi * (Din + Dout)) ≈ 35.4 GHz.
73BOOST_AUTO_TEST_CASE( AirFilledTE11Cutoff )
74{
75 COAX calc;
76 SetDefaults( calc );
77 calc.SetParameter( TCP::EPSILONR, 1.0 );
80 calc.SetParameter( TCP::FREQUENCY, 1.0e9 );
81
82 calc.Analyse();
83
84 const double fc = calc.GetAnalysisResults()[TCP::CUTOFF_FREQUENCY].first;
85 BOOST_TEST( fc == 35.4e9, boost::test_tools::tolerance( 1.0 / 35.4 ) );
86}
87
88
89// Teflon-filled 50 Ω (RG-142 family geometry).
90// εr = 2.04, Din = 0.91 mm, Dout = 2.95 mm. Z0 = 60/√εr * ln(Dout/Din) ≈ 49.37 Ω.
91BOOST_AUTO_TEST_CASE( TeflonFilled50OhmImpedance )
92{
93 COAX calc;
94 SetDefaults( calc );
95 calc.SetParameter( TCP::EPSILONR, 2.04 );
98 calc.SetParameter( TCP::FREQUENCY, 1.0e9 );
99
100 calc.Analyse();
101
102 const double Z0 = calc.GetAnalysisResults()[TCP::Z0].first;
103 BOOST_TEST( Z0 == 50.0, boost::test_tools::tolerance( 1.0 / 50.0 ) );
104}
105
106
107// Dielectric loss is finite and positive for a lossy dielectric.
108// εr ≈ 4.3, tan δ = 0.02 at 1 GHz, 100 mm length.
109BOOST_AUTO_TEST_CASE( DielectricLossIsFiniteAndPositive )
110{
111 COAX calc;
112 SetDefaults( calc );
113 calc.SetParameter( TCP::EPSILONR, 4.3 );
114 calc.SetParameter( TCP::TAND, 0.02 );
117 calc.SetParameter( TCP::PHYS_LEN, 100.0 * TC::UNIT_MM );
118 calc.SetParameter( TCP::FREQUENCY, 1.0e9 );
119
120 calc.Analyse();
121
122 const double loss_d = calc.GetAnalysisResults()[TCP::LOSS_DIELECTRIC].first;
123
124 BOOST_TEST( std::isfinite( loss_d ) );
125 BOOST_TEST( loss_d > 0.0 );
126
127 // α_d = π · f · √εr · tan δ / c (Np/m); convert to dB/m via LOG2DB.
128 const double alpha_d = ( M_PI * 1.0e9 * std::sqrt( 4.3 ) * 0.02 ) / TC::C0;
129 const double expected_dB = alpha_d * ( 100.0 * TC::UNIT_MM ) * TC::LOG2DB;
130
131 BOOST_TEST( loss_d == expected_dB, boost::test_tools::tolerance( 0.01 ) );
132}
133
134
135// Round-trip synthesis. Given Z0 = 50 Ω, Dout = 3.75 mm, εr = 1, solve for Din,
136// then re-analyse and confirm Z0 matches within 0.1 Ω.
137BOOST_AUTO_TEST_CASE( SynthesisRoundTripSolveForDin )
138{
139 COAX calc;
140 SetDefaults( calc );
141 calc.SetParameter( TCP::EPSILONR, 1.0 );
144 calc.SetParameter( TCP::Z0, 50.0 );
145 calc.SetParameter( TCP::ANG_L, M_PI / 2.0 );
146 calc.SetParameter( TCP::FREQUENCY, 1.0e9 );
147
150
151 const double Din_synth = calc.GetParameter( TCP::PHYS_DIAM_IN );
152 BOOST_TEST( std::isfinite( Din_synth ) );
153 BOOST_TEST( Din_synth > 0.0 );
154 BOOST_TEST( Din_synth < 3.75 * TC::UNIT_MM );
155
156 // Now analyse with the synthesized Din and confirm the Z0 target is met.
157 calc.Analyse();
158 const double Z0_check = calc.GetAnalysisResults()[TCP::Z0].first;
159 BOOST_TEST( Z0_check == 50.0, boost::test_tools::tolerance( 0.1 / 50.0 ) );
160}
161
162
163// TE11 mode string correctly reports "H(1,1) " above cutoff and is empty below.
164BOOST_AUTO_TEST_CASE( TE11ModeString )
165{
166 COAX calc;
167 SetDefaults( calc );
168 calc.SetParameter( TCP::EPSILONR, 1.0 );
171
172 // Below TE11 cutoff (f ≈ 35.4 GHz) the TE string is empty.
173 calc.SetParameter( TCP::FREQUENCY, 10.0e9 );
174 calc.Analyse();
175 BOOST_TEST( calc.GetTEModes() == std::string( "" ) );
176
177 // Above TE11 cutoff the string begins with "H(1,1) ".
178 calc.SetParameter( TCP::FREQUENCY, 50.0e9 );
179 calc.Analyse();
180 const std::string teModes = calc.GetTEModes();
181 BOOST_TEST( teModes.rfind( "H(1,1) ", 0 ) == 0u );
182}
183
184
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:55
BOOST_AUTO_TEST_SUITE_END()
BOOST_TEST(netlist.find("R_G1 ARM_OUT1 DIE_B R='0.001 / ((SW_STATE)") !=std::string::npos)
#define M_PI
TRANSLINE_PARAMETERS
All possible parameters used (as inputs or outputs) by the transmission line calculations.