My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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: tline.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 "tline.h"
31 
32 tline::tline () : circuit (2) {
33  type = CIR_TLINE;
34 }
35 
36 void tline::calcSP (nr_double_t frequency) {
37  nr_double_t l = getPropertyDouble ("L");
38  nr_double_t z = getPropertyDouble ("Z");
39  nr_double_t a = getPropertyDouble ("Alpha");
40  nr_double_t r = (z - z0) / (z + z0);
41  nr_double_t b = 2 * M_PI * frequency / C0;
42  a = log (a) / 2;
43  nr_complex_t p = exp (-l * rect (a, b));
44  nr_complex_t s11 = r * (1.0 - p * p) / (1.0 - p * p * r * r);
45  nr_complex_t s21 = p * (1.0 - r * r) / (1.0 - p * p * r * r);
46  setS (NODE_1, NODE_1, s11); setS (NODE_2, NODE_2, s11);
47  setS (NODE_1, NODE_2, s21); setS (NODE_2, NODE_1, s21);
48 }
49 
50 void tline::calcNoiseSP (nr_double_t) {
51  nr_double_t T = getPropertyDouble ("Temp");
52  nr_double_t l = getPropertyDouble ("L");
53  nr_double_t z = getPropertyDouble ("Z");
54  nr_double_t a = getPropertyDouble ("Alpha");
55  a = log (a) / 2;
56  a = exp (a * l);
57  nr_double_t r = (z - z0) / (z + z0);
58  nr_double_t f = (a - 1) * (r * r - 1) / sqr (a - r * r) * kelvin (T) / T0;
59  nr_double_t n11 = -f * (r * r + a);
60  nr_double_t n21 = +f * 2 * r * sqrt (a);
61  setN (NODE_1, NODE_1, n11); setN (NODE_2, NODE_2, n11);
62  setN (NODE_1, NODE_2, n21); setN (NODE_2, NODE_1, n21);
63 }
64 
65 void tline::calcNoiseAC (nr_double_t) {
66  nr_double_t T = getPropertyDouble ("Temp");
67  nr_double_t l = getPropertyDouble ("L");
68  nr_double_t z = getPropertyDouble ("Z");
69  nr_double_t a = getPropertyDouble ("Alpha");
70  a = log (a) / 2;
71  if (a * l != 0.0) {
72  a = exp (a * l);
73  nr_double_t f = 4.0 * kelvin (T) / T0 / z / (a - 1);
74  nr_double_t n11 = +f * (a + 1);
75  nr_double_t n21 = -f * 2 * sqrt (a);
76  setN (NODE_1, NODE_1, n11); setN (NODE_2, NODE_2, n11);
77  setN (NODE_1, NODE_2, n21); setN (NODE_2, NODE_1, n21);
78  }
79 }
80 
81 void tline::initDC (void) {
82  nr_double_t z = getPropertyDouble ("Z");
83  nr_double_t a = getPropertyDouble ("Alpha");
84  nr_double_t l = getPropertyDouble ("L");
85  a = log (a) / 2;
86  if (a * l != 0.0) {
88  allocMatrixMNA ();
89  a = exp (a * l);
90  nr_double_t f = 1 / z / (a - 1);
91  nr_double_t y11 = +f * (a + 1);
92  nr_double_t y21 = -f * 2 * sqrt (a);
93  setY (NODE_1, NODE_1, y11); setY (NODE_2, NODE_2, y11);
94  setY (NODE_1, NODE_2, y21); setY (NODE_2, NODE_1, y21);
95  } else {
97  allocMatrixMNA ();
99  }
100 }
101 
102 void tline::initAC (void) {
103  nr_double_t l = getPropertyDouble ("L");
104  if (l != 0.0) {
105  setVoltageSources (0);
106  allocMatrixMNA ();
107  } else {
108  setVoltageSources (1);
109  allocMatrixMNA ();
111  }
112 }
113 
114 void tline::calcAC (nr_double_t frequency) {
115  nr_double_t l = getPropertyDouble ("L");
116  nr_double_t z = getPropertyDouble ("Z");
117  nr_double_t a = getPropertyDouble ("Alpha");
118  nr_double_t b = 2 * M_PI * frequency / C0;
119  a = log (a) / 2;
120  if (l != 0.0) {
121  nr_complex_t y11 = +1 / z / tanh (rect (a, b) * l);
122  nr_complex_t y21 = -1 / z / sinh (rect (a, b) * l);
123  setY (NODE_1, NODE_1, y11); setY (NODE_2, NODE_2, y11);
124  setY (NODE_1, NODE_2, y21); setY (NODE_2, NODE_1, y21);
125  }
126 }
127 
128 void tline::initTR (void) {
129  nr_double_t l = getPropertyDouble ("L");
130  nr_double_t z = getPropertyDouble ("Z");
131  deleteHistory ();
132  if (l > 0.0) {
133  setVoltageSources (2);
134  allocMatrixMNA ();
135  setHistory (true);
136  initHistory (l / C0);
137  setB (NODE_1, VSRC_1, +1); setB (NODE_2, VSRC_2, +1);
138  setC (VSRC_1, NODE_1, +1); setC (VSRC_2, NODE_2, +1);
139  setD (VSRC_1, VSRC_1, -z); setD (VSRC_2, VSRC_2, -z);
140  } else {
141  setVoltageSources (1);
142  allocMatrixMNA ();
144  }
145 }
146 
147 void tline::calcTR (nr_double_t t) {
148  nr_double_t l = getPropertyDouble ("L");
149  nr_double_t a = getPropertyDouble ("Alpha");
150  nr_double_t z = getPropertyDouble ("Z");
151  nr_double_t T = l / C0;
152  a = log (a) / 2;
153  if (T > 0.0) {
154  T = t - T;
155  a = exp (-a / 2 * l);
156  setE (VSRC_1, a * (getV (NODE_2, T) + z * getJ (VSRC_2, T)));
157  setE (VSRC_2, a * (getV (NODE_1, T) + z * getJ (VSRC_1, T)));
158  }
159 }
160 
161 // properties
162 PROP_REQ [] = {
163  { "Z", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
164  { "L", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_NO_RANGE },
165  PROP_NO_PROP };
166 PROP_OPT [] = {
167  { "Alpha", PROP_REAL, { 1, PROP_NO_STR }, PROP_POS_RANGEX },
168  { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
169  PROP_NO_PROP };
170 struct define_t tline::cirdef =