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

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * coaxline.cpp - coaxial cable class implementation
       3                 :            :  *
       4                 :            :  * Copyright (C) 2006, 2008, 2009, 2011 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 "coaxline.h"
      31                 :            : 
      32                 :            : using namespace qucs;
      33                 :            : 
      34                 :          0 : coaxline::coaxline () : circuit (2) {
      35                 :          0 :   alpha = beta = zl = fc = 0;
      36                 :          0 :   type = CIR_COAXLINE;
      37                 :          0 : }
      38                 :            : 
      39                 :          0 : void coaxline::calcPropagation (nr_double_t frequency) {
      40                 :          0 :   nr_double_t er   = getPropertyDouble ("er");
      41                 :          0 :   nr_double_t mur  = getPropertyDouble ("mur");
      42                 :          0 :   nr_double_t rho  = getPropertyDouble ("rho");
      43                 :          0 :   nr_double_t tand = getPropertyDouble ("tand");
      44                 :          0 :   nr_double_t d    = getPropertyDouble ("d");
      45                 :          0 :   nr_double_t D    = getPropertyDouble ("D");
      46                 :            :   nr_double_t ad, ac, rs;
      47                 :            : 
      48                 :            :   // check cutoff frequency
      49         [ #  # ]:          0 :   if (frequency > fc) {
      50                 :            :     logprint (LOG_ERROR, "WARNING: Operating frequency (%g) beyond "
      51                 :          0 :               "cutoff frequency (%g).\n", frequency, fc);
      52                 :            :   }
      53                 :            : 
      54                 :            :   // calculate losses
      55                 :          0 :   ad = M_PI / C0 * frequency * std::sqrt (er) * tand;
      56                 :          0 :   rs = std::sqrt (M_PI * frequency * mur * MU0 * rho);
      57                 :          0 :   ac = std::sqrt (er) * (1 / d + 1 / D) / std::log (D / d) * rs / Z0;
      58                 :            : 
      59                 :            :   // calculate propagation constants and reference impedance
      60                 :          0 :   alpha = ac + ad;
      61                 :          0 :   beta  = std::sqrt (er * mur) * 2 * M_PI * frequency / C0;
      62                 :          0 :   zl = Z0 / 2 / M_PI / std::sqrt (er) * std::log (D / d);
      63                 :          0 : }
      64                 :            : 
      65                 :          0 : void coaxline::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 coaxline::initCheck (void) {
      76                 :          0 :   nr_double_t d   = getPropertyDouble ("d");
      77                 :          0 :   nr_double_t D   = getPropertyDouble ("D");
      78                 :          0 :   nr_double_t er  = getPropertyDouble ("er");
      79                 :          0 :   nr_double_t mur = getPropertyDouble ("mur");
      80                 :            : 
      81                 :            :   // check validity
      82         [ #  # ]:          0 :   if (d >= D) {
      83                 :            :     logprint (LOG_ERROR,
      84                 :          0 :               "ERROR: Inner diameter larger than outer diameter.\n");
      85                 :            :   }
      86                 :            :   nr_double_t f1, f2, cl;
      87                 :          0 :   cl = C0 / std::sqrt (mur * er);
      88                 :          0 :   f1 = cl / (M_PI_2 * (D + d)); // TE_11
      89                 :          0 :   f2 = cl / (1 * (D - d));      // TM_N1
      90         [ #  # ]:          0 :   fc = MIN (f1, f2);
      91                 :          0 : }
      92                 :            : 
      93                 :          0 : void coaxline::saveCharacteristics (nr_double_t) {
      94                 :          0 :   setCharacteristic ("Zl", zl);
      95                 :          0 : }
      96                 :            : 
      97                 :          0 : void coaxline::initSP (void) {
      98                 :            :   // allocate S-parameter matrix
      99                 :          0 :   allocMatrixS ();
     100                 :          0 :   initCheck ();
     101                 :          0 : }
     102                 :            : 
     103                 :          0 : void coaxline::calcSP (nr_double_t frequency) {
     104         [ #  # ]:          0 :   nr_double_t l = getPropertyDouble ("L");
     105                 :            : 
     106                 :            :   // calculate propagation constants
     107         [ #  # ]:          0 :   calcPropagation (frequency);
     108                 :            : 
     109                 :            :   // calculate S-parameters
     110                 :          0 :   nr_double_t z = zl / z0;
     111                 :          0 :   nr_double_t y = 1 / z;
     112                 :          0 :   nr_complex_t g = nr_complex_t (alpha, beta);
     113 [ #  # ][ #  # ]:          0 :   nr_complex_t n = 2.0 * cosh (g * l) + (z + y) * sinh (g * l);
                 [ #  # ]
     114 [ #  # ][ #  # ]:          0 :   nr_complex_t s11 = (z - y) * sinh (g * l) / n;
     115         [ #  # ]:          0 :   nr_complex_t s21 = 2.0 / n;
     116 [ #  # ][ #  # ]:          0 :   setS (NODE_1, NODE_1, s11); setS (NODE_2, NODE_2, s11);
     117 [ #  # ][ #  # ]:          0 :   setS (NODE_1, NODE_2, s21); setS (NODE_2, NODE_1, s21);
     118                 :          0 : }
     119                 :            : 
     120                 :          0 : void coaxline::initDC (void) {
     121                 :          0 :   nr_double_t l   = getPropertyDouble ("L");
     122                 :          0 :   nr_double_t d   = getPropertyDouble ("d");
     123                 :          0 :   nr_double_t rho = getPropertyDouble ("rho");
     124                 :            : 
     125 [ #  # ][ #  # ]:          0 :   if (d != 0.0 && rho != 0.0 && l != 0.0) {
                 [ #  # ]
     126                 :            :     // a tiny resistance
     127                 :          0 :     nr_double_t g = M_PI * sqr (d / 2) / rho / l;
     128                 :          0 :     setVoltageSources (0);
     129                 :          0 :     allocMatrixMNA ();
     130 [ #  # ][ #  # ]:          0 :     setY (NODE_1, NODE_1, +g); setY (NODE_2, NODE_2, +g);
     131 [ #  # ][ #  # ]:          0 :     setY (NODE_1, NODE_2, -g); setY (NODE_2, NODE_1, -g);
     132                 :            :   }
     133                 :            :   else {
     134                 :            :     // a DC short
     135                 :          0 :     setVoltageSources (1);
     136                 :          0 :     setInternalVoltageSource (1);
     137                 :          0 :     allocMatrixMNA ();
     138                 :          0 :     voltageSource (VSRC_1, NODE_1, NODE_2);
     139                 :            :   }
     140                 :          0 : }
     141                 :            : 
     142                 :          0 : void coaxline::initAC (void) {
     143                 :          0 :   setVoltageSources (0);
     144                 :          0 :   allocMatrixMNA ();
     145                 :          0 :   initCheck ();
     146                 :          0 : }
     147                 :            : 
     148                 :          0 : void coaxline::calcAC (nr_double_t frequency) {
     149         [ #  # ]:          0 :   nr_double_t l = getPropertyDouble ("L");
     150                 :            : 
     151                 :            :   // calculate propagation constants
     152         [ #  # ]:          0 :   calcPropagation (frequency);
     153                 :            : 
     154                 :            :   // calculate Y-parameters
     155                 :          0 :   nr_complex_t g = nr_complex_t (alpha, beta);
     156         [ #  # ]:          0 :   nr_complex_t y11 = coth (g * l) / zl;
     157         [ #  # ]:          0 :   nr_complex_t y21 = -cosech (g * l) / zl;
     158 [ #  # ][ #  # ]:          0 :   setY (NODE_1, NODE_1, y11); setY (NODE_2, NODE_2, y11);
     159 [ #  # ][ #  # ]:          0 :   setY (NODE_1, NODE_2, y21); setY (NODE_2, NODE_1, y21);
     160                 :          0 : }
     161                 :            : 
     162                 :          0 : void coaxline::calcNoiseAC (nr_double_t) {
     163                 :          0 :   nr_double_t l = getPropertyDouble ("L");
     164         [ #  # ]:          0 :   if (l < 0) return;
     165                 :            :   // calculate noise using Bosma's theorem
     166                 :          0 :   nr_double_t T = getPropertyDouble ("Temp");
     167 [ #  # ][ #  # ]:          0 :   setMatrixN (4 * kelvin (T) / T0 * real (getMatrixY ()));
         [ #  # ][ #  # ]
                 [ #  # ]
     168                 :            : }
     169                 :            : 
     170                 :            : // properties
     171                 :            : PROP_REQ [] = {
     172                 :            :   { "D", PROP_REAL, { 2.95e-3, PROP_NO_STR }, PROP_POS_RANGEX },
     173                 :            :   { "d", PROP_REAL, { 0.9e-3, PROP_NO_STR }, PROP_POS_RANGEX },
     174                 :            :   { "L", PROP_REAL, { 1500e-3, PROP_NO_STR }, PROP_NO_RANGE },
     175                 :            :   { "er", PROP_REAL, { 2.29, PROP_NO_STR }, PROP_RNGII (1, 100) },
     176                 :            :   { "mur", PROP_REAL, { 1, PROP_NO_STR }, PROP_RNGII (1, 100) },
     177                 :            :   { "tand", PROP_REAL, { 4e-4, PROP_NO_STR }, PROP_POS_RANGE },
     178                 :            :   { "rho", PROP_REAL, { 0.022e-6, PROP_NO_STR }, PROP_POS_RANGE },
     179                 :            :   PROP_NO_PROP };
     180                 :            : PROP_OPT [] = {
     181                 :            :   { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
     182                 :            :   PROP_NO_PROP };
     183                 :            : struct define_t coaxline::cirdef =
     184                 :            :   { "COAX", 2, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };

Generated by: LCOV version 1.11