LCOV - code coverage report
Current view: top level - src/components - ccvs.cpp (source / functions) Hit Total Coverage
Test: qucs-core-0.0.19 Code Coverage Lines: 38 63 60.3 %
Date: 2015-01-05 16:01:02 Functions: 6 8 75.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 29 120 24.2 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * ccvs.cpp - ccvs class implementation
       3                 :            :  *
       4                 :            :  * Copyright (C) 2003, 2004, 2005, 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 "ccvs.h"
      31                 :            : 
      32                 :            : using namespace qucs;
      33                 :            : 
      34                 :          9 : ccvs::ccvs () : circuit (4) {
      35                 :          9 :   type = CIR_CCVS;
      36   [ +  -  #  # ]:          9 :   setVoltageSources (2);
      37                 :          9 : }
      38                 :            : 
      39                 :          0 : void ccvs::calcSP (nr_double_t frequency) {
      40                 :            : 
      41         [ #  # ]:          0 :   nr_double_t g = getPropertyDouble ("G") / z0;
      42         [ #  # ]:          0 :   nr_double_t t = getPropertyDouble ("T");
      43                 :            : 
      44         [ #  # ]:          0 :   nr_complex_t z1 = qucs::polar (g / 2.0, M_PI - 2.0 * M_PI * frequency * t);
      45         [ #  # ]:          0 :   nr_complex_t z2 = qucs::polar (g / 2.0, - 2.0 * M_PI * frequency * t);
      46                 :            : 
      47 [ #  # ][ #  # ]:          0 :   setS (NODE_1, NODE_1, 0.0); setS (NODE_1, NODE_2, 0.0);
      48 [ #  # ][ #  # ]:          0 :   setS (NODE_1, NODE_3, 0.0); setS (NODE_1, NODE_4, 1.0);
      49 [ #  # ][ #  # ]:          0 :   setS (NODE_2, NODE_1, z2);  setS (NODE_2, NODE_2, 0.0);
      50 [ #  # ][ #  # ]:          0 :   setS (NODE_2, NODE_3, 1.0); setS (NODE_2, NODE_4, z1);
      51 [ #  # ][ #  # ]:          0 :   setS (NODE_3, NODE_1, z1);  setS (NODE_3, NODE_2, 1.0);
      52 [ #  # ][ #  # ]:          0 :   setS (NODE_3, NODE_3, 0.0); setS (NODE_3, NODE_4, z2);
      53 [ #  # ][ #  # ]:          0 :   setS (NODE_4, NODE_1, 1.0); setS (NODE_4, NODE_2, 0.0);
      54 [ #  # ][ #  # ]:          0 :   setS (NODE_4, NODE_3, 0.0); setS (NODE_4, NODE_4, 0.0);
      55                 :          0 : }
      56                 :            : 
      57                 :        120 : void ccvs::initDC (void) {
      58                 :        120 :   allocMatrixMNA ();
      59 [ +  - ][ +  - ]:        120 :   setB (NODE_1, VSRC_1, +1.0); setB (NODE_2, VSRC_1, +0.0);
      60 [ +  - ][ +  - ]:        120 :   setB (NODE_3, VSRC_1, +0.0); setB (NODE_4, VSRC_1, -1.0);
      61 [ +  - ][ +  - ]:        120 :   setB (NODE_1, VSRC_2, +0.0); setB (NODE_2, VSRC_2, -1.0);
      62 [ +  - ][ +  - ]:        120 :   setB (NODE_3, VSRC_2, +1.0); setB (NODE_4, VSRC_2, +0.0);
      63 [ +  - ][ +  - ]:        120 :   setC (VSRC_1, NODE_1, +0.0); setC (VSRC_1, NODE_2, +1.0);
      64 [ +  - ][ +  - ]:        120 :   setC (VSRC_1, NODE_3, -1.0); setC (VSRC_1, NODE_4, +0.0);
      65 [ +  - ][ +  - ]:        120 :   setC (VSRC_2, NODE_1, +1.0); setC (VSRC_2, NODE_2, +0.0);
      66 [ +  - ][ +  - ]:        120 :   setC (VSRC_2, NODE_3, +0.0); setC (VSRC_2, NODE_4, -1.0);
      67         [ +  - ]:        120 :   setD (VSRC_1, VSRC_1, - getPropertyDouble ("G"));
      68         [ +  - ]:        120 :   setD (VSRC_2, VSRC_2, 0.0);
      69 [ +  - ][ +  - ]:        120 :   setD (VSRC_1, VSRC_2, 0.0); setD (VSRC_2, VSRC_1, 0.0);
      70         [ +  - ]:        120 :   setE (VSRC_1, 0.0);
      71         [ +  - ]:        120 :   setE (VSRC_2, 0.0);
      72                 :        120 : }
      73                 :            : 
      74                 :         30 : void ccvs::initAC (void) {
      75                 :         30 :   initDC ();
      76                 :         30 : }
      77                 :            : 
      78                 :       2730 : void ccvs::calcAC (nr_double_t frequency) {
      79         [ +  - ]:       2730 :   nr_double_t t = getPropertyDouble ("T");
      80                 :            :   nr_complex_t g = qucs::polar (getPropertyDouble ("G"),
      81 [ +  - ][ +  - ]:       2730 :                           - 2.0 * M_PI * frequency * t);
      82         [ +  - ]:       2730 :   setD (VSRC_1, VSRC_1, -g);
      83                 :       2730 : }
      84                 :            : 
      85                 :         30 : void ccvs::initTR (void) {
      86                 :         30 :   nr_double_t t = getPropertyDouble ("T");
      87                 :         30 :   initDC ();
      88                 :         30 :   deleteHistory ();
      89         [ -  + ]:         30 :   if (t > 0.0) {
      90                 :          0 :     setHistory (true);
      91                 :          0 :     initHistory (t);
      92 [ #  # ][ #  # ]:          0 :     setC (VSRC_2, NODE_1, +0.0); setC (VSRC_2, NODE_2, +1.0);
      93 [ #  # ][ #  # ]:          0 :     setC (VSRC_2, NODE_3, -1.0); setC (VSRC_2, NODE_4, +0.0);
      94 [ #  # ][ #  # ]:          0 :     setC (VSRC_1, NODE_1, +1.0); setC (VSRC_1, NODE_2, +0.0);
      95 [ #  # ][ #  # ]:          0 :     setC (VSRC_1, NODE_3, +0.0); setC (VSRC_1, NODE_4, -1.0);
      96         [ #  # ]:          0 :     setD (VSRC_1, VSRC_1, 0.0);
      97                 :            :   }
      98                 :         30 : }
      99                 :            : 
     100                 :     192192 : void ccvs::calcTR (nr_double_t t) {
     101                 :     192192 :   nr_double_t T = getPropertyDouble ("T");
     102         [ -  + ]:     192192 :   if (T > 0.0) {
     103                 :          0 :     T = t - T;
     104                 :          0 :     nr_double_t g = getPropertyDouble ("G");
     105                 :          0 :     nr_double_t i = getJ (VSRC_1, T);
     106         [ #  # ]:          0 :     setE (VSRC_2, g * i);
     107                 :            :   }
     108                 :     192192 : }
     109                 :            : 
     110                 :            : // properties
     111                 :            : PROP_REQ [] = {
     112                 :            :   { "G", PROP_REAL, { 1, PROP_NO_STR }, PROP_NO_RANGE }, PROP_NO_PROP };
     113                 :            : PROP_OPT [] = {
     114                 :            :   { "T", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE }, PROP_NO_PROP };
     115                 :            : struct define_t ccvs::cirdef =
     116                 :            :   { "CCVS", 4, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };

Generated by: LCOV version 1.11