Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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$
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 using namespace qucs;
33 
34 tline4p::tline4p () : circuit (4) {
35  type = CIR_TLINE4P;
36 }
37 
38 void tline4p::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 b = 2 * M_PI * frequency / C0;
43  a = std::log (a) / 2;
44 
45  nr_complex_t g = nr_complex_t (a, b);
46  nr_double_t p = 2 * z0 + z;
47  nr_double_t n = 2 * z0 - z;
48  nr_complex_t e = std::exp (2.0 * g * l);
49  nr_complex_t d = p * p * e - n * n;
50 
51  nr_complex_t s11 = z * (p * e + n) / d;
52  nr_complex_t s14 = 1.0 - s11;
53  nr_complex_t s12 = 4.0 * z * z0 * std::exp (g * l) / d;
54 
55  setS (NODE_1, NODE_1, +s11); setS (NODE_2, NODE_2, +s11);
56  setS (NODE_3, NODE_3, +s11); setS (NODE_4, NODE_4, +s11);
57  setS (NODE_1, NODE_4, +s14); setS (NODE_4, NODE_1, +s14);
58  setS (NODE_2, NODE_3, +s14); setS (NODE_3, NODE_2, +s14);
59  setS (NODE_1, NODE_2, +s12); setS (NODE_2, NODE_1, +s12);
60  setS (NODE_3, NODE_4, +s12); setS (NODE_4, NODE_3, +s12);
61  setS (NODE_1, NODE_3, -s12); setS (NODE_3, NODE_1, -s12);
62  setS (NODE_2, NODE_4, -s12); setS (NODE_4, NODE_2, -s12);
63 }
64 
65 void tline4p::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 tline4p::calcNoiseAC (nr_double_t) {
76  nr_double_t l = getPropertyDouble ("L");
77  if (l < 0) return;
78  // calculate noise using Bosma's theorem
79  nr_double_t T = getPropertyDouble ("Temp");
80  setMatrixN (4 * kelvin (T) / T0 * real (getMatrixY ()));
81 }
82 
83 void tline4p::initDC (void) {
85  allocMatrixMNA ();
88 }
89 
90 void tline4p::initAC (void) {
91  nr_double_t l = getPropertyDouble ("L");
92  if (l != 0.0) {
94  allocMatrixMNA ();
95  } else {
97  allocMatrixMNA ();
100  }
101 }
102 
103 void tline4p::calcAC (nr_double_t frequency) {
104  nr_double_t l = getPropertyDouble ("L");
105  nr_double_t z = getPropertyDouble ("Z");
106  nr_double_t a = getPropertyDouble ("Alpha");
107  nr_double_t b = 2 * M_PI * frequency / C0;
108  a = std::log (a) / 2;
109  if (l != 0.0) {
110  nr_complex_t g = nr_complex_t (a, b);
111  nr_complex_t y11 = coth (g * l) / z;
112  nr_complex_t y21 = -cosech (g * l) / z;
113  setY (NODE_1, NODE_1, +y11); setY (NODE_2, NODE_2, +y11);
114  setY (NODE_3, NODE_3, +y11); setY (NODE_4, NODE_4, +y11);
115  setY (NODE_1, NODE_4, -y11); setY (NODE_4, NODE_1, -y11);
116  setY (NODE_2, NODE_3, -y11); setY (NODE_3, NODE_2, -y11);
117  setY (NODE_1, NODE_2, +y21); setY (NODE_2, NODE_1, +y21);
118  setY (NODE_3, NODE_4, +y21); setY (NODE_4, NODE_3, +y21);
119  setY (NODE_1, NODE_3, -y21); setY (NODE_3, NODE_1, -y21);
120  setY (NODE_2, NODE_4, -y21); setY (NODE_4, NODE_2, -y21);
121  }
122 }
123 
124 void tline4p::initTR (void) {
125  nr_double_t l = getPropertyDouble ("L");
126  nr_double_t z = getPropertyDouble ("Z");
127  deleteHistory ();
128  if (l > 0.0) {
129  setVoltageSources (2);
130  allocMatrixMNA ();
131  setHistory (true);
132  initHistory (l / C0);
133  setB (NODE_1, VSRC_1, +1); setB (NODE_2, VSRC_2, +1);
134  setB (NODE_4, VSRC_1, -1); setB (NODE_3, VSRC_2, -1);
135  setC (VSRC_1, NODE_1, +1); setC (VSRC_2, NODE_2, +1);
136  setC (VSRC_1, NODE_4, -1); setC (VSRC_2, NODE_3, -1);
137  setD (VSRC_1, VSRC_1, -z); setD (VSRC_2, VSRC_2, -z);
138  } else {
139  setVoltageSources (2);
140  allocMatrixMNA ();
143  }
144 }
145 
146 void tline4p::calcTR (nr_double_t t) {
147  nr_double_t l = getPropertyDouble ("L");
148  nr_double_t a = getPropertyDouble ("Alpha");
149  nr_double_t z = getPropertyDouble ("Z");
150  nr_double_t T = l / C0;
151  a = std::log (a) / 2;
152  if (T > 0.0) {
153  T = t - T;
154  a = std::exp (-a / 2 * l);
155  setE (VSRC_1, a * (getV (NODE_2, T) - getV (NODE_3, T) +
156  z * getJ (VSRC_2, T)));
157  setE (VSRC_2, a * (getV (NODE_1, T) - getV (NODE_4, T) +
158  z * getJ (VSRC_1, T)));
159  }
160 }
161 
162 // properties
163 PROP_REQ [] = {
164  { "Z", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
165  { "L", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_NO_RANGE },
166  PROP_NO_PROP };
167 PROP_OPT [] = {
168  { "Alpha", PROP_REAL, { 1, PROP_NO_STR }, PROP_POS_RANGEX },
169  { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
170  PROP_NO_PROP };
171 struct define_t tline4p::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
void calcNoiseSP(nr_double_t)
Definition: tline4p.cpp:65
#define NODE_2
Definition: circuit.h:35
matrix real(matrix a)
Real part matrix.
Definition: matrix.cpp:568
void initAC(void)
Definition: tline4p.cpp:90
#define T0
standard temperature
Definition: constants.h:61
#define kelvin(x)
Definition: constants.h:108
#define PROP_DEF
Definition: netdefs.h:189
void initDC(void)
Definition: tline4p.cpp:83
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
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
n
Definition: parse_citi.y:147
#define PROP_LINEAR
Definition: netdefs.h:120
static const nr_double_t z0
Definition: circuit.h:320
matrix getMatrixY(void)
Definition: circuit.cpp:696
int getSize(void)
Get the number of ports the circuit element has.
Definition: circuit.h:143
#define NODE_4
Definition: circuit.h:37
#define VSRC_1
Definition: circuit.h:40
void calcTR(nr_double_t)
Definition: tline4p.cpp:146
nr_double_t getJ(int, nr_double_t)
Definition: circuit.cpp:951
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
void deleteHistory(void)
Definition: circuit.cpp:886
void setE(int, nr_complex_t)
Definition: circuit.cpp:385
PROP_OPT[]
Definition: tline4p.cpp:167
void initTR(void)
Definition: tline4p.cpp:124
#define NODE_3
Definition: circuit.h:36
#define M_PI
Archimedes' constant ( )
Definition: consts.h:47
matrix transpose(matrix a)
Matrix transposition.
Definition: matrix.cpp:492
void calcAC(nr_double_t)
Definition: tline4p.cpp:103
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
void allocMatrixMNA(void)
Definition: circuit.cpp:267
void calcNoiseAC(nr_double_t)
Definition: tline4p.cpp:75
#define PROP_POS_RANGEX
Definition: netdefs.h:131
nr_double_t getV(int, nr_double_t)
Definition: circuit.cpp:941
#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
nr_complex_t exp(const nr_complex_t z)
Compute complex exponential.
Definition: complex.cpp:205
void setS(int, int, nr_complex_t)
Definition: circuit.cpp:587
matrix conj(matrix a)
Conjugate complex matrix.
Definition: matrix.cpp:505
void setC(int, int, nr_complex_t)
Definition: circuit.cpp:361
void calcSP(nr_double_t)
Definition: tline4p.cpp:38
#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
#define PROP_NO_SUBSTRATE
Definition: netdefs.h:118
PROP_REQ[]
Definition: tline4p.cpp:163