Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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$
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 ipulse::ipulse () : circuit (2) {
35  type = CIR_IPULSE;
36  setISource (true);
37 }
38 
39 void ipulse::initSP (void) {
40  allocMatrixS ();
41  setS (NODE_1, NODE_1, 1.0);
42  setS (NODE_1, NODE_2, 0.0);
43  setS (NODE_2, NODE_1, 0.0);
44  setS (NODE_2, NODE_2, 1.0);
45 }
46 
47 void ipulse::initDC (void) {
48  nr_double_t i = getPropertyDouble ("I1");
49  allocMatrixMNA ();
50  setI (NODE_1, +i); setI (NODE_2, -i);
51 }
52 
53 void ipulse::initAC (void) {
54  allocMatrixMNA ();
55  clearI ();
56 }
57 
58 void ipulse::initTR (void) {
59  initDC ();
60 }
61 
62 void ipulse::calcTR (nr_double_t t) {
63  nr_double_t i1 = getPropertyDouble ("I1");
64  nr_double_t i2 = getPropertyDouble ("I2");
65  nr_double_t t1 = getPropertyDouble ("T1");
66  nr_double_t t2 = getPropertyDouble ("T2");
67  nr_double_t tr = getPropertyDouble ("Tr");
68  nr_double_t tf = getPropertyDouble ("Tf");
69  nr_double_t it = 0;
70  nr_double_t s = getNet()->getSrcFactor ();
71 
72  if (t < t1) { // before pulse
73  it = i1;
74  }
75  else if (t >= t1 && t < t1 + tr) { // rising edge
76  it = i1 + (i2 - i1) / tr * (t - t1);
77  }
78  else if (t >= t1 + tr && t < t2 - tf) { // during full pulse
79  it = i2;
80  }
81  else if (t >= t2 - tf && t < t2) { // falling edge
82  it = i2 + (i1 - i2) / tf * (t - (t2 - tf));
83  }
84  else { // after pulse
85  it = i1;
86  }
87  setI (NODE_1, +it * s); setI (NODE_2, -it * s);
88 }
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 =
#define PROP_POS_RANGE
Definition: netdefs.h:129
#define NODE_2
Definition: circuit.h:35
nr_double_t getSrcFactor(void)
Definition: net.h:87
void initSP(void)
placehoder for S-Parameter initialisation function
Definition: ipulse.cpp:39
void setISource(bool i)
Definition: circuit.h:194
#define PROP_DEF
Definition: netdefs.h:189
nr_double_t getPropertyDouble(const char *)
Definition: object.cpp:176
#define PROP_REAL
Definition: netdefs.h:174
t
Definition: parse_vcd.y:290
void initTR(void)
Definition: ipulse.cpp:58
#define PROP_NO_PROP
Definition: netdefs.h:122
#define PROP_NO_RANGE
Definition: netdefs.h:126
#define PROP_NO_STR
Definition: netdefs.h:125
void allocMatrixS(void)
Definition: circuit.cpp:251
#define PROP_LINEAR
Definition: netdefs.h:120
i1
Definition: parse_citi.y:148
void clearI(void)
Definition: circuit.cpp:730
i
Definition: parse_mdl.y:516
PROP_OPT[]
Definition: ipulse.cpp:97
void initAC(void)
Definition: ipulse.cpp:53
void initDC(void)
Definition: ipulse.cpp:47
#define PROP_COMPONENT
Definition: netdefs.h:116
void calcTR(nr_double_t)
Definition: ipulse.cpp:62
net * getNet(void)
Definition: circuit.h:173
void setI(int, nr_complex_t)
Definition: circuit.cpp:397
PROP_REQ[]
Definition: ipulse.cpp:91
i2
Definition: parse_citi.y:160
void allocMatrixMNA(void)
Definition: circuit.cpp:267
PROP_NO_SUBSTRATE
Definition: ipulse.cpp:102
#define NODE_1
Definition: circuit.h:34
void setS(int, int, nr_complex_t)
Definition: circuit.cpp:587