LCOV - code coverage report
Current view: top level - src/components - vccs.cpp (source / functions) Hit Total Coverage
Test: qucs-core-0.0.19 Code Coverage Lines: 17 52 32.7 %
Date: 2015-01-05 16:01:02 Functions: 2 8 25.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 20 70 28.6 %

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

Generated by: LCOV version 1.11