My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
coaxline.cpp
Go to the documentation of this file.
1 /*
2  * coaxline.cpp - coaxial cable class implementation
3  *
4  * Copyright (C) 2006, 2008, 2009, 2011 Stefan Jahn <stefan@lkcc.org>
5  *
6  * This is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * This software 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 package; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  * $Id: coaxline.cpp 1825 2011-03-11 20:42:14Z ela $
22  *
23  */
24 
25 #if HAVE_CONFIG_H
26 # include <config.h>
27 #endif
28 
29 #include "component.h"
30 #include "coaxline.h"
31 
32 coaxline::coaxline () : circuit (2) {
33  alpha = beta = zl = fc = 0;
35 }
36 
37 void coaxline::calcPropagation (nr_double_t frequency) {
38  nr_double_t er = getPropertyDouble ("er");
39  nr_double_t mur = getPropertyDouble ("mur");
40  nr_double_t rho = getPropertyDouble ("rho");
41  nr_double_t tand = getPropertyDouble ("tand");
42  nr_double_t d = getPropertyDouble ("d");
43  nr_double_t D = getPropertyDouble ("D");
44  nr_double_t ad, ac, rs;
45 
46  // check cutoff frequency
47  if (frequency > fc) {
48  logprint (LOG_ERROR, "WARNING: Operating frequency (%g) beyond "
49  "cutoff frequency (%g).\n", frequency, fc);
50  }
51 
52  // calculate losses
53  ad = M_PI / C0 * frequency * sqrt (er) * tand;
54  rs = sqrt (M_PI * frequency * mur * MU0 * rho);
55  ac = sqrt (er) * (1 / d + 1 / D) / log (D / d) * rs / Z0;
56 
57  // calculate propagation constants and reference impedance
58  alpha = ac + ad;
59  beta = sqrt (er * mur) * 2 * M_PI * frequency / C0;
60  zl = Z0 / 2 / M_PI / sqrt (er) * log (D / d);
61 }
62 
63 void coaxline::calcNoiseSP (nr_double_t) {
64  nr_double_t l = getPropertyDouble ("L");
65  if (l < 0) return;
66  // calculate noise using Bosma's theorem
67  nr_double_t T = getPropertyDouble ("Temp");
68  matrix s = getMatrixS ();
69  matrix e = eye (getSize ());
70  setMatrixN (kelvin (T) / T0 * (e - s * transpose (conj (s))));
71 }
72 
73 void coaxline::initCheck (void) {
74  nr_double_t d = getPropertyDouble ("d");
75  nr_double_t D = getPropertyDouble ("D");
76  nr_double_t er = getPropertyDouble ("er");
77  nr_double_t mur = getPropertyDouble ("mur");
78 
79  // check validity
80  if (d >= D) {
82  "ERROR: Inner diameter larger than outer diameter.\n");
83  }
84  nr_double_t f1, f2, cl;
85  cl = C0 / sqrt (mur * er);
86  f1 = cl / (M_PI_2 * (D + d)); // TE_11
87  f2 = cl / (1 * (D - d)); // TM_N1
88  fc = MIN (f1, f2);
89 }
90 
91 void coaxline::saveCharacteristics (nr_double_t) {
92  setCharacteristic ("Zl", zl);
93 }
94 
95 void coaxline::initSP (void) {
96  // allocate S-parameter matrix
97  allocMatrixS ();
98  initCheck ();
99 }
100 
101 void coaxline::calcSP (nr_double_t frequency) {
102  nr_double_t l = getPropertyDouble ("L");
103 
104  // calculate propagation constants
105  calcPropagation (frequency);
106 
107  // calculate S-parameters
108  nr_double_t z = zl / z0;
109  nr_double_t y = 1 / z;
110  nr_complex_t g = rect (alpha, beta);
111  nr_complex_t n = 2.0 * cosh (g * l) + (z + y) * sinh (g * l);
112  nr_complex_t s11 = (z - y) * sinh (g * l) / n;
113  nr_complex_t s21 = 2.0 / n;
114  setS (NODE_1, NODE_1, s11); setS (NODE_2, NODE_2, s11);
115  setS (NODE_1, NODE_2, s21); setS (NODE_2, NODE_1, s21);
116 }
117 
118 void coaxline::initDC (void) {
119  nr_double_t l = getPropertyDouble ("L");
120  nr_double_t d = getPropertyDouble ("d");
121  nr_double_t rho = getPropertyDouble ("rho");
122 
123  if (d != 0.0 && rho != 0.0 && l != 0.0) {
124  // a tiny resistance
125  nr_double_t g = M_PI * sqr (d / 2) / rho / l;
126  setVoltageSources (0);
127  allocMatrixMNA ();
128  setY (NODE_1, NODE_1, +g); setY (NODE_2, NODE_2, +g);
129  setY (NODE_1, NODE_2, -g); setY (NODE_2, NODE_1, -g);
130  }
131  else {
132  // a DC short
133  setVoltageSources (1);
135  allocMatrixMNA ();
137  }
138 }
139 
140 void coaxline::initAC (void) {
141  setVoltageSources (0);
142  allocMatrixMNA ();
143  initCheck ();
144 }
145 
146 void coaxline::calcAC (nr_double_t frequency) {
147  nr_double_t l = getPropertyDouble ("L");
148 
149  // calculate propagation constants
150  calcPropagation (frequency);
151 
152  // calculate Y-parameters
153  nr_complex_t g = rect (alpha, beta);
154  nr_complex_t y11 = coth (g * l) / zl;
155  nr_complex_t y21 = -cosech (g * l) / zl;
156  setY (NODE_1, NODE_1, y11); setY (NODE_2, NODE_2, y11);
157  setY (NODE_1, NODE_2, y21); setY (NODE_2, NODE_1, y21);
158 }
159 
160 void coaxline::calcNoiseAC (nr_double_t) {
161  nr_double_t l = getPropertyDouble ("L");
162  if (l < 0) return;
163  // calculate noise using Bosma's theorem
164  nr_double_t T = getPropertyDouble ("Temp");
165  setMatrixN (4 * kelvin (T) / T0 * real (getMatrixY ()));
166 }
167 
168 // properties
169 PROP_REQ [] = {
170  { "D", PROP_REAL, { 2.95e-3, PROP_NO_STR }, PROP_POS_RANGEX },
171  { "d", PROP_REAL, { 0.9e-3, PROP_NO_STR }, PROP_POS_RANGEX },
172  { "L", PROP_REAL, { 1500e-3, PROP_NO_STR }, PROP_NO_RANGE },
173  { "er", PROP_REAL, { 2.29, PROP_NO_STR }, PROP_RNGII (1, 100) },
174  { "mur", PROP_REAL, { 1, PROP_NO_STR }, PROP_RNGII (1, 100) },
175  { "tand", PROP_REAL, { 4e-4, PROP_NO_STR }, PROP_POS_RANGE },
176  { "rho", PROP_REAL, { 0.022e-6, PROP_NO_STR }, PROP_POS_RANGE },
177  PROP_NO_PROP };
178 PROP_OPT [] = {
179  { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
180  PROP_NO_PROP };
181 struct define_t coaxline::cirdef =