Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ctline.cpp
Go to the documentation of this file.
1 /*
2  * ctline.cpp - ideal coupled transmission line class implementation
3  *
4  * Copyright (C) 2011 Michael Margraf <michael.margraf@alumni.tu-berlin.de>
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: ctline.cpp 1876 2013-03-11 08:00:11Z fransschreuder $
22  *
23  */
24 
25 #if HAVE_CONFIG_H
26 # include <config.h>
27 #endif
28 
29 #include "component.h"
30 #include "ctline.h"
31 
32 using namespace qucs;
33 
34 ctline::ctline () : circuit (4) {
35  type = CIR_CTLINE;
36 }
37 
38 void ctline::calcSP (nr_double_t frequency) {
39  nr_double_t l = getPropertyDouble ("L");
40  nr_double_t ze = getPropertyDouble ("Ze");
41  nr_double_t zo = getPropertyDouble ("Zo");
42  nr_double_t ere = getPropertyDouble ("Ere");
43  nr_double_t ero = getPropertyDouble ("Ero");
44  nr_double_t ae = getPropertyDouble ("Ae");
45  nr_double_t ao = getPropertyDouble ("Ao");
46  nr_double_t o = 2.0 * M_PI * frequency;
47 
48  nr_complex_t ge = nr_complex_t (std::log (ae) / 2, o / C0 * std::sqrt (ere)) * l;
49  nr_complex_t go = nr_complex_t (std::log (ao) / 2, o / C0 * std::sqrt (ero)) * l;
50  nr_complex_t xe = 2.0 * ze * z0 * std::cosh (ge) + (ze*ze + z0*z0) * std::sinh (ge);
51  nr_complex_t xo = 2.0 * zo * z0 * std::cosh (go) + (zo*zo + z0*z0) * std::sinh (go);
52  nr_complex_t ye = ze * z0 / xe;
53  nr_complex_t yo = zo * z0 / xo;
54  xe = (ze*ze - z0*z0) * std::sinh (ge) / 2.0 / xe;
55  xo = (zo*zo - z0*z0) * std::sinh (go) / 2.0 / xo;
56 
57  setS (NODE_1, NODE_1, xe+xo); setS (NODE_2, NODE_2, xe+xo);
58  setS (NODE_3, NODE_3, xe+xo); setS (NODE_4, NODE_4, xe+xo);
59  setS (NODE_1, NODE_4, xe-xo); setS (NODE_4, NODE_1, xe-xo);
60  setS (NODE_2, NODE_3, xe-xo); setS (NODE_3, NODE_2, xe-xo);
61  setS (NODE_1, NODE_2, ye+yo); setS (NODE_2, NODE_1, ye+yo);
62  setS (NODE_3, NODE_4, ye+yo); setS (NODE_4, NODE_3, ye+yo);
63  setS (NODE_1, NODE_3, ye-yo); setS (NODE_3, NODE_1, ye-yo);
64  setS (NODE_2, NODE_4, ye-yo); setS (NODE_4, NODE_2, ye-yo);
65 }
66 
67 void ctline::calcNoiseSP (nr_double_t) {
68  nr_double_t l = getPropertyDouble ("L");
69  if (l < 0) return;
70  // calculate noise using Bosma's theorem
71  nr_double_t T = getPropertyDouble ("Temp");
72  matrix s = getMatrixS ();
73  matrix e = eye (getSize ());
74  setMatrixN (kelvin (T) / T0 * (e - s * transpose (conj (s))));
75 }
76 
77 void ctline::calcNoiseAC (nr_double_t) {
78  nr_double_t l = getPropertyDouble ("L");
79  if (l < 0) return;
80  // calculate noise using Bosma's theorem
81  nr_double_t T = getPropertyDouble ("Temp");
82  setMatrixN (4 * kelvin (T) / T0 * real (getMatrixY ()));
83 }
84 
85 void ctline::initDC (void) {
87  allocMatrixMNA ();
90 }
91 
92 void ctline::initAC (void) {
93  nr_double_t l = getPropertyDouble ("L");
94  if (l != 0.0) {
96  allocMatrixMNA ();
97  } else {
99  allocMatrixMNA ();
102  }
103 }
104 
105 void ctline::calcAC (nr_double_t frequency) {
106  nr_double_t l = getPropertyDouble ("L");
107  nr_double_t ze = getPropertyDouble ("Ze");
108  nr_double_t zo = getPropertyDouble ("Zo");
109  nr_double_t ere = getPropertyDouble ("Ere");
110  nr_double_t ero = getPropertyDouble ("Ero");
111  nr_double_t ae = getPropertyDouble ("Ae");
112  nr_double_t ao = getPropertyDouble ("Ao");
113  nr_double_t o = 2.0 * M_PI * frequency;
114 
115  if (l != 0.0) {
116  nr_complex_t y11, y12, y13, y14;
117  nr_complex_t arg_e = nr_complex_t (std::log (ae) / 2.0, o / C0 * std::sqrt (ere)) * l;
118  nr_complex_t arg_o = nr_complex_t (std::log (ao) / 2.0, o / C0 * std::sqrt (ero)) * l;
119 
120  y12 = 0.5 / sinh (arg_e) / ze;
121  y13 = -0.5 / sinh (arg_o) / zo;
122  arg_e = std::cosh (arg_e) * y12;
123  arg_o = std::cosh (arg_o) * y13;
124  y11 = arg_e - arg_o;
125  y14 = arg_e + arg_o;
126  arg_e = y12;
127  y12 = y13 - y12;
128  y13 = -y13 - arg_e;
129 
130  setY (NODE_1, NODE_1, +y11); setY (NODE_2, NODE_2, +y11);
131  setY (NODE_3, NODE_3, +y11); setY (NODE_4, NODE_4, +y11);
132  setY (NODE_1, NODE_2, +y12); setY (NODE_2, NODE_1, +y12);
133  setY (NODE_3, NODE_4, +y12); setY (NODE_4, NODE_3, +y12);
134  setY (NODE_1, NODE_3, +y13); setY (NODE_3, NODE_1, +y13);
135  setY (NODE_2, NODE_4, +y13); setY (NODE_4, NODE_2, +y13);
136  setY (NODE_1, NODE_4, +y14); setY (NODE_4, NODE_1, +y14);
137  setY (NODE_2, NODE_3, +y14); setY (NODE_3, NODE_2, +y14);
138  }
139 }
140 
141 // properties
142 PROP_REQ [] = {
143  { "Ze", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
144  { "Zo", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
145  { "L", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_NO_RANGE },
146  PROP_NO_PROP };
147 PROP_OPT [] = {
148  { "Ere", PROP_REAL, { 1, PROP_NO_STR }, PROP_POS_RANGE },
149  { "Ero", PROP_REAL, { 1, PROP_NO_STR }, PROP_POS_RANGE },
150  { "Ae", PROP_REAL, { 1, PROP_NO_STR }, PROP_POS_RANGEX },
151  { "Ao", PROP_REAL, { 1, PROP_NO_STR }, PROP_POS_RANGEX },
152  { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
153  PROP_NO_PROP };
154 struct define_t ctline::cirdef =
std::complex< nr_double_t > nr_complex_t
Definition: complex.h:31
#define PROP_POS_RANGE
Definition: netdefs.h:129
l
Definition: parse_vcd.y:213
PROP_OPT[]
Definition: ctline.cpp:147
#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 kelvin(x)
Definition: constants.h:108
#define PROP_DEF
Definition: netdefs.h:189
nr_double_t getPropertyDouble(const char *)
Definition: object.cpp:176
#define PROP_REAL
Definition: netdefs.h:174
void calcNoiseSP(nr_double_t)
Definition: ctline.cpp:67
#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 initAC(void)
Definition: ctline.cpp:92
#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
nr_complex_t cosh(const nr_complex_t z)
Compute complex hyperbolic cosine.
Definition: complex.cpp:135
#define VSRC_1
Definition: circuit.h:40
PROP_REQ[]
Definition: ctline.cpp:142
nr_complex_t sqrt(const nr_complex_t z)
Compute principal value of square root.
Definition: complex.cpp:271
#define PROP_COMPONENT
Definition: netdefs.h:116
void initDC(void)
Definition: ctline.cpp:85
void calcSP(nr_double_t)
Definition: ctline.cpp:38
#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
type
Definition: parse_vcd.y:164
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
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
#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
PROP_NO_SUBSTRATE
Definition: ctline.cpp:155
matrix eye(int rs, int cs)
Create identity matrix with specified number of rows and columns.
Definition: matrix.cpp:603
void setS(int, int, nr_complex_t)
Definition: circuit.cpp:587
matrix conj(matrix a)
Conjugate complex matrix.
Definition: matrix.cpp:505
#define VSRC_2
Definition: circuit.h:41
nr_complex_t log(const nr_complex_t z)
Compute principal value of natural logarithm of z.
Definition: complex.cpp:215
void calcNoiseAC(nr_double_t)
Definition: ctline.cpp:77
void calcAC(nr_double_t)
Definition: ctline.cpp:105