Qucs-core  0.0.19
rlcg.cpp
Go to the documentation of this file.
00001 /*
00002  * rlcg.cpp - lossy RLCG transmission line class implementation
00003  *
00004  * Copyright (C) 2009 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 "rlcg.h"
00031 
00032 using namespace qucs;
00033 
00034 rlcg::rlcg () : circuit (2) {
00035   type = CIR_RLCG;
00036 }
00037 
00038 // Calculates propagation constant and characteristic complex impedance.
00039 void rlcg::calcPropagation (nr_double_t frequency) {
00040   nr_double_t R = getPropertyDouble ("R");
00041   nr_double_t L = getPropertyDouble ("L");
00042   nr_double_t C = getPropertyDouble ("C");
00043   nr_double_t G = getPropertyDouble ("G");
00044   nr_complex_t Z = nr_complex_t (R, 2 * pi * frequency * L);
00045   nr_complex_t Y = nr_complex_t (G, 2 * pi * frequency * C);
00046   g = std::sqrt (Z * Y);
00047   z = std::sqrt (Z / Y);
00048 }
00049 
00050 void rlcg::calcSP (nr_double_t frequency) {
00051   nr_double_t l = getPropertyDouble ("Length");
00052   calcPropagation (frequency);
00053   nr_complex_t r = (z - z0) / (z + z0);
00054   nr_complex_t p = std::exp (-l * g);
00055   nr_complex_t s11 = r * (1.0 - p * p) / (1.0 - p * p * r * r);
00056   nr_complex_t s21 = p * (1.0 - r * r) / (1.0 - p * p * r * r);
00057   setS (NODE_1, NODE_1, s11); setS (NODE_2, NODE_2, s11);
00058   setS (NODE_1, NODE_2, s21); setS (NODE_2, NODE_1, s21);
00059 }
00060 
00061 void rlcg::saveCharacteristics (nr_double_t) {
00062   setCharacteristic ("Zl", real (z));
00063 }
00064 
00065 void rlcg::calcNoiseSP (nr_double_t) {
00066   nr_double_t l = getPropertyDouble ("Length");
00067   if (l == 0.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 rlcg::calcNoiseAC (nr_double_t) {
00076   nr_double_t l = getPropertyDouble ("Length");
00077   if (l == 0.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 rlcg::initDC (void) {
00084   nr_double_t R = getPropertyDouble ("R");
00085   nr_double_t l = getPropertyDouble ("Length");
00086   if (R != 0.0 && l != 0.0) {
00087     // a tiny resistance
00088     nr_double_t g = 1.0 / R / l;
00089     setVoltageSources (0);
00090     allocMatrixMNA ();
00091     setY (NODE_1, NODE_1, +g); setY (NODE_2, NODE_2, +g);
00092     setY (NODE_1, NODE_2, -g); setY (NODE_2, NODE_1, -g);
00093   }
00094   else {
00095     // a DC short
00096     setVoltageSources (1);
00097     setInternalVoltageSource (1);
00098     allocMatrixMNA ();
00099     voltageSource (VSRC_1, NODE_1, NODE_2);
00100   }
00101 }
00102 
00103 void rlcg::initAC (void) {
00104   nr_double_t l = getPropertyDouble ("L");
00105   if (l != 0.0) {
00106     setVoltageSources (0);
00107     allocMatrixMNA ();
00108   } else {
00109     setVoltageSources (1);
00110     allocMatrixMNA ();
00111     voltageSource (VSRC_1, NODE_1, NODE_2);
00112   }
00113 }
00114 
00115 void rlcg::calcAC (nr_double_t frequency) {
00116   nr_double_t l = getPropertyDouble ("Length");
00117   if (l != 0.0) {
00118     calcPropagation (frequency);
00119     nr_complex_t y11 = +1.0 / z / tanh (g * l);
00120     nr_complex_t y21 = -1.0 / z / sinh (g * l);
00121     setY (NODE_1, NODE_1, y11); setY (NODE_2, NODE_2, y11);
00122     setY (NODE_1, NODE_2, y21); setY (NODE_2, NODE_1, y21);
00123   }
00124 }
00125 
00126 void rlcg::initTR (void) {
00127   initDC ();
00128 }
00129 
00130 // properties
00131 PROP_REQ [] = {
00132   { "R", PROP_REAL, { 0.0, PROP_NO_STR }, PROP_POS_RANGE },
00133   { "L", PROP_REAL, { 0.6e-6, PROP_NO_STR }, PROP_POS_RANGEX },
00134   { "C", PROP_REAL, { 240e-12, PROP_NO_STR }, PROP_POS_RANGEX },
00135   { "G", PROP_REAL, { 0.0, PROP_NO_STR }, PROP_POS_RANGE },
00136   { "Length", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_NO_RANGE },
00137   PROP_NO_PROP };
00138 PROP_OPT [] = {
00139   { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
00140   PROP_NO_PROP };
00141 struct define_t rlcg::cirdef =
00142   { "RLCG", 2, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };