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

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * vexp.cpp - exponential voltage source class implementation
       3                 :            :  *
       4                 :            :  * Copyright (C) 2007, 2008 Stefan Jahn <stefan@lkcc.org>
       5                 :            :  * Copyright (C) 2007 Gunther Kraut <gn.kraut@t-online.de>
       6                 :            :  *
       7                 :            :  * This is free software; you can redistribute it and/or modify
       8                 :            :  * it under the terms of the GNU General Public License as published by
       9                 :            :  * the Free Software Foundation; either version 2, or (at your option)
      10                 :            :  * any later version.
      11                 :            :  *
      12                 :            :  * This software is distributed in the hope that it will be useful,
      13                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :            :  * GNU General Public License for more details.
      16                 :            :  *
      17                 :            :  * You should have received a copy of the GNU General Public License
      18                 :            :  * along with this package; see the file COPYING.  If not, write to
      19                 :            :  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
      20                 :            :  * Boston, MA 02110-1301, USA.
      21                 :            :  *
      22                 :            :  * $Id$
      23                 :            :  *
      24                 :            :  */
      25                 :            : 
      26                 :            : #if HAVE_CONFIG_H
      27                 :            : # include <config.h>
      28                 :            : #endif
      29                 :            : 
      30                 :            : #include "component.h"
      31                 :            : #include "vexp.h"
      32                 :            : 
      33                 :            : using namespace qucs;
      34                 :            : 
      35                 :          0 : vexp::vexp () : circuit (2) {
      36                 :          0 :   type = CIR_VEXP;
      37                 :          0 :   setVSource (true);
      38   [ #  #  #  # ]:          0 :   setVoltageSources (1);
      39                 :          0 : }
      40                 :            : 
      41                 :          0 : void vexp::initSP (void) {
      42                 :          0 :   allocMatrixS ();
      43         [ #  # ]:          0 :   setS (NODE_1, NODE_1, 0.0);
      44         [ #  # ]:          0 :   setS (NODE_1, NODE_2, 1.0);
      45         [ #  # ]:          0 :   setS (NODE_2, NODE_1, 1.0);
      46         [ #  # ]:          0 :   setS (NODE_2, NODE_2, 0.0);
      47                 :          0 : }
      48                 :            : 
      49                 :          0 : void vexp::initDC (void) {
      50                 :          0 :   allocMatrixMNA ();
      51                 :          0 :   voltageSource (VSRC_1, NODE_1, NODE_2);
      52         [ #  # ]:          0 :   setE (VSRC_1, getPropertyDouble ("U1"));
      53                 :          0 : }
      54                 :            : 
      55                 :          0 : void vexp::initAC (void) {
      56                 :          0 :   initDC ();
      57         [ #  # ]:          0 :   setE (VSRC_1, 0);
      58                 :          0 : }
      59                 :            : 
      60                 :          0 : void vexp::initTR (void) {
      61                 :          0 :   initDC ();
      62                 :          0 : }
      63                 :            : 
      64                 :          0 : void vexp::calcTR (nr_double_t t) {
      65                 :          0 :   nr_double_t u1 = getPropertyDouble ("U1");
      66                 :          0 :   nr_double_t u2 = getPropertyDouble ("U2");
      67                 :          0 :   nr_double_t t1 = getPropertyDouble ("T1");
      68                 :          0 :   nr_double_t t2 = getPropertyDouble ("T2");
      69                 :          0 :   nr_double_t tr = getPropertyDouble ("Tr");
      70                 :          0 :   nr_double_t tf = getPropertyDouble ("Tf");
      71                 :          0 :   nr_double_t ut = 0;
      72                 :          0 :   nr_double_t s  = getNet()->getSrcFactor ();
      73                 :            : 
      74         [ #  # ]:          0 :   if (t <= t1) { // before pulse
      75                 :          0 :     ut = u1;
      76                 :            :   }
      77 [ #  # ][ #  # ]:          0 :   else if (t > t1 && t <= t2) { // rising edge
      78                 :          0 :     ut = u1 + (u2 - u1) * (1 - std::exp (-(t - t1) / tr));
      79                 :            :   }
      80                 :            :   else { // falling edge
      81                 :          0 :     ut += u1;
      82                 :          0 :     ut += (u2 - u1) * (1 - std::exp (-(t - t1) / tr));
      83                 :          0 :     ut -= (u2 - u1) * (1 - std::exp (-(t - t2) / tf));
      84                 :            :   }
      85         [ #  # ]:          0 :   setE (VSRC_1, ut * s);
      86                 :          0 : }
      87                 :            : 
      88                 :            : // properties
      89                 :            : PROP_REQ [] = {
      90                 :            :   { "U1", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE },
      91                 :            :   { "U2", PROP_REAL, { 1, PROP_NO_STR }, PROP_NO_RANGE },
      92                 :            :   { "T1", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE },
      93                 :            :   { "T2", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_POS_RANGE },
      94                 :            :   PROP_NO_PROP };
      95                 :            : PROP_OPT [] = {
      96                 :            :   { "Tr", PROP_REAL, { 1e-9, PROP_NO_STR }, PROP_POS_RANGE },
      97                 :            :   { "Tf", PROP_REAL, { 1e-9, PROP_NO_STR }, PROP_POS_RANGE },
      98                 :            :   PROP_NO_PROP };
      99                 :            : struct define_t vexp::cirdef =
     100                 :            :   { "Vexp", 2, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };

Generated by: LCOV version 1.11