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

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * digisource.cpp - digital source class implementation
       3                 :            :  *
       4                 :            :  * Copyright (C) 2005, 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 "digisource.h"
      31                 :            : 
      32                 :            : using namespace qucs;
      33                 :            : 
      34                 :          0 : digisource::digisource () : circuit (1) {
      35                 :          0 :   type = CIR_DIGISOURCE;
      36                 :          0 :   setVSource (true);
      37   [ #  #  #  # ]:          0 :   setVoltageSources (1);
      38                 :          0 : }
      39                 :            : 
      40                 :          0 : void digisource::initSP (void) {
      41                 :          0 :   allocMatrixS ();
      42         [ #  # ]:          0 :   setS (NODE_1, NODE_1, -1.0);
      43                 :          0 : }
      44                 :            : 
      45                 :          0 : void digisource::initDC (void) {
      46                 :          0 :   const char * const init = getPropertyString ("init");
      47                 :          0 :   nr_double_t v = getPropertyDouble ("V");
      48                 :          0 :   bool lo = !strcmp (init, "low");
      49                 :          0 :   allocMatrixMNA ();
      50         [ #  # ]:          0 :   setC (VSRC_1, NODE_1, 1.0);
      51         [ #  # ]:          0 :   setB (NODE_1, VSRC_1, 1.0);
      52         [ #  # ]:          0 :   setD (VSRC_1, VSRC_1, 0.0);
      53 [ #  # ][ #  # ]:          0 :   setE (VSRC_1, lo ? 0 : v);
      54                 :          0 : }
      55                 :            : 
      56                 :          0 : void digisource::initAC (void) {
      57                 :          0 :   initDC ();
      58         [ #  # ]:          0 :   setE (VSRC_1, 0);
      59                 :          0 : }
      60                 :            : 
      61                 :          0 : void digisource::initTR (void) {
      62                 :          0 :   qucs::vector * values = getPropertyVector ("times");
      63         [ #  # ]:          0 :   T = real (sum (*values));
      64                 :          0 :   initDC ();
      65                 :          0 : }
      66                 :            : 
      67                 :          0 : void digisource::calcTR (nr_double_t t) {
      68                 :          0 :   const char * const init = getPropertyString ("init");
      69                 :          0 :   nr_double_t v = getPropertyDouble ("V");
      70                 :          0 :   qucs::vector * values = getPropertyVector ("times");
      71                 :          0 :   bool lo = !strcmp (init, "low");
      72                 :          0 :   nr_double_t ti = 0;
      73                 :            : 
      74                 :          0 :   t = t - T * qucs::floor (t / T);
      75         [ #  # ]:          0 :   for (int i = 0; i < values->getSize (); i++) {
      76                 :          0 :     ti += real (values->get (i));
      77         [ #  # ]:          0 :     if (t >= ti) lo = !lo; else break;
      78                 :            :   }
      79                 :            : 
      80 [ #  # ][ #  # ]:          0 :   setE (VSRC_1, lo ? 0 : v);
      81                 :          0 : }
      82                 :            : 
      83                 :            : // properties
      84                 :            : PROP_REQ [] = {
      85                 :            :   { "init", PROP_STR, { PROP_NO_VAL, "low" }, PROP_RNG_STR2 ("low", "high") },
      86                 :            :   { "times", PROP_LIST, { 1e-9, PROP_NO_STR }, PROP_POS_RANGE },
      87                 :            :   PROP_NO_PROP };
      88                 :            : PROP_OPT [] = {
      89                 :            :   { "V", PROP_REAL, { 1, PROP_NO_STR }, PROP_POS_RANGE }, PROP_NO_PROP };
      90                 :            : struct define_t digisource::cirdef =
      91                 :            :   { "DigiSource",
      92                 :            :     1, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };

Generated by: LCOV version 1.11