My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ipulse.cpp
Go to the documentation of this file.
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: ipulse.cpp 1825 2011-03-11 20:42:14Z ela $
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 ipulse::ipulse () : circuit (2) {
33  type = CIR_IPULSE;
34  setISource (true);
35 }
36 
37 void ipulse::initSP (void) {
38  allocMatrixS ();
39  setS (NODE_1, NODE_1, 1.0);
40  setS (NODE_1, NODE_2, 0.0);
41  setS (NODE_2, NODE_1, 0.0);
42  setS (NODE_2, NODE_2, 1.0);
43 }
44 
45 void ipulse::initDC (void) {
46  nr_double_t i = getPropertyDouble ("I1");
47  allocMatrixMNA ();
48  setI (NODE_1, +i); setI (NODE_2, -i);
49 }
50 
51 void ipulse::initAC (void) {
52  allocMatrixMNA ();
53  clearI ();
54 }
55 
56 void ipulse::initTR (void) {
57  initDC ();
58 }
59 
60 void ipulse::calcTR (nr_double_t t) {
61  nr_double_t i1 = getPropertyDouble ("I1");
62  nr_double_t i2 = getPropertyDouble ("I2");
63  nr_double_t t1 = getPropertyDouble ("T1");
64  nr_double_t t2 = getPropertyDouble ("T2");
65  nr_double_t tr = getPropertyDouble ("Tr");
66  nr_double_t tf = getPropertyDouble ("Tf");
67  nr_double_t it = 0;
68  nr_double_t s = getNet()->getSrcFactor ();
69 
70  if (t < t1) { // before pulse
71  it = i1;
72  }
73  else if (t >= t1 && t < t1 + tr) { // rising edge
74  it = i1 + (i2 - i1) / tr * (t - t1);
75  }
76  else if (t >= t1 + tr && t < t2 - tf) { // during full pulse
77  it = i2;
78  }
79  else if (t >= t2 - tf && t < t2) { // falling edge
80  it = i2 + (i1 - i2) / tf * (t - (t2 - tf));
81  }
82  else { // after pulse
83  it = i1;
84  }
85  setI (NODE_1, +it * s); setI (NODE_2, -it * s);
86 }
87 
88 // properties
89 PROP_REQ [] = {
90  { "I1", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE },
91  { "I2", 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 ipulse::cirdef =