Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tline.cpp
Go to the documentation of this file.
1 /*
2  * tline.cpp - ideal transmission line class implementation
3  *
4  * Copyright (C) 2004, 2006, 2008 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 "tline.h"
31 
32 using namespace qucs;
33 
34 tline::tline () : circuit (2) {
35  type = CIR_TLINE;
36 }
37 
38 void tline::calcSP (nr_double_t frequency) {
39  nr_double_t l = getPropertyDouble ("L");
40  nr_double_t z = getPropertyDouble ("Z");
41  nr_double_t a = getPropertyDouble ("Alpha");
42  nr_double_t r = (z - z0) / (z + z0);
43  nr_double_t b = 2 * M_PI * frequency / C0;
44  a = std::log (a) / 2;
45  nr_complex_t p = std::exp (-l * nr_complex_t (a, b));
46  nr_complex_t s11 = r * (1.0 - p * p) / (1.0 - p * p * r * r);
47  nr_complex_t s21 = p * (1.0 - r * r) / (1.0 - p * p * r * r);
48  setS (NODE_1, NODE_1, s11); setS (NODE_2, NODE_2, s11);
49  setS (NODE_1, NODE_2, s21); setS (NODE_2, NODE_1, s21);
50 }
51 
52 void tline::calcNoiseSP (nr_double_t) {
53  nr_double_t T = getPropertyDouble ("Temp");
54  nr_double_t l = getPropertyDouble ("L");
55  nr_double_t z = getPropertyDouble ("Z");
56  nr_double_t a = getPropertyDouble ("Alpha");
57  a = std::log (a) / 2;
58  a = std::exp (a * l);
59  nr_double_t r = (z - z0) / (z + z0);
60  nr_double_t f = (a - 1) * (r * r - 1) / sqr (a - r * r) * kelvin (T) / T0;
61  nr_double_t n11 = -f * (r * r + a);
62  nr_double_t n21 = +f * 2 * r * std::sqrt (a);
63  setN (NODE_1, NODE_1, n11); setN (NODE_2, NODE_2, n11);
64  setN (NODE_1, NODE_2, n21); setN (NODE_2, NODE_1, n21);
65 }
66 
67 void tline::calcNoiseAC (nr_double_t) {
68  nr_double_t T = getPropertyDouble ("Temp");
69  nr_double_t l = getPropertyDouble ("L");
70  nr_double_t z = getPropertyDouble ("Z");
71  nr_double_t a = getPropertyDouble ("Alpha");
72  a = std::log (a) / 2;
73  if (a * l != 0.0) {
74  a = std::exp (a * l);
75  nr_double_t f = 4.0 * kelvin (T) / T0 / z / (a - 1);
76  nr_double_t n11 = +f * (a + 1);
77  nr_double_t n21 = -f * 2 * std::sqrt (a);
78  setN (NODE_1, NODE_1, n11); setN (NODE_2, NODE_2, n11);
79  setN (NODE_1, NODE_2, n21); setN (NODE_2, NODE_1, n21);
80  }
81 }
82 
83 void tline::initDC (void) {
84  nr_double_t z = getPropertyDouble ("Z");
85  nr_double_t a = getPropertyDouble ("Alpha");
86  nr_double_t l = getPropertyDouble ("L");
87  a = std::log (a) / 2;
88  if (a * l != 0.0) {
90  allocMatrixMNA ();
91  a = std::exp (a * l);
92  nr_double_t f = 1 / z / (a - 1);
93  nr_double_t y11 = +f * (a + 1);
94  nr_double_t y21 = -f * 2 * std::sqrt (a);
95  setY (NODE_1, NODE_1, y11); setY (NODE_2, NODE_2, y11);
96  setY (NODE_1, NODE_2, y21); setY (NODE_2, NODE_1, y21);
97  } else {
99  allocMatrixMNA ();
101  }
102 }
103 
104 void tline::initAC (void) {
105  nr_double_t l = getPropertyDouble ("L");
106  if (l != 0.0) {
107  setVoltageSources (0);
108  allocMatrixMNA ();
109  } else {
110  setVoltageSources (1);
111  allocMatrixMNA ();
113  }
114 }
115 
116 void tline::calcAC (nr_double_t frequency) {
117  nr_double_t l = getPropertyDouble ("L");
118  nr_double_t z = getPropertyDouble ("Z");
119  nr_double_t a = getPropertyDouble ("Alpha");
120  nr_double_t b = 2 * M_PI * frequency / C0;
121  a = std::log (a) / 2;
122  if (l != 0.0) {
123  nr_complex_t y11 = +1 / z / tanh (nr_complex_t (a, b) * l);
124  nr_complex_t y21 = -1 / z / sinh (nr_complex_t (a, b) * l);
125  setY (NODE_1, NODE_1, y11); setY (NODE_2, NODE_2, y11);
126  setY (NODE_1, NODE_2, y21); setY (NODE_2, NODE_1, y21);
127  }
128 }
129 
130 void tline::initTR (void) {
131  nr_double_t l = getPropertyDouble ("L");
132  nr_double_t z = getPropertyDouble ("Z");
133  deleteHistory ();
134  if (l > 0.0) {
135  setVoltageSources (2);
136  allocMatrixMNA ();
137  setHistory (true);
138  initHistory (l / C0);
139  setB (NODE_1, VSRC_1, +1); setB (NODE_2, VSRC_2, +1);
140  setC (VSRC_1, NODE_1, +1); setC (VSRC_2, NODE_2, +1);
141  setD (VSRC_1, VSRC_1, -z); setD (VSRC_2, VSRC_2, -z);
142  } else {
143  setVoltageSources (1);
144  allocMatrixMNA ();
146  }
147 }
148 
149 void tline::calcTR (nr_double_t t) {
150  nr_double_t l = getPropertyDouble ("L");
151  nr_double_t a = getPropertyDouble ("Alpha");
152  nr_double_t z = getPropertyDouble ("Z");
153  nr_double_t T = l / C0;
154  a = std::log (a) / 2;
155  if (T > 0.0) {
156  T = t - T;
157  a = std::exp (-a / 2 * l);
158  setE (VSRC_1, a * (getV (NODE_2, T) + z * getJ (VSRC_2, T)));
159  setE (VSRC_2, a * (getV (NODE_1, T) + z * getJ (VSRC_1, T)));
160  }
161 }
162 
163 // properties
164 PROP_REQ [] = {
165  { "Z", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
166  { "L", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_NO_RANGE },
167  PROP_NO_PROP };
168 PROP_OPT [] = {
169  { "Alpha", PROP_REAL, { 1, PROP_NO_STR }, PROP_POS_RANGEX },
170  { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
171  PROP_NO_PROP };
172 struct define_t tline::cirdef =
std::complex< nr_double_t > nr_complex_t
Definition: complex.h:31
#define PROP_POS_RANGE
Definition: netdefs.h:129
void setHistory(bool h)
Definition: circuit.h:213
l
Definition: parse_vcd.y:213
#define NODE_2
Definition: circuit.h:35
#define T0
standard temperature
Definition: constants.h:61
#define kelvin(x)
Definition: constants.h:108
PROP_OPT[]
Definition: tline.cpp:168
#define PROP_DEF
Definition: netdefs.h:189
nr_double_t getPropertyDouble(const char *)
Definition: object.cpp:176
void setD(int, int, nr_complex_t)
Definition: circuit.cpp:373
#define PROP_REAL
Definition: netdefs.h:174
t
Definition: parse_vcd.y:290
#define PROP_NO_PROP
Definition: netdefs.h:122
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 setB(int, int, nr_complex_t)
Definition: circuit.cpp:349
#define PROP_LINEAR
Definition: netdefs.h:120
static const nr_double_t z0
Definition: circuit.h:320
r
Definition: parse_mdl.y:515
#define VSRC_1
Definition: circuit.h:40
nr_complex_t sqr(const nr_complex_t z)
Square of complex number.
Definition: complex.cpp:673
void initDC(void)
Definition: tline.cpp:83
nr_complex_t sqrt(const nr_complex_t z)
Compute principal value of square root.
Definition: complex.cpp:271
PROP_REQ[]
Definition: tline.cpp:164
nr_double_t getJ(int, nr_double_t)
Definition: circuit.cpp:951
nr_complex_t tanh(const nr_complex_t z)
Compute complex hyperbolic tangent.
Definition: complex.cpp:153
#define PROP_COMPONENT
Definition: netdefs.h:116
void deleteHistory(void)
Definition: circuit.cpp:886
void calcAC(nr_double_t)
Definition: tline.cpp:116
void setE(int, nr_complex_t)
Definition: circuit.cpp:385
#define M_PI
Archimedes' constant ( )
Definition: consts.h:47
void calcTR(nr_double_t)
Definition: tline.cpp:149
void setY(int, int, nr_complex_t)
Definition: circuit.cpp:452
#define PROP_MIN_VAL(k)
Definition: netdefs.h:133
void allocMatrixMNA(void)
Definition: circuit.cpp:267
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
void calcSP(nr_double_t)
Definition: tline.cpp:38
nr_double_t getV(int, nr_double_t)
Definition: circuit.cpp:941
void calcNoiseAC(nr_double_t)
Definition: tline.cpp:67
#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
nr_complex_t exp(const nr_complex_t z)
Compute complex exponential.
Definition: complex.cpp:205
Definition: tline.cpp:172
void setS(int, int, nr_complex_t)
Definition: circuit.cpp:587
void setN(int, int, nr_complex_t)
Definition: circuit.cpp:597
void initAC(void)
Definition: tline.cpp:104
void setC(int, int, nr_complex_t)
Definition: circuit.cpp:361
#define VSRC_2
Definition: circuit.h:41
void initHistory(nr_double_t)
Definition: circuit.cpp:869
nr_complex_t log(const nr_complex_t z)
Compute principal value of natural logarithm of z.
Definition: complex.cpp:215
void calcNoiseSP(nr_double_t)
Definition: tline.cpp:52
void initTR(void)
Definition: tline.cpp:130
#define PROP_NO_SUBSTRATE
Definition: netdefs.h:118