Qucs-core  0.0.19
ctline.cpp
Go to the documentation of this file.
00001 /*
00002  * ctline.cpp - ideal coupled transmission line class implementation
00003  *
00004  * Copyright (C) 2011 Michael Margraf <michael.margraf@alumni.tu-berlin.de>
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: ctline.cpp 1876 2013-03-11 08:00:11Z fransschreuder $
00022  *
00023  */
00024 
00025 #if HAVE_CONFIG_H
00026 # include <config.h>
00027 #endif
00028 
00029 #include "component.h"
00030 #include "ctline.h"
00031 
00032 using namespace qucs;
00033 
00034 ctline::ctline () : circuit (4) {
00035   type = CIR_CTLINE;
00036 }
00037 
00038 void ctline::calcSP (nr_double_t frequency) {
00039   nr_double_t l   = getPropertyDouble ("L");
00040   nr_double_t ze  = getPropertyDouble ("Ze");
00041   nr_double_t zo  = getPropertyDouble ("Zo");
00042   nr_double_t ere = getPropertyDouble ("Ere");
00043   nr_double_t ero = getPropertyDouble ("Ero");
00044   nr_double_t ae  = getPropertyDouble ("Ae");
00045   nr_double_t ao  = getPropertyDouble ("Ao");
00046   nr_double_t o   = 2.0 * pi * frequency;
00047 
00048   nr_complex_t ge = nr_complex_t (std::log (ae) / 2, o / C0 * std::sqrt (ere)) * l;
00049   nr_complex_t go = nr_complex_t (std::log (ao) / 2, o / C0 * std::sqrt (ero)) * l;
00050   nr_complex_t xe = 2.0 * ze * z0 * std::cosh (ge) + (ze*ze + z0*z0) * std::sinh (ge);
00051   nr_complex_t xo = 2.0 * zo * z0 * std::cosh (go) + (zo*zo + z0*z0) * std::sinh (go);
00052   nr_complex_t ye = ze * z0 / xe;
00053   nr_complex_t yo = zo * z0 / xo;
00054   xe = (ze*ze - z0*z0) * std::sinh (ge) / 2.0 / xe;
00055   xo = (zo*zo - z0*z0) * std::sinh (go) / 2.0 / xo;
00056 
00057   setS (NODE_1, NODE_1, xe+xo); setS (NODE_2, NODE_2, xe+xo);
00058   setS (NODE_3, NODE_3, xe+xo); setS (NODE_4, NODE_4, xe+xo);
00059   setS (NODE_1, NODE_4, xe-xo); setS (NODE_4, NODE_1, xe-xo);
00060   setS (NODE_2, NODE_3, xe-xo); setS (NODE_3, NODE_2, xe-xo);
00061   setS (NODE_1, NODE_2, ye+yo); setS (NODE_2, NODE_1, ye+yo);
00062   setS (NODE_3, NODE_4, ye+yo); setS (NODE_4, NODE_3, ye+yo);
00063   setS (NODE_1, NODE_3, ye-yo); setS (NODE_3, NODE_1, ye-yo);
00064   setS (NODE_2, NODE_4, ye-yo); setS (NODE_4, NODE_2, ye-yo);
00065 }
00066 
00067 void ctline::calcNoiseSP (nr_double_t) {
00068   nr_double_t l = getPropertyDouble ("L");
00069   if (l < 0) return;
00070   // calculate noise using Bosma's theorem
00071   nr_double_t T = getPropertyDouble ("Temp");
00072   matrix s = getMatrixS ();
00073   matrix e = eye (getSize ());
00074   setMatrixN (celsius2kelvin (T) / T0 * (e - s * transpose (conj (s))));
00075 }
00076 
00077 void ctline::calcNoiseAC (nr_double_t) {
00078   nr_double_t l = getPropertyDouble ("L");
00079   if (l < 0) return;
00080   // calculate noise using Bosma's theorem
00081   nr_double_t T = getPropertyDouble ("Temp");
00082   setMatrixN (4 * celsius2kelvin (T) / T0 * real (getMatrixY ()));
00083 }
00084 
00085 void ctline::initDC (void) {
00086   setVoltageSources (2);
00087   allocMatrixMNA ();
00088   voltageSource (VSRC_1, NODE_1, NODE_2);
00089   voltageSource (VSRC_2, NODE_3, NODE_4);
00090 }
00091 
00092 void ctline::initAC (void) {
00093   nr_double_t l = getPropertyDouble ("L");
00094   if (l != 0.0) {
00095     setVoltageSources (0);
00096     allocMatrixMNA ();
00097   } else {
00098     setVoltageSources (2);
00099     allocMatrixMNA ();
00100     voltageSource (VSRC_1, NODE_1, NODE_2);
00101     voltageSource (VSRC_2, NODE_3, NODE_4);
00102   }
00103 }
00104 
00105 void ctline::calcAC (nr_double_t frequency) {
00106   nr_double_t l   = getPropertyDouble ("L");
00107   nr_double_t ze  = getPropertyDouble ("Ze");
00108   nr_double_t zo  = getPropertyDouble ("Zo");
00109   nr_double_t ere = getPropertyDouble ("Ere");
00110   nr_double_t ero = getPropertyDouble ("Ero");
00111   nr_double_t ae  = getPropertyDouble ("Ae");
00112   nr_double_t ao  = getPropertyDouble ("Ao");
00113   nr_double_t o   = 2.0 * pi * frequency;
00114 
00115   if (l != 0.0) {
00116     nr_complex_t y11, y12, y13, y14;
00117     nr_complex_t arg_e = nr_complex_t (std::log (ae) / 2.0, o / C0 * std::sqrt (ere)) * l;
00118     nr_complex_t arg_o = nr_complex_t (std::log (ao) / 2.0, o / C0 * std::sqrt (ero)) * l;
00119 
00120     y12   =  0.5 / sinh (arg_e) / ze;
00121     y13   = -0.5 / sinh (arg_o) / zo;
00122     arg_e = std::cosh (arg_e) * y12;
00123     arg_o = std::cosh (arg_o) * y13;
00124     y11   = arg_e - arg_o;
00125     y14   = arg_e + arg_o;
00126     arg_e = y12;
00127     y12   =  y13 - y12;
00128     y13   = -y13 - arg_e;
00129 
00130     setY (NODE_1, NODE_1, +y11); setY (NODE_2, NODE_2, +y11);
00131     setY (NODE_3, NODE_3, +y11); setY (NODE_4, NODE_4, +y11);
00132     setY (NODE_1, NODE_2, +y12); setY (NODE_2, NODE_1, +y12);
00133     setY (NODE_3, NODE_4, +y12); setY (NODE_4, NODE_3, +y12);
00134     setY (NODE_1, NODE_3, +y13); setY (NODE_3, NODE_1, +y13);
00135     setY (NODE_2, NODE_4, +y13); setY (NODE_4, NODE_2, +y13);
00136     setY (NODE_1, NODE_4, +y14); setY (NODE_4, NODE_1, +y14);
00137     setY (NODE_2, NODE_3, +y14); setY (NODE_3, NODE_2, +y14);
00138   }
00139 }
00140 
00141 // properties
00142 PROP_REQ [] = {
00143   { "Ze", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
00144   { "Zo", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
00145   { "L", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_NO_RANGE },
00146   PROP_NO_PROP };
00147 PROP_OPT [] = {
00148   { "Ere", PROP_REAL, { 1, PROP_NO_STR }, PROP_POS_RANGE },
00149   { "Ero", PROP_REAL, { 1, PROP_NO_STR }, PROP_POS_RANGE },
00150   { "Ae", PROP_REAL, { 1, PROP_NO_STR }, PROP_POS_RANGEX },
00151   { "Ao", PROP_REAL, { 1, PROP_NO_STR }, PROP_POS_RANGEX },
00152   { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
00153   PROP_NO_PROP };
00154 struct define_t ctline::cirdef =
00155   { "CTLIN", 4, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };