My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
tline4p.cpp
Go to the documentation of this file.
1 /*
2  * tline4p.cpp - ideal 4-terminal transmission line class implementation
3  *
4  * Copyright (C) 2007, 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: tline4p.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 "tline4p.h"
31 
32 tline4p::tline4p () : circuit (4) {
33  type = CIR_TLINE4P;
34 }
35 
36 void tline4p::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 b = 2 * M_PI * frequency / C0;
41  a = log (a) / 2;
42 
43  nr_complex_t g = rect (a, b);
44  nr_double_t p = 2 * z0 + z;
45  nr_double_t n = 2 * z0 - z;
46  nr_complex_t e = exp (2.0 * g * l);
47  nr_complex_t d = p * p * e - n * n;
48 
49  nr_complex_t s11 = z * (p * e + n) / d;
50  nr_complex_t s14 = 1.0 - s11;
51  nr_complex_t s12 = 4.0 * z * z0 * exp (g * l) / d;
52 
53  setS (NODE_1, NODE_1, +s11); setS (NODE_2, NODE_2, +s11);
54  setS (NODE_3, NODE_3, +s11); setS (NODE_4, NODE_4, +s11);
55  setS (NODE_1, NODE_4, +s14); setS (NODE_4, NODE_1, +s14);
56  setS (NODE_2, NODE_3, +s14); setS (NODE_3, NODE_2, +s14);
57  setS (NODE_1, NODE_2, +s12); setS (NODE_2, NODE_1, +s12);
58  setS (NODE_3, NODE_4, +s12); setS (NODE_4, NODE_3, +s12);
59  setS (NODE_1, NODE_3, -s12); setS (NODE_3, NODE_1, -s12);
60  setS (NODE_2, NODE_4, -s12); setS (NODE_4, NODE_2, -s12);
61 }
62 
63 void tline4p::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 tline4p::calcNoiseAC (nr_double_t) {
74  nr_double_t l = getPropertyDouble ("L");
75  if (l < 0) return;
76  // calculate noise using Bosma's theorem
77  nr_double_t T = getPropertyDouble ("Temp");
78  setMatrixN (4 * kelvin (T) / T0 * real (getMatrixY ()));
79 }
80 
81 void tline4p::initDC (void) {
83  allocMatrixMNA ();
86 }
87 
88 void tline4p::initAC (void) {
89  nr_double_t l = getPropertyDouble ("L");
90  if (l != 0.0) {
92  allocMatrixMNA ();
93  } else {
95  allocMatrixMNA ();
98  }
99 }
100 
101 void tline4p::calcAC (nr_double_t frequency) {
102  nr_double_t l = getPropertyDouble ("L");
103  nr_double_t z = getPropertyDouble ("Z");
104  nr_double_t a = getPropertyDouble ("Alpha");
105  nr_double_t b = 2 * M_PI * frequency / C0;
106  a = log (a) / 2;
107  if (l != 0.0) {
108  nr_complex_t g = rect (a, b);
109  nr_complex_t y11 = coth (g * l) / z;
110  nr_complex_t y21 = -cosech (g * l) / z;
111  setY (NODE_1, NODE_1, +y11); setY (NODE_2, NODE_2, +y11);
112  setY (NODE_3, NODE_3, +y11); setY (NODE_4, NODE_4, +y11);
113  setY (NODE_1, NODE_4, -y11); setY (NODE_4, NODE_1, -y11);
114  setY (NODE_2, NODE_3, -y11); setY (NODE_3, NODE_2, -y11);
115  setY (NODE_1, NODE_2, +y21); setY (NODE_2, NODE_1, +y21);
116  setY (NODE_3, NODE_4, +y21); setY (NODE_4, NODE_3, +y21);
117  setY (NODE_1, NODE_3, -y21); setY (NODE_3, NODE_1, -y21);
118  setY (NODE_2, NODE_4, -y21); setY (NODE_4, NODE_2, -y21);
119  }
120 }
121 
122 void tline4p::initTR (void) {
123  nr_double_t l = getPropertyDouble ("L");
124  nr_double_t z = getPropertyDouble ("Z");
125  deleteHistory ();
126  if (l > 0.0) {
127  setVoltageSources (2);
128  allocMatrixMNA ();
129  setHistory (true);
130  initHistory (l / C0);
131  setB (NODE_1, VSRC_1, +1); setB (NODE_2, VSRC_2, +1);
132  setB (NODE_4, VSRC_1, -1); setB (NODE_3, VSRC_2, -1);
133  setC (VSRC_1, NODE_1, +1); setC (VSRC_2, NODE_2, +1);
134  setC (VSRC_1, NODE_4, -1); setC (VSRC_2, NODE_3, -1);
135  setD (VSRC_1, VSRC_1, -z); setD (VSRC_2, VSRC_2, -z);
136  } else {
137  setVoltageSources (2);
138  allocMatrixMNA ();
141  }
142 }
143 
144 void tline4p::calcTR (nr_double_t t) {
145  nr_double_t l = getPropertyDouble ("L");
146  nr_double_t a = getPropertyDouble ("Alpha");
147  nr_double_t z = getPropertyDouble ("Z");
148  nr_double_t T = l / C0;
149  a = log (a) / 2;
150  if (T > 0.0) {
151  T = t - T;
152  a = exp (-a / 2 * l);
153  setE (VSRC_1, a * (getV (NODE_2, T) - getV (NODE_3, T) +
154  z * getJ (VSRC_2, T)));
155  setE (VSRC_2, a * (getV (NODE_1, T) - getV (NODE_4, T) +
156  z * getJ (VSRC_1, T)));
157  }
158 }
159 
160 // properties
161 PROP_REQ [] = {
162  { "Z", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
163  { "L", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_NO_RANGE },
164  PROP_NO_PROP };
165 PROP_OPT [] = {
166  { "Alpha", PROP_REAL, { 1, PROP_NO_STR }, PROP_POS_RANGEX },
167  { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
168  PROP_NO_PROP };
169 struct define_t tline4p::cirdef =