LCOV - code coverage report
Current view: top level - src/components - vcvs.cpp (source / functions) Hit Total Coverage
Test: qucs-core-0.0.19 Code Coverage Lines: 22 53 41.5 %
Date: 2015-01-05 16:01:02 Functions: 4 8 50.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 16 84 19.0 %

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

Generated by: LCOV version 1.11