Qucs-core
0.0.19
|
00001 /* 00002 * tline4p.cpp - ideal 4-terminal transmission line class implementation 00003 * 00004 * Copyright (C) 2007, 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 "tline4p.h" 00031 00032 using namespace qucs; 00033 00034 tline4p::tline4p () : circuit (4) { 00035 type = CIR_TLINE4P; 00036 } 00037 00038 void tline4p::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 b = 2 * pi * frequency / C0; 00043 a = std::log (a) / 2; 00044 00045 nr_complex_t g = nr_complex_t (a, b); 00046 nr_double_t p = 2 * z0 + z; 00047 nr_double_t n = 2 * z0 - z; 00048 nr_complex_t e = std::exp (2.0 * g * l); 00049 nr_complex_t d = p * p * e - n * n; 00050 00051 nr_complex_t s11 = z * (p * e + n) / d; 00052 nr_complex_t s14 = 1.0 - s11; 00053 nr_complex_t s12 = 4.0 * z * z0 * std::exp (g * l) / d; 00054 00055 setS (NODE_1, NODE_1, +s11); setS (NODE_2, NODE_2, +s11); 00056 setS (NODE_3, NODE_3, +s11); setS (NODE_4, NODE_4, +s11); 00057 setS (NODE_1, NODE_4, +s14); setS (NODE_4, NODE_1, +s14); 00058 setS (NODE_2, NODE_3, +s14); setS (NODE_3, NODE_2, +s14); 00059 setS (NODE_1, NODE_2, +s12); setS (NODE_2, NODE_1, +s12); 00060 setS (NODE_3, NODE_4, +s12); setS (NODE_4, NODE_3, +s12); 00061 setS (NODE_1, NODE_3, -s12); setS (NODE_3, NODE_1, -s12); 00062 setS (NODE_2, NODE_4, -s12); setS (NODE_4, NODE_2, -s12); 00063 } 00064 00065 void tline4p::calcNoiseSP (nr_double_t) { 00066 nr_double_t l = getPropertyDouble ("L"); 00067 if (l < 0) return; 00068 // calculate noise using Bosma's theorem 00069 nr_double_t T = getPropertyDouble ("Temp"); 00070 matrix s = getMatrixS (); 00071 matrix e = eye (getSize ()); 00072 setMatrixN (celsius2kelvin (T) / T0 * (e - s * transpose (conj (s)))); 00073 } 00074 00075 void tline4p::calcNoiseAC (nr_double_t) { 00076 nr_double_t l = getPropertyDouble ("L"); 00077 if (l < 0) return; 00078 // calculate noise using Bosma's theorem 00079 nr_double_t T = getPropertyDouble ("Temp"); 00080 setMatrixN (4 * celsius2kelvin (T) / T0 * real (getMatrixY ())); 00081 } 00082 00083 void tline4p::initDC (void) { 00084 setVoltageSources (2); 00085 allocMatrixMNA (); 00086 voltageSource (VSRC_1, NODE_1, NODE_2); 00087 voltageSource (VSRC_2, NODE_3, NODE_4); 00088 } 00089 00090 void tline4p::initAC (void) { 00091 nr_double_t l = getPropertyDouble ("L"); 00092 if (l != 0.0) { 00093 setVoltageSources (0); 00094 allocMatrixMNA (); 00095 } else { 00096 setVoltageSources (2); 00097 allocMatrixMNA (); 00098 voltageSource (VSRC_1, NODE_1, NODE_2); 00099 voltageSource (VSRC_2, NODE_3, NODE_4); 00100 } 00101 } 00102 00103 void tline4p::calcAC (nr_double_t frequency) { 00104 nr_double_t l = getPropertyDouble ("L"); 00105 nr_double_t z = getPropertyDouble ("Z"); 00106 nr_double_t a = getPropertyDouble ("Alpha"); 00107 nr_double_t b = 2 * pi * frequency / C0; 00108 a = std::log (a) / 2; 00109 if (l != 0.0) { 00110 nr_complex_t g = nr_complex_t (a, b); 00111 nr_complex_t y11 = coth (g * l) / z; 00112 nr_complex_t y21 = -cosech (g * l) / z; 00113 setY (NODE_1, NODE_1, +y11); setY (NODE_2, NODE_2, +y11); 00114 setY (NODE_3, NODE_3, +y11); setY (NODE_4, NODE_4, +y11); 00115 setY (NODE_1, NODE_4, -y11); setY (NODE_4, NODE_1, -y11); 00116 setY (NODE_2, NODE_3, -y11); setY (NODE_3, NODE_2, -y11); 00117 setY (NODE_1, NODE_2, +y21); setY (NODE_2, NODE_1, +y21); 00118 setY (NODE_3, NODE_4, +y21); setY (NODE_4, NODE_3, +y21); 00119 setY (NODE_1, NODE_3, -y21); setY (NODE_3, NODE_1, -y21); 00120 setY (NODE_2, NODE_4, -y21); setY (NODE_4, NODE_2, -y21); 00121 } 00122 } 00123 00124 void tline4p::initTR (void) { 00125 nr_double_t l = getPropertyDouble ("L"); 00126 nr_double_t z = getPropertyDouble ("Z"); 00127 deleteHistory (); 00128 if (l > 0.0) { 00129 setVoltageSources (2); 00130 allocMatrixMNA (); 00131 setHistory (true); 00132 initHistory (l / C0); 00133 setB (NODE_1, VSRC_1, +1); setB (NODE_2, VSRC_2, +1); 00134 setB (NODE_4, VSRC_1, -1); setB (NODE_3, VSRC_2, -1); 00135 setC (VSRC_1, NODE_1, +1); setC (VSRC_2, NODE_2, +1); 00136 setC (VSRC_1, NODE_4, -1); setC (VSRC_2, NODE_3, -1); 00137 setD (VSRC_1, VSRC_1, -z); setD (VSRC_2, VSRC_2, -z); 00138 } else { 00139 setVoltageSources (2); 00140 allocMatrixMNA (); 00141 voltageSource (VSRC_1, NODE_1, NODE_2); 00142 voltageSource (VSRC_2, NODE_3, NODE_4); 00143 } 00144 } 00145 00146 void tline4p::calcTR (nr_double_t t) { 00147 nr_double_t l = getPropertyDouble ("L"); 00148 nr_double_t a = getPropertyDouble ("Alpha"); 00149 nr_double_t z = getPropertyDouble ("Z"); 00150 nr_double_t T = l / C0; 00151 a = std::log (a) / 2; 00152 if (T > 0.0) { 00153 T = t - T; 00154 a = std::exp (-a / 2 * l); 00155 setE (VSRC_1, a * (getV (NODE_2, T) - getV (NODE_3, T) + 00156 z * getJ (VSRC_2, T))); 00157 setE (VSRC_2, a * (getV (NODE_1, T) - getV (NODE_4, T) + 00158 z * getJ (VSRC_1, T))); 00159 } 00160 } 00161 00162 // properties 00163 PROP_REQ [] = { 00164 { "Z", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE }, 00165 { "L", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_NO_RANGE }, 00166 PROP_NO_PROP }; 00167 PROP_OPT [] = { 00168 { "Alpha", PROP_REAL, { 1, PROP_NO_STR }, PROP_POS_RANGEX }, 00169 { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) }, 00170 PROP_NO_PROP }; 00171 struct define_t tline4p::cirdef = 00172 { "TLIN4P", 4, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };