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

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * tline4p.cpp - ideal 4-terminal transmission line class implementation
       3                 :            :  *
       4                 :            :  * Copyright (C) 2007, 2008 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 "tline4p.h"
      31                 :            : 
      32                 :            : using namespace qucs;
      33                 :            : 
      34                 :          0 : tline4p::tline4p () : circuit (4) {
      35                 :          0 :   type = CIR_TLINE4P;
      36                 :          0 : }
      37                 :            : 
      38                 :          0 : void tline4p::calcSP (nr_double_t frequency) {
      39         [ #  # ]:          0 :   nr_double_t l = getPropertyDouble ("L");
      40         [ #  # ]:          0 :   nr_double_t z = getPropertyDouble ("Z");
      41         [ #  # ]:          0 :   nr_double_t a = getPropertyDouble ("Alpha");
      42                 :          0 :   nr_double_t b = 2 * M_PI * frequency / C0;
      43                 :          0 :   a = std::log (a) / 2;
      44                 :            : 
      45                 :          0 :   nr_complex_t g = nr_complex_t (a, b);
      46                 :          0 :   nr_double_t p = 2 * z0 + z;
      47                 :          0 :   nr_double_t n = 2 * z0 - z;
      48                 :          0 :   nr_complex_t e = std::exp (2.0 * g * l);
      49                 :          0 :   nr_complex_t d = p * p * e - n * n;
      50                 :            : 
      51         [ #  # ]:          0 :   nr_complex_t s11 = z * (p * e + n) / d;
      52                 :          0 :   nr_complex_t s14 = 1.0 - s11;
      53         [ #  # ]:          0 :   nr_complex_t s12 = 4.0 * z * z0 * std::exp (g * l) / d;
      54                 :            : 
      55 [ #  # ][ #  # ]:          0 :   setS (NODE_1, NODE_1, +s11); setS (NODE_2, NODE_2, +s11);
      56 [ #  # ][ #  # ]:          0 :   setS (NODE_3, NODE_3, +s11); setS (NODE_4, NODE_4, +s11);
      57 [ #  # ][ #  # ]:          0 :   setS (NODE_1, NODE_4, +s14); setS (NODE_4, NODE_1, +s14);
      58 [ #  # ][ #  # ]:          0 :   setS (NODE_2, NODE_3, +s14); setS (NODE_3, NODE_2, +s14);
      59 [ #  # ][ #  # ]:          0 :   setS (NODE_1, NODE_2, +s12); setS (NODE_2, NODE_1, +s12);
      60 [ #  # ][ #  # ]:          0 :   setS (NODE_3, NODE_4, +s12); setS (NODE_4, NODE_3, +s12);
      61 [ #  # ][ #  # ]:          0 :   setS (NODE_1, NODE_3, -s12); setS (NODE_3, NODE_1, -s12);
      62 [ #  # ][ #  # ]:          0 :   setS (NODE_2, NODE_4, -s12); setS (NODE_4, NODE_2, -s12);
      63                 :          0 : }
      64                 :            : 
      65                 :          0 : void tline4p::calcNoiseSP (nr_double_t) {
      66         [ #  # ]:          0 :   nr_double_t l = getPropertyDouble ("L");
      67         [ #  # ]:          0 :   if (l < 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 tline4p::calcNoiseAC (nr_double_t) {
      76                 :          0 :   nr_double_t l = getPropertyDouble ("L");
      77         [ #  # ]:          0 :   if (l < 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 tline4p::initDC (void) {
      84                 :          0 :   setVoltageSources (2);
      85                 :          0 :   allocMatrixMNA ();
      86                 :          0 :   voltageSource (VSRC_1, NODE_1, NODE_2);
      87                 :          0 :   voltageSource (VSRC_2, NODE_3, NODE_4);
      88                 :          0 : }
      89                 :            : 
      90                 :          0 : void tline4p::initAC (void) {
      91                 :          0 :   nr_double_t l = getPropertyDouble ("L");
      92         [ #  # ]:          0 :   if (l != 0.0) {
      93                 :          0 :     setVoltageSources (0);
      94                 :          0 :     allocMatrixMNA ();
      95                 :            :   } else {
      96                 :          0 :     setVoltageSources (2);
      97                 :          0 :     allocMatrixMNA ();
      98                 :          0 :     voltageSource (VSRC_1, NODE_1, NODE_2);
      99                 :          0 :     voltageSource (VSRC_2, NODE_3, NODE_4);
     100                 :            :   }
     101                 :          0 : }
     102                 :            : 
     103                 :          0 : void tline4p::calcAC (nr_double_t frequency) {
     104         [ #  # ]:          0 :   nr_double_t l = getPropertyDouble ("L");
     105         [ #  # ]:          0 :   nr_double_t z = getPropertyDouble ("Z");
     106         [ #  # ]:          0 :   nr_double_t a = getPropertyDouble ("Alpha");
     107                 :          0 :   nr_double_t b = 2 * M_PI * frequency / C0;
     108                 :          0 :   a = std::log (a) / 2;
     109         [ #  # ]:          0 :   if (l != 0.0) {
     110                 :          0 :     nr_complex_t g = nr_complex_t (a, b);
     111         [ #  # ]:          0 :     nr_complex_t y11 = coth (g * l) / z;
     112         [ #  # ]:          0 :     nr_complex_t y21 = -cosech (g * l) / z;
     113 [ #  # ][ #  # ]:          0 :     setY (NODE_1, NODE_1, +y11); setY (NODE_2, NODE_2, +y11);
     114 [ #  # ][ #  # ]:          0 :     setY (NODE_3, NODE_3, +y11); setY (NODE_4, NODE_4, +y11);
     115 [ #  # ][ #  # ]:          0 :     setY (NODE_1, NODE_4, -y11); setY (NODE_4, NODE_1, -y11);
     116 [ #  # ][ #  # ]:          0 :     setY (NODE_2, NODE_3, -y11); setY (NODE_3, NODE_2, -y11);
     117 [ #  # ][ #  # ]:          0 :     setY (NODE_1, NODE_2, +y21); setY (NODE_2, NODE_1, +y21);
     118 [ #  # ][ #  # ]:          0 :     setY (NODE_3, NODE_4, +y21); setY (NODE_4, NODE_3, +y21);
     119 [ #  # ][ #  # ]:          0 :     setY (NODE_1, NODE_3, -y21); setY (NODE_3, NODE_1, -y21);
     120 [ #  # ][ #  # ]:          0 :     setY (NODE_2, NODE_4, -y21); setY (NODE_4, NODE_2, -y21);
     121                 :            :   }
     122                 :          0 : }
     123                 :            : 
     124                 :          0 : void tline4p::initTR (void) {
     125                 :          0 :   nr_double_t l = getPropertyDouble ("L");
     126                 :          0 :   nr_double_t z = getPropertyDouble ("Z");
     127                 :          0 :   deleteHistory ();
     128         [ #  # ]:          0 :   if (l > 0.0) {
     129                 :          0 :     setVoltageSources (2);
     130                 :          0 :     allocMatrixMNA ();
     131                 :          0 :     setHistory (true);
     132                 :          0 :     initHistory (l / C0);
     133 [ #  # ][ #  # ]:          0 :     setB (NODE_1, VSRC_1, +1); setB (NODE_2, VSRC_2, +1);
     134 [ #  # ][ #  # ]:          0 :     setB (NODE_4, VSRC_1, -1); setB (NODE_3, VSRC_2, -1);
     135 [ #  # ][ #  # ]:          0 :     setC (VSRC_1, NODE_1, +1); setC (VSRC_2, NODE_2, +1);
     136 [ #  # ][ #  # ]:          0 :     setC (VSRC_1, NODE_4, -1); setC (VSRC_2, NODE_3, -1);
     137 [ #  # ][ #  # ]:          0 :     setD (VSRC_1, VSRC_1, -z); setD (VSRC_2, VSRC_2, -z);
     138                 :            :   } else {
     139                 :          0 :     setVoltageSources (2);
     140                 :          0 :     allocMatrixMNA ();
     141                 :          0 :     voltageSource (VSRC_1, NODE_1, NODE_2);
     142                 :          0 :     voltageSource (VSRC_2, NODE_3, NODE_4);
     143                 :            :   }
     144                 :          0 : }
     145                 :            : 
     146                 :          0 : void tline4p::calcTR (nr_double_t t) {
     147                 :          0 :   nr_double_t l = getPropertyDouble ("L");
     148                 :          0 :   nr_double_t a = getPropertyDouble ("Alpha");
     149                 :          0 :   nr_double_t z = getPropertyDouble ("Z");
     150                 :          0 :   nr_double_t T = l / C0;
     151                 :          0 :   a = std::log (a) / 2;
     152         [ #  # ]:          0 :   if (T > 0.0) {
     153                 :          0 :     T = t - T;
     154                 :          0 :     a = std::exp (-a / 2 * l);
     155                 :          0 :     setE (VSRC_1, a * (getV (NODE_2, T) - getV (NODE_3, T) +
     156         [ #  # ]:          0 :                        z * getJ (VSRC_2, T)));
     157                 :          0 :     setE (VSRC_2, a * (getV (NODE_1, T) - getV (NODE_4, T) +
     158         [ #  # ]:          0 :                        z * getJ (VSRC_1, T)));
     159                 :            :   }
     160                 :          0 : }
     161                 :            : 
     162                 :            : // properties
     163                 :            : PROP_REQ [] = {
     164                 :            :   { "Z", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
     165                 :            :   { "L", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_NO_RANGE },
     166                 :            :   PROP_NO_PROP };
     167                 :            : PROP_OPT [] = {
     168                 :            :   { "Alpha", PROP_REAL, { 1, PROP_NO_STR }, PROP_POS_RANGEX },
     169                 :            :   { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
     170                 :            :   PROP_NO_PROP };
     171                 :            : struct define_t tline4p::cirdef =
     172                 :            :   { "TLIN4P", 4, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };

Generated by: LCOV version 1.11