Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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$
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 using namespace qucs;
33 
34 coaxline::coaxline () : circuit (2) {
35  alpha = beta = zl = fc = 0;
36  type = CIR_COAXLINE;
37 }
38 
39 void coaxline::calcPropagation (nr_double_t frequency) {
40  nr_double_t er = getPropertyDouble ("er");
41  nr_double_t mur = getPropertyDouble ("mur");
42  nr_double_t rho = getPropertyDouble ("rho");
43  nr_double_t tand = getPropertyDouble ("tand");
44  nr_double_t d = getPropertyDouble ("d");
45  nr_double_t D = getPropertyDouble ("D");
46  nr_double_t ad, ac, rs;
47 
48  // check cutoff frequency
49  if (frequency > fc) {
50  logprint (LOG_ERROR, "WARNING: Operating frequency (%g) beyond "
51  "cutoff frequency (%g).\n", frequency, fc);
52  }
53 
54  // calculate losses
55  ad = M_PI / C0 * frequency * std::sqrt (er) * tand;
56  rs = std::sqrt (M_PI * frequency * mur * MU0 * rho);
57  ac = std::sqrt (er) * (1 / d + 1 / D) / std::log (D / d) * rs / Z0;
58 
59  // calculate propagation constants and reference impedance
60  alpha = ac + ad;
61  beta = std::sqrt (er * mur) * 2 * M_PI * frequency / C0;
62  zl = Z0 / 2 / M_PI / std::sqrt (er) * std::log (D / d);
63 }
64 
65 void coaxline::calcNoiseSP (nr_double_t) {
66  nr_double_t l = getPropertyDouble ("L");
67  if (l < 0) return;
68  // calculate noise using Bosma's theorem
69  nr_double_t T = getPropertyDouble ("Temp");
70  matrix s = getMatrixS ();
71  matrix e = eye (getSize ());
72  setMatrixN (kelvin (T) / T0 * (e - s * transpose (conj (s))));
73 }
74 
75 void coaxline::initCheck (void) {
76  nr_double_t d = getPropertyDouble ("d");
77  nr_double_t D = getPropertyDouble ("D");
78  nr_double_t er = getPropertyDouble ("er");
79  nr_double_t mur = getPropertyDouble ("mur");
80 
81  // check validity
82  if (d >= D) {
84  "ERROR: Inner diameter larger than outer diameter.\n");
85  }
86  nr_double_t f1, f2, cl;
87  cl = C0 / std::sqrt (mur * er);
88  f1 = cl / (M_PI_2 * (D + d)); // TE_11
89  f2 = cl / (1 * (D - d)); // TM_N1
90  fc = MIN (f1, f2);
91 }
92 
93 void coaxline::saveCharacteristics (nr_double_t) {
94  setCharacteristic ("Zl", zl);
95 }
96 
97 void coaxline::initSP (void) {
98  // allocate S-parameter matrix
99  allocMatrixS ();
100  initCheck ();
101 }
102 
103 void coaxline::calcSP (nr_double_t frequency) {
104  nr_double_t l = getPropertyDouble ("L");
105 
106  // calculate propagation constants
107  calcPropagation (frequency);
108 
109  // calculate S-parameters
110  nr_double_t z = zl / z0;
111  nr_double_t y = 1 / z;
113  nr_complex_t n = 2.0 * cosh (g * l) + (z + y) * sinh (g * l);
114  nr_complex_t s11 = (z - y) * sinh (g * l) / n;
115  nr_complex_t s21 = 2.0 / n;
116  setS (NODE_1, NODE_1, s11); setS (NODE_2, NODE_2, s11);
117  setS (NODE_1, NODE_2, s21); setS (NODE_2, NODE_1, s21);
118 }
119 
120 void coaxline::initDC (void) {
121  nr_double_t l = getPropertyDouble ("L");
122  nr_double_t d = getPropertyDouble ("d");
123  nr_double_t rho = getPropertyDouble ("rho");
124 
125  if (d != 0.0 && rho != 0.0 && l != 0.0) {
126  // a tiny resistance
127  nr_double_t g = M_PI * sqr (d / 2) / rho / l;
128  setVoltageSources (0);
129  allocMatrixMNA ();
130  setY (NODE_1, NODE_1, +g); setY (NODE_2, NODE_2, +g);
131  setY (NODE_1, NODE_2, -g); setY (NODE_2, NODE_1, -g);
132  }
133  else {
134  // a DC short
135  setVoltageSources (1);
137  allocMatrixMNA ();
139  }
140 }
141 
142 void coaxline::initAC (void) {
143  setVoltageSources (0);
144  allocMatrixMNA ();
145  initCheck ();
146 }
147 
148 void coaxline::calcAC (nr_double_t frequency) {
149  nr_double_t l = getPropertyDouble ("L");
150 
151  // calculate propagation constants
152  calcPropagation (frequency);
153 
154  // calculate Y-parameters
156  nr_complex_t y11 = coth (g * l) / zl;
157  nr_complex_t y21 = -cosech (g * l) / zl;
158  setY (NODE_1, NODE_1, y11); setY (NODE_2, NODE_2, y11);
159  setY (NODE_1, NODE_2, y21); setY (NODE_2, NODE_1, y21);
160 }
161 
162 void coaxline::calcNoiseAC (nr_double_t) {
163  nr_double_t l = getPropertyDouble ("L");
164  if (l < 0) return;
165  // calculate noise using Bosma's theorem
166  nr_double_t T = getPropertyDouble ("Temp");
167  setMatrixN (4 * kelvin (T) / T0 * real (getMatrixY ()));
168 }
169 
170 // properties
171 PROP_REQ [] = {
172  { "D", PROP_REAL, { 2.95e-3, PROP_NO_STR }, PROP_POS_RANGEX },
173  { "d", PROP_REAL, { 0.9e-3, PROP_NO_STR }, PROP_POS_RANGEX },
174  { "L", PROP_REAL, { 1500e-3, PROP_NO_STR }, PROP_NO_RANGE },
175  { "er", PROP_REAL, { 2.29, PROP_NO_STR }, PROP_RNGII (1, 100) },
176  { "mur", PROP_REAL, { 1, PROP_NO_STR }, PROP_RNGII (1, 100) },
177  { "tand", PROP_REAL, { 4e-4, PROP_NO_STR }, PROP_POS_RANGE },
178  { "rho", PROP_REAL, { 0.022e-6, PROP_NO_STR }, PROP_POS_RANGE },
179  PROP_NO_PROP };
180 PROP_OPT [] = {
181  { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
182  PROP_NO_PROP };
183 struct define_t coaxline::cirdef =
std::complex< nr_double_t > nr_complex_t
Definition: complex.h:31
#define MU0
magnetic constant of vacuum ( )
Definition: constants.h:49
#define PROP_POS_RANGE
Definition: netdefs.h:129
l
Definition: parse_vcd.y:213
PROP_REQ[]
Definition: coaxline.cpp:171
#define NODE_2
Definition: circuit.h:35
matrix real(matrix a)
Real part matrix.
Definition: matrix.cpp:568
#define T0
standard temperature
Definition: constants.h:61
#define PROP_RNGII(f, t)
Definition: netdefs.h:138
#define kelvin(x)
Definition: constants.h:108
#define PROP_DEF
Definition: netdefs.h:189
void calcNoiseSP(nr_double_t)
Definition: coaxline.cpp:65
nr_complex_t coth(const nr_complex_t z)
Compute complex hyperbolic cotangent.
Definition: complex.cpp:320
nr_double_t getPropertyDouble(const char *)
Definition: object.cpp:176
#define PROP_REAL
Definition: netdefs.h:174
void calcPropagation(nr_double_t)
Definition: coaxline.cpp:39
void initDC(void)
Definition: coaxline.cpp:120
void setInternalVoltageSource(bool i)
Definition: circuit.h:184
#define PROP_NO_PROP
Definition: netdefs.h:122
void calcNoiseAC(nr_double_t)
Definition: coaxline.cpp:162
void setVoltageSources(int)
Definition: circuit.cpp:607
#define K
Absolute 0 in centigrade.
Definition: constants.h:59
#define PROP_NO_RANGE
Definition: netdefs.h:126
#define PROP_NO_STR
Definition: netdefs.h:125
void allocMatrixS(void)
Definition: circuit.cpp:251
n
Definition: parse_citi.y:147
#define PROP_LINEAR
Definition: netdefs.h:120
PROP_NO_SUBSTRATE
Definition: coaxline.cpp:184
static const nr_double_t z0
Definition: circuit.h:320
void initSP(void)
placehoder for S-Parameter initialisation function
Definition: coaxline.cpp:97
matrix getMatrixY(void)
Definition: circuit.cpp:696
int getSize(void)
Get the number of ports the circuit element has.
Definition: circuit.h:143
nr_complex_t cosh(const nr_complex_t z)
Compute complex hyperbolic cosine.
Definition: complex.cpp:135
#define VSRC_1
Definition: circuit.h:40
nr_complex_t sqr(const nr_complex_t z)
Square of complex number.
Definition: complex.cpp:673
#define M_PI_2
Half of Archimedes' constant ( )
Definition: consts.h:51
nr_complex_t sqrt(const nr_complex_t z)
Compute principal value of square root.
Definition: complex.cpp:271
nr_complex_t cosech(const nr_complex_t z)
Compute complex argument hyperbolic cosec.
Definition: complex.cpp:364
#define PROP_COMPONENT
Definition: netdefs.h:116
nr_double_t zl
Definition: coaxline.h:44
void calcAC(nr_double_t)
Definition: coaxline.cpp:148
#define M_PI
Archimedes' constant ( )
Definition: consts.h:47
matrix transpose(matrix a)
Matrix transposition.
Definition: matrix.cpp:492
matrix getMatrixS(void)
Definition: circuit.cpp:654
void setY(int, int, nr_complex_t)
Definition: circuit.cpp:452
#define PROP_MIN_VAL(k)
Definition: netdefs.h:133
nr_double_t fc
Definition: coaxline.h:44
#define MIN(x, y)
Minimum of x and y.
Definition: constants.h:132
void calcSP(nr_double_t)
Definition: coaxline.cpp:103
void allocMatrixMNA(void)
Definition: circuit.cpp:267
void saveCharacteristics(nr_double_t)
Definition: coaxline.cpp:93
nr_complex_t sinh(const nr_complex_t z)
Compute complex hyperbolic sine.
Definition: complex.cpp:144
#define PROP_POS_RANGEX
Definition: netdefs.h:131
y
Definition: parse_mdl.y:499
#define NODE_1
Definition: circuit.h:34
#define C0
speed of light in vacuum ( )
Definition: constants.h:47
void voltageSource(int, int, int, nr_double_t value=0.0)
Definition: circuit.cpp:748
void setMatrixN(matrix)
Definition: circuit.cpp:664
matrix eye(int rs, int cs)
Create identity matrix with specified number of rows and columns.
Definition: matrix.cpp:603
PROP_OPT[]
Definition: coaxline.cpp:180
#define LOG_ERROR
Definition: logging.h:28
#define D(con)
void initAC(void)
Definition: coaxline.cpp:142
void setS(int, int, nr_complex_t)
Definition: circuit.cpp:587
matrix conj(matrix a)
Conjugate complex matrix.
Definition: matrix.cpp:505
void setCharacteristic(const char *, nr_double_t)
Definition: circuit.cpp:566
void initCheck(void)
Definition: coaxline.cpp:75
void logprint(int level, const char *format,...)
Definition: logging.c:37
nr_complex_t log(const nr_complex_t z)
Compute principal value of natural logarithm of z.
Definition: complex.cpp:215
#define Z0
Wave impedance in vacuum ( )
Definition: constants.h:53
nr_double_t alpha
Definition: coaxline.h:44
nr_double_t beta
Definition: coaxline.h:44