Qucs-core
0.0.19
|
00001 /* 00002 * tline.cpp - ideal transmission line class implementation 00003 * 00004 * Copyright (C) 2004, 2006, 2008 Stefan Jahn <stefan@lkcc.org> 00005 * 00006 * This is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2, or (at your option) 00009 * any later version. 00010 * 00011 * This software is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this package; see the file COPYING. If not, write to 00018 * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 * 00021 * $Id$ 00022 * 00023 */ 00024 00025 #if HAVE_CONFIG_H 00026 # include <config.h> 00027 #endif 00028 00029 #include "component.h" 00030 #include "tline.h" 00031 00032 using namespace qucs; 00033 00034 tline::tline () : circuit (2) { 00035 type = CIR_TLINE; 00036 } 00037 00038 void tline::calcSP (nr_double_t frequency) { 00039 nr_double_t l = getPropertyDouble ("L"); 00040 nr_double_t z = getPropertyDouble ("Z"); 00041 nr_double_t a = getPropertyDouble ("Alpha"); 00042 nr_double_t r = (z - z0) / (z + z0); 00043 nr_double_t b = 2 * pi * frequency / C0; 00044 a = std::log (a) / 2; 00045 nr_complex_t p = std::exp (-l * nr_complex_t (a, b)); 00046 nr_complex_t s11 = r * (1.0 - p * p) / (1.0 - p * p * r * r); 00047 nr_complex_t s21 = p * (1.0 - r * r) / (1.0 - p * p * r * r); 00048 setS (NODE_1, NODE_1, s11); setS (NODE_2, NODE_2, s11); 00049 setS (NODE_1, NODE_2, s21); setS (NODE_2, NODE_1, s21); 00050 } 00051 00052 void tline::calcNoiseSP (nr_double_t) { 00053 nr_double_t T = getPropertyDouble ("Temp"); 00054 nr_double_t l = getPropertyDouble ("L"); 00055 nr_double_t z = getPropertyDouble ("Z"); 00056 nr_double_t a = getPropertyDouble ("Alpha"); 00057 a = std::log (a) / 2; 00058 a = std::exp (a * l); 00059 nr_double_t r = (z - z0) / (z + z0); 00060 nr_double_t f = (a - 1) * (r * r - 1) / sqr (a - r * r) * celsius2kelvin (T) / T0; 00061 nr_double_t n11 = -f * (r * r + a); 00062 nr_double_t n21 = +f * 2 * r * std::sqrt (a); 00063 setN (NODE_1, NODE_1, n11); setN (NODE_2, NODE_2, n11); 00064 setN (NODE_1, NODE_2, n21); setN (NODE_2, NODE_1, n21); 00065 } 00066 00067 void tline::calcNoiseAC (nr_double_t) { 00068 nr_double_t T = getPropertyDouble ("Temp"); 00069 nr_double_t l = getPropertyDouble ("L"); 00070 nr_double_t z = getPropertyDouble ("Z"); 00071 nr_double_t a = getPropertyDouble ("Alpha"); 00072 a = std::log (a) / 2; 00073 if (a * l != 0.0) { 00074 a = std::exp (a * l); 00075 nr_double_t f = 4.0 * celsius2kelvin (T) / T0 / z / (a - 1); 00076 nr_double_t n11 = +f * (a + 1); 00077 nr_double_t n21 = -f * 2 * std::sqrt (a); 00078 setN (NODE_1, NODE_1, n11); setN (NODE_2, NODE_2, n11); 00079 setN (NODE_1, NODE_2, n21); setN (NODE_2, NODE_1, n21); 00080 } 00081 } 00082 00083 void tline::initDC (void) { 00084 nr_double_t z = getPropertyDouble ("Z"); 00085 nr_double_t a = getPropertyDouble ("Alpha"); 00086 nr_double_t l = getPropertyDouble ("L"); 00087 a = std::log (a) / 2; 00088 if (a * l != 0.0) { 00089 setVoltageSources (0); 00090 allocMatrixMNA (); 00091 a = std::exp (a * l); 00092 nr_double_t f = 1 / z / (a - 1); 00093 nr_double_t y11 = +f * (a + 1); 00094 nr_double_t y21 = -f * 2 * std::sqrt (a); 00095 setY (NODE_1, NODE_1, y11); setY (NODE_2, NODE_2, y11); 00096 setY (NODE_1, NODE_2, y21); setY (NODE_2, NODE_1, y21); 00097 } else { 00098 setVoltageSources (1); 00099 allocMatrixMNA (); 00100 voltageSource (VSRC_1, NODE_1, NODE_2); 00101 } 00102 } 00103 00104 void tline::initAC (void) { 00105 nr_double_t l = getPropertyDouble ("L"); 00106 if (l != 0.0) { 00107 setVoltageSources (0); 00108 allocMatrixMNA (); 00109 } else { 00110 setVoltageSources (1); 00111 allocMatrixMNA (); 00112 voltageSource (VSRC_1, NODE_1, NODE_2); 00113 } 00114 } 00115 00116 void tline::calcAC (nr_double_t frequency) { 00117 nr_double_t l = getPropertyDouble ("L"); 00118 nr_double_t z = getPropertyDouble ("Z"); 00119 nr_double_t a = getPropertyDouble ("Alpha"); 00120 nr_double_t b = 2 * pi * frequency / C0; 00121 a = std::log (a) / 2; 00122 if (l != 0.0) { 00123 nr_complex_t y11 = +1 / z / tanh (nr_complex_t (a, b) * l); 00124 nr_complex_t y21 = -1 / z / sinh (nr_complex_t (a, b) * l); 00125 setY (NODE_1, NODE_1, y11); setY (NODE_2, NODE_2, y11); 00126 setY (NODE_1, NODE_2, y21); setY (NODE_2, NODE_1, y21); 00127 } 00128 } 00129 00130 void tline::initTR (void) { 00131 nr_double_t l = getPropertyDouble ("L"); 00132 nr_double_t z = getPropertyDouble ("Z"); 00133 deleteHistory (); 00134 if (l > 0.0) { 00135 setVoltageSources (2); 00136 allocMatrixMNA (); 00137 setHistory (true); 00138 initHistory (l / C0); 00139 setB (NODE_1, VSRC_1, +1); setB (NODE_2, VSRC_2, +1); 00140 setC (VSRC_1, NODE_1, +1); setC (VSRC_2, NODE_2, +1); 00141 setD (VSRC_1, VSRC_1, -z); setD (VSRC_2, VSRC_2, -z); 00142 } else { 00143 setVoltageSources (1); 00144 allocMatrixMNA (); 00145 voltageSource (VSRC_1, NODE_1, NODE_2); 00146 } 00147 } 00148 00149 void tline::calcTR (nr_double_t t) { 00150 nr_double_t l = getPropertyDouble ("L"); 00151 nr_double_t a = getPropertyDouble ("Alpha"); 00152 nr_double_t z = getPropertyDouble ("Z"); 00153 nr_double_t T = l / C0; 00154 a = std::log (a) / 2; 00155 if (T > 0.0) { 00156 T = t - T; 00157 a = std::exp (-a / 2 * l); 00158 setE (VSRC_1, a * (getV (NODE_2, T) + z * getJ (VSRC_2, T))); 00159 setE (VSRC_2, a * (getV (NODE_1, T) + z * getJ (VSRC_1, T))); 00160 } 00161 } 00162 00163 // properties 00164 PROP_REQ [] = { 00165 { "Z", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE }, 00166 { "L", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_NO_RANGE }, 00167 PROP_NO_PROP }; 00168 PROP_OPT [] = { 00169 { "Alpha", PROP_REAL, { 1, PROP_NO_STR }, PROP_POS_RANGEX }, 00170 { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) }, 00171 PROP_NO_PROP }; 00172 struct define_t tline::cirdef = 00173 { "TLIN", 2, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };