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

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * irect.cpp - rectangular 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 "irect.h"
      31                 :            : 
      32                 :            : using namespace qucs;
      33                 :            : 
      34                 :          0 : irect::irect () : circuit (2) {
      35                 :          0 :   type = CIR_IRECT;
      36                 :          0 :   setISource (true);
      37                 :          0 : }
      38                 :            : 
      39                 :          0 : void irect::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 irect::initDC (void) {
      48                 :          0 :   nr_double_t th = getPropertyDouble ("TH");
      49                 :          0 :   nr_double_t tl = getPropertyDouble ("TL");
      50                 :          0 :   nr_double_t tr = getPropertyDouble ("Tr");
      51                 :          0 :   nr_double_t tf = getPropertyDouble ("Tf");
      52         [ #  # ]:          0 :   if (tr > th) tr = th;
      53         [ #  # ]:          0 :   if (tf > tl) tf = tl;
      54                 :          0 :   nr_double_t a  = (th + (tf - tr) / 2) / (th + tl);
      55                 :          0 :   nr_double_t i  = getPropertyDouble ("I") * a;
      56                 :          0 :   allocMatrixMNA ();
      57 [ #  # ][ #  # ]:          0 :   setI (NODE_1, +i); setI (NODE_2, -i);
      58                 :          0 : }
      59                 :            : 
      60                 :          0 : void irect::initAC (void) {
      61                 :          0 :   allocMatrixMNA ();
      62                 :          0 :   clearI ();
      63                 :          0 : }
      64                 :            : 
      65                 :          0 : void irect::initTR (void) {
      66                 :          0 :   initDC ();
      67                 :          0 : }
      68                 :            : 
      69                 :          0 : void irect::calcTR (nr_double_t t) {
      70                 :          0 :   nr_double_t i  = getPropertyDouble ("I");
      71                 :          0 :   nr_double_t th = getPropertyDouble ("TH");
      72                 :          0 :   nr_double_t tl = getPropertyDouble ("TL");
      73                 :          0 :   nr_double_t tr = getPropertyDouble ("Tr");
      74                 :          0 :   nr_double_t tf = getPropertyDouble ("Tf");
      75                 :          0 :   nr_double_t td = getPropertyDouble ("Td");
      76                 :          0 :   nr_double_t it = 0;
      77                 :          0 :   nr_double_t s  = getNet()->getSrcFactor ();
      78                 :            : 
      79         [ #  # ]:          0 :   if (tr > th) tr = th;
      80         [ #  # ]:          0 :   if (tf > tl) tf = tl;
      81                 :            : 
      82         [ #  # ]:          0 :   if (t > td) { // after delay
      83                 :          0 :     t = t - td;
      84                 :          0 :     t = t - (th + tl) * qucs::floor (t / (th + tl));
      85         [ #  # ]:          0 :     if (t < tr) { // rising edge
      86                 :          0 :       it = + i / tr * t;
      87                 :            :     }
      88         [ #  # ]:          0 :     else if (t < th) { // high pulse
      89                 :          0 :       it = i;
      90                 :            :     }
      91         [ #  # ]:          0 :     else if (t < th + tf) { // falling edge
      92                 :          0 :       it = - i / tf * (t - (th + tf));
      93                 :            :     }
      94                 :            :   }
      95 [ #  # ][ #  # ]:          0 :   setI (NODE_1, +it * s); setI (NODE_2, -it * s);
      96                 :          0 : }
      97                 :            : 
      98                 :            : // properties
      99                 :            : PROP_REQ [] = {
     100                 :            :   { "I", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_NO_RANGE },
     101                 :            :   { "TH", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_POS_RANGE },
     102                 :            :   { "TL", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_POS_RANGE },
     103                 :            :   PROP_NO_PROP };
     104                 :            : PROP_OPT [] = {
     105                 :            :   { "Tr", PROP_REAL, { 1e-9, PROP_NO_STR }, PROP_POS_RANGE },
     106                 :            :   { "Tf", PROP_REAL, { 1e-9, PROP_NO_STR }, PROP_POS_RANGE },
     107                 :            :   { "Td", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE },
     108                 :            :   PROP_NO_PROP };
     109                 :            : struct define_t irect::cirdef =
     110                 :            :   { "Irect", 2, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };

Generated by: LCOV version 1.11