LCOV - code coverage report
Current view: top level - src/components/microstrip - msstep.cpp (source / functions) Hit Total Coverage
Test: qucs-core-0.0.19 Code Coverage Lines: 40 57 70.2 %
Date: 2015-01-05 16:01:02 Functions: 3 8 37.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 24 54 44.4 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * msstep.cpp - microstrip impedance step class implementation
       3                 :            :  *
       4                 :            :  * Copyright (C) 2004, 2007, 2008 Stefan Jahn <stefan@lkcc.org>
       5                 :            :  * Copyright (C) 2004 Michael Margraf <Michael.Margraf@alumni.TU-Berlin.DE>
       6                 :            :  *
       7                 :            :  * This is free software; you can redistribute it and/or modify
       8                 :            :  * it under the terms of the GNU General Public License as published by
       9                 :            :  * the Free Software Foundation; either version 2, or (at your option)
      10                 :            :  * any later version.
      11                 :            :  *
      12                 :            :  * This software is distributed in the hope that it will be useful,
      13                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :            :  * GNU General Public License for more details.
      16                 :            :  *
      17                 :            :  * You should have received a copy of the GNU General Public License
      18                 :            :  * along with this package; see the file COPYING.  If not, write to
      19                 :            :  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
      20                 :            :  * Boston, MA 02110-1301, USA.
      21                 :            :  *
      22                 :            :  * $Id$
      23                 :            :  *
      24                 :            :  */
      25                 :            : 
      26                 :            : #if HAVE_CONFIG_H
      27                 :            : # include <config.h>
      28                 :            : #endif
      29                 :            : 
      30                 :            : #include "component.h"
      31                 :            : #include "substrate.h"
      32                 :            : #include "msline.h"
      33                 :            : #include "msstep.h"
      34                 :            : 
      35                 :            : using namespace qucs;
      36                 :            : 
      37                 :          4 : msstep::msstep () : circuit (2) {
      38                 :          4 :   type = CIR_MSSTEP;
      39                 :          4 : }
      40                 :            : 
      41                 :        600 : void msstep::calcSP (nr_double_t frequency) {
      42 [ +  - ][ +  - ]:        600 :   setMatrixS (ztos (calcMatrixZ (frequency)));
         [ +  - ][ +  - ]
                 [ +  - ]
      43                 :        600 : }
      44                 :            : 
      45                 :        600 : matrix msstep::calcMatrixZ (nr_double_t frequency) {
      46                 :            : 
      47                 :            :   /* how to get properties of this component, e.g. W */
      48         [ +  - ]:        600 :   nr_double_t W1 = getPropertyDouble ("W1");
      49         [ +  - ]:        600 :   nr_double_t W2 = getPropertyDouble ("W2");
      50         [ +  - ]:        600 :   const char * SModel = getPropertyString ("MSModel");
      51         [ +  - ]:        600 :   const char * DModel = getPropertyString ("MSDispModel");
      52                 :            : 
      53                 :            :   /* how to get properties of the substrate, e.g. Er, H */
      54         [ +  - ]:        600 :   substrate * subst = getSubstrate ();
      55         [ +  - ]:        600 :   nr_double_t er    = subst->getPropertyDouble ("er");
      56         [ +  - ]:        600 :   nr_double_t h     = subst->getPropertyDouble ("h");
      57         [ +  - ]:        600 :   nr_double_t t     = subst->getPropertyDouble ("t");
      58                 :            : 
      59                 :            :   // compute parallel capacitance
      60                 :        600 :   nr_double_t t1 = std::log10 (er);
      61                 :        600 :   nr_double_t t2 = W1 / W2;
      62                 :        600 :   nr_double_t Cs = std::sqrt (W1 * W2) *
      63                 :        600 :     (t2 * (10.1 * t1 + 2.33) - 12.6 * t1 - 3.17);
      64                 :            : 
      65                 :            :   // compute series inductance
      66                 :        600 :   t1 = std::log10 (t2);
      67                 :        600 :   t2 = t2 - 1;
      68                 :        600 :   nr_double_t Ls = h * (t2 * (40.5 + 0.2 * t2) - 75 * t1);
      69                 :            : 
      70                 :            :   nr_double_t ZlEff, ErEff, WEff, ZlEffFreq, ErEffFreq;
      71         [ +  - ]:        600 :   msline::analyseQuasiStatic (W1, h, t, er, SModel, ZlEff, ErEff, WEff);
      72                 :            :   msline::analyseDispersion  (W1, h, er, ZlEff, ErEff, frequency, DModel,
      73         [ +  - ]:        600 :                               ZlEffFreq, ErEffFreq);
      74                 :        600 :   nr_double_t L1 = ZlEffFreq * std::sqrt (ErEffFreq) / C0;
      75                 :            : 
      76         [ +  - ]:        600 :   msline::analyseQuasiStatic (W2, h, t, er, SModel, ZlEff, ErEff, WEff);
      77                 :            :   msline::analyseDispersion  (W2, h, er, ZlEff, ErEff, frequency, DModel,
      78         [ +  - ]:        600 :                               ZlEffFreq, ErEffFreq);
      79                 :        600 :   nr_double_t L2 = ZlEffFreq * std::sqrt (ErEffFreq) / C0;
      80                 :            : 
      81                 :        600 :   Ls /= (L1 + L2);
      82                 :        600 :   L1 *= Ls;
      83                 :        600 :   L2 *= Ls;
      84                 :            : 
      85                 :            :   // build Z-parameter matrix
      86                 :        600 :   nr_complex_t z21 = nr_complex_t (0.0, -0.5e12 / (M_PI * frequency * Cs));
      87         [ +  - ]:        600 :   nr_complex_t z11 = nr_complex_t (0.0, 2e-9 * M_PI * frequency * L1) + z21;
      88         [ +  - ]:        600 :   nr_complex_t z22 = nr_complex_t (0.0, 2e-9 * M_PI * frequency * L2) + z21;
      89         [ +  - ]:        600 :   matrix z (2);
      90         [ +  - ]:        600 :   z.set (0, 0, z11);
      91         [ +  - ]:        600 :   z.set (0, 1, z21);
      92         [ +  - ]:        600 :   z.set (1, 0, z21);
      93         [ +  - ]:        600 :   z.set (1, 1, z22);
      94                 :        600 :   return z;
      95                 :            : }
      96                 :            : 
      97                 :          0 : void msstep::initDC (void) {
      98                 :            :   // a DC short (voltage source V = 0 volts)
      99                 :          0 :   setVoltageSources (1);
     100                 :          0 :   setInternalVoltageSource (1);
     101                 :          0 :   allocMatrixMNA ();
     102                 :          0 :   clearY ();
     103                 :          0 :   voltageSource (VSRC_1, NODE_1, NODE_2);
     104                 :          0 : }
     105                 :            : 
     106                 :          0 : void msstep::initAC (void) {
     107                 :          0 :   setVoltageSources (0);
     108                 :          0 :   allocMatrixMNA ();
     109                 :          0 : }
     110                 :            : 
     111                 :          0 : void msstep::calcAC (nr_double_t frequency) {
     112 [ #  # ][ #  # ]:          0 :   setMatrixY (ztoy (calcMatrixZ (frequency)));
                 [ #  # ]
     113                 :          0 : }
     114                 :            : 
     115                 :          0 : void msstep::initTR (void) {
     116                 :          0 :   initDC ();
     117                 :          0 : }
     118                 :            : 
     119                 :            : // properties
     120                 :            : PROP_REQ [] = {
     121                 :            :   { "W1", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_POS_RANGE },
     122                 :            :   { "W2", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_POS_RANGE },
     123                 :            :   { "Subst", PROP_STR, { PROP_NO_VAL, "Subst1" }, PROP_NO_RANGE },
     124                 :            :   { "MSDispModel", PROP_STR, { PROP_NO_VAL, "Kirschning" }, PROP_RNG_DIS },
     125                 :            :   { "MSModel", PROP_STR, { PROP_NO_VAL, "Hammerstad" }, PROP_RNG_MOD },
     126                 :            :   PROP_NO_PROP };
     127                 :            : PROP_OPT [] = {
     128                 :            :   PROP_NO_PROP };
     129                 :            : struct define_t msstep::cirdef =
     130                 :            :   { "MSTEP", 2, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };

Generated by: LCOV version 1.11