LCOV - code coverage report
Current view: top level - src/components - ipulse.cpp (source / functions) Hit Total Coverage
Test: qucs-core-0.0.19 Code Coverage Lines: 0 43 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 30 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * ipulse.cpp - pulse current source class implementation
       3                 :            :  *
       4                 :            :  * Copyright (C) 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 "ipulse.h"
      31                 :            : 
      32                 :            : using namespace qucs;
      33                 :            : 
      34                 :          0 : ipulse::ipulse () : circuit (2) {
      35                 :          0 :   type = CIR_IPULSE;
      36                 :          0 :   setISource (true);
      37                 :          0 : }
      38                 :            : 
      39                 :          0 : void ipulse::initSP (void) {
      40                 :          0 :   allocMatrixS ();
      41         [ #  # ]:          0 :   setS (NODE_1, NODE_1, 1.0);
      42         [ #  # ]:          0 :   setS (NODE_1, NODE_2, 0.0);
      43         [ #  # ]:          0 :   setS (NODE_2, NODE_1, 0.0);
      44         [ #  # ]:          0 :   setS (NODE_2, NODE_2, 1.0);
      45                 :          0 : }
      46                 :            : 
      47                 :          0 : void ipulse::initDC (void) {
      48                 :          0 :   nr_double_t i = getPropertyDouble ("I1");
      49                 :          0 :   allocMatrixMNA ();
      50 [ #  # ][ #  # ]:          0 :   setI (NODE_1, +i); setI (NODE_2, -i);
      51                 :          0 : }
      52                 :            : 
      53                 :          0 : void ipulse::initAC (void) {
      54                 :          0 :   allocMatrixMNA ();
      55                 :          0 :   clearI ();
      56                 :          0 : }
      57                 :            : 
      58                 :          0 : void ipulse::initTR (void) {
      59                 :          0 :   initDC ();
      60                 :          0 : }
      61                 :            : 
      62                 :          0 : void ipulse::calcTR (nr_double_t t) {
      63                 :          0 :   nr_double_t i1 = getPropertyDouble ("I1");
      64                 :          0 :   nr_double_t i2 = getPropertyDouble ("I2");
      65                 :          0 :   nr_double_t t1 = getPropertyDouble ("T1");
      66                 :          0 :   nr_double_t t2 = getPropertyDouble ("T2");
      67                 :          0 :   nr_double_t tr = getPropertyDouble ("Tr");
      68                 :          0 :   nr_double_t tf = getPropertyDouble ("Tf");
      69                 :          0 :   nr_double_t it = 0;
      70                 :          0 :   nr_double_t s  = getNet()->getSrcFactor ();
      71                 :            : 
      72         [ #  # ]:          0 :   if (t < t1) { // before pulse
      73                 :          0 :     it = i1;
      74                 :            :   }
      75 [ #  # ][ #  # ]:          0 :   else if (t >= t1 && t < t1 + tr) { // rising edge
      76                 :          0 :     it = i1 + (i2 - i1) / tr * (t - t1);
      77                 :            :   }
      78 [ #  # ][ #  # ]:          0 :   else if (t >= t1 + tr && t < t2 - tf) { // during full pulse
      79                 :          0 :     it = i2;
      80                 :            :   }
      81 [ #  # ][ #  # ]:          0 :   else if (t >= t2 - tf && t < t2) { // falling edge
      82                 :          0 :     it = i2 + (i1 - i2) / tf * (t - (t2 - tf));
      83                 :            :   }
      84                 :            :   else { // after pulse
      85                 :          0 :     it = i1;
      86                 :            :   }
      87 [ #  # ][ #  # ]:          0 :   setI (NODE_1, +it * s); setI (NODE_2, -it * s);
      88                 :          0 : }
      89                 :            : 
      90                 :            : // properties
      91                 :            : PROP_REQ [] = {
      92                 :            :   { "I1", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE },
      93                 :            :   { "I2", PROP_REAL, { 1, PROP_NO_STR }, PROP_NO_RANGE },
      94                 :            :   { "T1", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE },
      95                 :            :   { "T2", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_POS_RANGE },
      96                 :            :   PROP_NO_PROP };
      97                 :            : PROP_OPT [] = {
      98                 :            :   { "Tr", PROP_REAL, { 1e-9, PROP_NO_STR }, PROP_POS_RANGE },
      99                 :            :   { "Tf", PROP_REAL, { 1e-9, PROP_NO_STR }, PROP_POS_RANGE },
     100                 :            :   PROP_NO_PROP };
     101                 :            : struct define_t ipulse::cirdef =
     102                 :            :   { "Ipulse", 2, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };

Generated by: LCOV version 1.11