LCOV - code coverage report
Current view: top level - src/components - rlcg.cpp (source / functions) Hit Total Coverage
Test: qucs-core-0.0.19 Code Coverage Lines: 0 73 0.0 %
Date: 2015-01-05 16:01:02 Functions: 0 11 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 150 0.0 %

           Branch data     Line data    Source code
       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$
      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                 :            : using namespace qucs;
      33                 :            : 
      34                 :          0 : rlcg::rlcg () : circuit (2) {
      35                 :          0 :   type = CIR_RLCG;
      36                 :          0 : }
      37                 :            : 
      38                 :            : // Calculates propagation constant and characteristic complex impedance.
      39                 :          0 : void rlcg::calcPropagation (nr_double_t frequency) {
      40         [ #  # ]:          0 :   nr_double_t R = getPropertyDouble ("R");
      41         [ #  # ]:          0 :   nr_double_t L = getPropertyDouble ("L");
      42         [ #  # ]:          0 :   nr_double_t C = getPropertyDouble ("C");
      43         [ #  # ]:          0 :   nr_double_t G = getPropertyDouble ("G");
      44                 :          0 :   nr_complex_t Z = nr_complex_t (R, 2 * M_PI * frequency * L);
      45                 :          0 :   nr_complex_t Y = nr_complex_t (G, 2 * M_PI * frequency * C);
      46         [ #  # ]:          0 :   g = std::sqrt (Z * Y);
      47         [ #  # ]:          0 :   z = std::sqrt (Z / Y);
      48                 :          0 : }
      49                 :            : 
      50                 :          0 : void rlcg::calcSP (nr_double_t frequency) {
      51         [ #  # ]:          0 :   nr_double_t l = getPropertyDouble ("Length");
      52         [ #  # ]:          0 :   calcPropagation (frequency);
      53         [ #  # ]:          0 :   nr_complex_t r = (z - z0) / (z + z0);
      54                 :          0 :   nr_complex_t p = std::exp (-l * g);
      55 [ #  # ][ #  # ]:          0 :   nr_complex_t s11 = r * (1.0 - p * p) / (1.0 - p * p * r * r);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      56 [ #  # ][ #  # ]:          0 :   nr_complex_t s21 = p * (1.0 - r * r) / (1.0 - p * p * r * r);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      57 [ #  # ][ #  # ]:          0 :   setS (NODE_1, NODE_1, s11); setS (NODE_2, NODE_2, s11);
      58 [ #  # ][ #  # ]:          0 :   setS (NODE_1, NODE_2, s21); setS (NODE_2, NODE_1, s21);
      59                 :          0 : }
      60                 :            : 
      61                 :          0 : void rlcg::saveCharacteristics (nr_double_t) {
      62                 :          0 :   setCharacteristic ("Zl", real (z));
      63                 :          0 : }
      64                 :            : 
      65                 :          0 : void rlcg::calcNoiseSP (nr_double_t) {
      66         [ #  # ]:          0 :   nr_double_t l = getPropertyDouble ("Length");
      67         [ #  # ]:          0 :   if (l == 0.0) return;
      68                 :            :   // calculate noise using Bosma's theorem
      69         [ #  # ]:          0 :   nr_double_t T = getPropertyDouble ("Temp");
      70         [ #  # ]:          0 :   matrix s = getMatrixS ();
      71         [ #  # ]:          0 :   matrix e = eye (getSize ());
      72 [ #  # ][ #  # ]:          0 :   setMatrixN (kelvin (T) / T0 * (e - s * transpose (conj (s))));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      73                 :            : }
      74                 :            : 
      75                 :          0 : void rlcg::calcNoiseAC (nr_double_t) {
      76                 :          0 :   nr_double_t l = getPropertyDouble ("Length");
      77         [ #  # ]:          0 :   if (l == 0.0) return;
      78                 :            :   // calculate noise using Bosma's theorem
      79                 :          0 :   nr_double_t T = getPropertyDouble ("Temp");
      80 [ #  # ][ #  # ]:          0 :   setMatrixN (4 * kelvin (T) / T0 * real (getMatrixY ()));
         [ #  # ][ #  # ]
                 [ #  # ]
      81                 :            : }
      82                 :            : 
      83                 :          0 : void rlcg::initDC (void) {
      84                 :          0 :   nr_double_t R = getPropertyDouble ("R");
      85                 :          0 :   nr_double_t l = getPropertyDouble ("Length");
      86 [ #  # ][ #  # ]:          0 :   if (R != 0.0 && l != 0.0) {
      87                 :            :     // a tiny resistance
      88                 :          0 :     nr_double_t g = 1.0 / R / l;
      89                 :          0 :     setVoltageSources (0);
      90                 :          0 :     allocMatrixMNA ();
      91 [ #  # ][ #  # ]:          0 :     setY (NODE_1, NODE_1, +g); setY (NODE_2, NODE_2, +g);
      92 [ #  # ][ #  # ]:          0 :     setY (NODE_1, NODE_2, -g); setY (NODE_2, NODE_1, -g);
      93                 :            :   }
      94                 :            :   else {
      95                 :            :     // a DC short
      96                 :          0 :     setVoltageSources (1);
      97                 :          0 :     setInternalVoltageSource (1);
      98                 :          0 :     allocMatrixMNA ();
      99                 :          0 :     voltageSource (VSRC_1, NODE_1, NODE_2);
     100                 :            :   }
     101                 :          0 : }
     102                 :            : 
     103                 :          0 : void rlcg::initAC (void) {
     104                 :          0 :   nr_double_t l = getPropertyDouble ("L");
     105         [ #  # ]:          0 :   if (l != 0.0) {
     106                 :          0 :     setVoltageSources (0);
     107                 :          0 :     allocMatrixMNA ();
     108                 :            :   } else {
     109                 :          0 :     setVoltageSources (1);
     110                 :          0 :     allocMatrixMNA ();
     111                 :          0 :     voltageSource (VSRC_1, NODE_1, NODE_2);
     112                 :            :   }
     113                 :          0 : }
     114                 :            : 
     115                 :          0 : void rlcg::calcAC (nr_double_t frequency) {
     116         [ #  # ]:          0 :   nr_double_t l = getPropertyDouble ("Length");
     117         [ #  # ]:          0 :   if (l != 0.0) {
     118         [ #  # ]:          0 :     calcPropagation (frequency);
     119 [ #  # ][ #  # ]:          0 :     nr_complex_t y11 = +1.0 / z / tanh (g * l);
                 [ #  # ]
     120 [ #  # ][ #  # ]:          0 :     nr_complex_t y21 = -1.0 / z / sinh (g * l);
                 [ #  # ]
     121 [ #  # ][ #  # ]:          0 :     setY (NODE_1, NODE_1, y11); setY (NODE_2, NODE_2, y11);
     122 [ #  # ][ #  # ]:          0 :     setY (NODE_1, NODE_2, y21); setY (NODE_2, NODE_1, y21);
     123                 :            :   }
     124                 :          0 : }
     125                 :            : 
     126                 :          0 : void rlcg::initTR (void) {
     127                 :          0 :   initDC ();
     128                 :          0 : }
     129                 :            : 
     130                 :            : // properties
     131                 :            : PROP_REQ [] = {
     132                 :            :   { "R", PROP_REAL, { 0.0, PROP_NO_STR }, PROP_POS_RANGE },
     133                 :            :   { "L", PROP_REAL, { 0.6e-6, PROP_NO_STR }, PROP_POS_RANGEX },
     134                 :            :   { "C", PROP_REAL, { 240e-12, PROP_NO_STR }, PROP_POS_RANGEX },
     135                 :            :   { "G", PROP_REAL, { 0.0, PROP_NO_STR }, PROP_POS_RANGE },
     136                 :            :   { "Length", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_NO_RANGE },
     137                 :            :   PROP_NO_PROP };
     138                 :            : PROP_OPT [] = {
     139                 :            :   { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
     140                 :            :   PROP_NO_PROP };
     141                 :            : struct define_t rlcg::cirdef =
     142                 :            :   { "RLCG", 2, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };

Generated by: LCOV version 1.11