My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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: rlcg.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 "rlcg.h"
31 
32 rlcg::rlcg () : circuit (2) {
33  type = CIR_RLCG;
34 }
35 
36 // Calculates propagation constant and characteristic complex impedance.
37 void rlcg::calcPropagation (nr_double_t frequency) {
38  nr_double_t R = getPropertyDouble ("R");
39  nr_double_t L = getPropertyDouble ("L");
40  nr_double_t C = getPropertyDouble ("C");
41  nr_double_t G = getPropertyDouble ("G");
42  nr_complex_t Z = rect (R, 2 * M_PI * frequency * L);
43  nr_complex_t Y = rect (G, 2 * M_PI * frequency * C);
44  g = sqrt (Z * Y);
45  z = sqrt (Z / Y);
46 }
47 
48 void rlcg::calcSP (nr_double_t frequency) {
49  nr_double_t l = getPropertyDouble ("Length");
50  calcPropagation (frequency);
51  nr_complex_t r = (z - z0) / (z + z0);
52  nr_complex_t p = exp (-l * g);
53  nr_complex_t s11 = r * (1.0 - p * p) / (1.0 - p * p * r * r);
54  nr_complex_t s21 = p * (1.0 - r * r) / (1.0 - p * p * r * r);
55  setS (NODE_1, NODE_1, s11); setS (NODE_2, NODE_2, s11);
56  setS (NODE_1, NODE_2, s21); setS (NODE_2, NODE_1, s21);
57 }
58 
59 void rlcg::saveCharacteristics (nr_double_t) {
60  setCharacteristic ("Zl", real (z));
61 }
62 
63 void rlcg::calcNoiseSP (nr_double_t) {
64  nr_double_t l = getPropertyDouble ("Length");
65  if (l == 0.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 rlcg::calcNoiseAC (nr_double_t) {
74  nr_double_t l = getPropertyDouble ("Length");
75  if (l == 0.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 rlcg::initDC (void) {
82  nr_double_t R = getPropertyDouble ("R");
83  nr_double_t l = getPropertyDouble ("Length");
84  if (R != 0.0 && l != 0.0) {
85  // a tiny resistance
86  nr_double_t g = 1.0 / R / l;
88  allocMatrixMNA ();
89  setY (NODE_1, NODE_1, +g); setY (NODE_2, NODE_2, +g);
90  setY (NODE_1, NODE_2, -g); setY (NODE_2, NODE_1, -g);
91  }
92  else {
93  // a DC short
96  allocMatrixMNA ();
98  }
99 }
100 
101 void rlcg::initAC (void) {
102  nr_double_t l = getPropertyDouble ("L");
103  if (l != 0.0) {
104  setVoltageSources (0);
105  allocMatrixMNA ();
106  } else {
107  setVoltageSources (1);
108  allocMatrixMNA ();
110  }
111 }
112 
113 void rlcg::calcAC (nr_double_t frequency) {
114  nr_double_t l = getPropertyDouble ("Length");
115  if (l != 0.0) {
116  calcPropagation (frequency);
117  nr_complex_t y11 = +1.0 / z / tanh (g * l);
118  nr_complex_t y21 = -1.0 / z / sinh (g * l);
119  setY (NODE_1, NODE_1, y11); setY (NODE_2, NODE_2, y11);
120  setY (NODE_1, NODE_2, y21); setY (NODE_2, NODE_1, y21);
121  }
122 }
123 
124 void rlcg::initTR (void) {
125  initDC ();
126 }
127 
128 // properties
129 PROP_REQ [] = {
130  { "R", PROP_REAL, { 0.0, PROP_NO_STR }, PROP_POS_RANGE },
131  { "L", PROP_REAL, { 0.6e-6, PROP_NO_STR }, PROP_POS_RANGEX },
132  { "C", PROP_REAL, { 240e-12, PROP_NO_STR }, PROP_POS_RANGEX },
133  { "G", PROP_REAL, { 0.0, PROP_NO_STR }, PROP_POS_RANGE },
134  { "Length", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_NO_RANGE },
135  PROP_NO_PROP };
136 PROP_OPT [] = {
137  { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
138  PROP_NO_PROP };
139 struct define_t rlcg::cirdef =