LCOV - code coverage report
Current view: top level - src/components - tline.cpp (source / functions) Hit Total Coverage
Test: qucs-core-0.0.19 Code Coverage Lines: 16 111 14.4 %
Date: 2015-01-05 16:01:02 Functions: 2 10 20.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 12 98 12.2 %

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

Generated by: LCOV version 1.11