Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rlcg.cpp
Go to the documentation of this file.
1 /*
2  * rlcg.cpp - lossy RLCG transmission line class implementation
3  *
4  * Copyright (C) 2009 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 "rlcg.h"
31 
32 using namespace qucs;
33 
34 rlcg::rlcg () : circuit (2) {
35  type = CIR_RLCG;
36 }
37 
38 // Calculates propagation constant and characteristic complex impedance.
39 void rlcg::calcPropagation (nr_double_t frequency) {
40  nr_double_t R = getPropertyDouble ("R");
41  nr_double_t L = getPropertyDouble ("L");
42  nr_double_t C = getPropertyDouble ("C");
43  nr_double_t G = getPropertyDouble ("G");
44  nr_complex_t Z = nr_complex_t (R, 2 * M_PI * frequency * L);
45  nr_complex_t Y = nr_complex_t (G, 2 * M_PI * frequency * C);
46  g = std::sqrt (Z * Y);
47  z = std::sqrt (Z / Y);
48 }
49 
50 void rlcg::calcSP (nr_double_t frequency) {
51  nr_double_t l = getPropertyDouble ("Length");
52  calcPropagation (frequency);
53  nr_complex_t r = (z - z0) / (z + z0);
54  nr_complex_t p = std::exp (-l * g);
55  nr_complex_t s11 = r * (1.0 - p * p) / (1.0 - p * p * r * r);
56  nr_complex_t s21 = p * (1.0 - r * r) / (1.0 - p * p * r * r);
57  setS (NODE_1, NODE_1, s11); setS (NODE_2, NODE_2, s11);
58  setS (NODE_1, NODE_2, s21); setS (NODE_2, NODE_1, s21);
59 }
60 
61 void rlcg::saveCharacteristics (nr_double_t) {
62  setCharacteristic ("Zl", real (z));
63 }
64 
65 void rlcg::calcNoiseSP (nr_double_t) {
66  nr_double_t l = getPropertyDouble ("Length");
67  if (l == 0.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 rlcg::calcNoiseAC (nr_double_t) {
76  nr_double_t l = getPropertyDouble ("Length");
77  if (l == 0.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 rlcg::initDC (void) {
84  nr_double_t R = getPropertyDouble ("R");
85  nr_double_t l = getPropertyDouble ("Length");
86  if (R != 0.0 && l != 0.0) {
87  // a tiny resistance
88  nr_double_t g = 1.0 / R / l;
90  allocMatrixMNA ();
91  setY (NODE_1, NODE_1, +g); setY (NODE_2, NODE_2, +g);
92  setY (NODE_1, NODE_2, -g); setY (NODE_2, NODE_1, -g);
93  }
94  else {
95  // a DC short
98  allocMatrixMNA ();
100  }
101 }
102 
103 void rlcg::initAC (void) {
104  nr_double_t l = getPropertyDouble ("L");
105  if (l != 0.0) {
106  setVoltageSources (0);
107  allocMatrixMNA ();
108  } else {
109  setVoltageSources (1);
110  allocMatrixMNA ();
112  }
113 }
114 
115 void rlcg::calcAC (nr_double_t frequency) {
116  nr_double_t l = getPropertyDouble ("Length");
117  if (l != 0.0) {
118  calcPropagation (frequency);
119  nr_complex_t y11 = +1.0 / z / tanh (g * l);
120  nr_complex_t y21 = -1.0 / z / sinh (g * l);
121  setY (NODE_1, NODE_1, y11); setY (NODE_2, NODE_2, y11);
122  setY (NODE_1, NODE_2, y21); setY (NODE_2, NODE_1, y21);
123  }
124 }
125 
126 void rlcg::initTR (void) {
127  initDC ();
128 }
129 
130 // properties
131 PROP_REQ [] = {
132  { "R", PROP_REAL, { 0.0, PROP_NO_STR }, PROP_POS_RANGE },
133  { "L", PROP_REAL, { 0.6e-6, PROP_NO_STR }, PROP_POS_RANGEX },
134  { "C", PROP_REAL, { 240e-12, PROP_NO_STR }, PROP_POS_RANGEX },
135  { "G", PROP_REAL, { 0.0, PROP_NO_STR }, PROP_POS_RANGE },
136  { "Length", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_NO_RANGE },
137  PROP_NO_PROP };
138 PROP_OPT [] = {
139  { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
140  PROP_NO_PROP };
141 struct define_t rlcg::cirdef =
Definition: rlcg.cpp:141
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
nr_complex_t g
Definition: rlcg.h:43
#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
void saveCharacteristics(nr_double_t)
Definition: rlcg.cpp: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 C(c)
Definition: eqndefined.cpp:73
void calcNoiseSP(nr_double_t)
Definition: rlcg.cpp:65
void calcNoiseAC(nr_double_t)
Definition: rlcg.cpp:75
#define PROP_REAL
Definition: netdefs.h:174
void setInternalVoltageSource(bool i)
Definition: circuit.h:184
#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 initDC(void)
Definition: rlcg.cpp:83
#define PROP_LINEAR
Definition: netdefs.h:120
void initAC(void)
Definition: rlcg.cpp:103
static const nr_double_t z0
Definition: circuit.h:320
r
Definition: parse_mdl.y:515
void calcSP(nr_double_t)
Definition: rlcg.cpp:50
matrix getMatrixY(void)
Definition: circuit.cpp:696
int getSize(void)
Get the number of ports the circuit element has.
Definition: circuit.h:143
#define R(con)
#define VSRC_1
Definition: circuit.h:40
nr_complex_t sqrt(const nr_complex_t z)
Compute principal value of square root.
Definition: complex.cpp:271
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 calcAC(nr_double_t)
Definition: rlcg.cpp:115
void initTR(void)
Definition: rlcg.cpp:126
#define M_PI
Archimedes' constant ( )
Definition: consts.h:47
matrix transpose(matrix a)
Matrix transposition.
Definition: matrix.cpp:492
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
nr_complex_t z
Definition: rlcg.h:44
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
PROP_REQ[]
Definition: rlcg.cpp:131
#define NODE_1
Definition: circuit.h:34
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 calcPropagation(nr_double_t)
Definition: rlcg.cpp:39
void setCharacteristic(const char *, nr_double_t)
Definition: circuit.cpp:566
PROP_OPT[]
Definition: rlcg.cpp:138
#define PROP_NO_SUBSTRATE
Definition: netdefs.h:118