Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
iexp.cpp
Go to the documentation of this file.
1 /*
2  * iexp.cpp - exponential current 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 "iexp.h"
32 
33 using namespace qucs;
34 
35 iexp::iexp () : circuit (2) {
36  type = CIR_IEXP;
37  setISource (true);
38 }
39 
40 void iexp::initSP (void) {
41  allocMatrixS ();
42  setS (NODE_1, NODE_1, 1.0);
43  setS (NODE_1, NODE_2, 0.0);
44  setS (NODE_2, NODE_1, 0.0);
45  setS (NODE_2, NODE_2, 1.0);
46 }
47 
48 void iexp::initDC (void) {
49  nr_double_t i = getPropertyDouble ("I1");
50  allocMatrixMNA ();
51  setI (NODE_1, +i); setI (NODE_2, -i);
52 }
53 
54 void iexp::initAC (void) {
55  allocMatrixMNA ();
56  clearI ();
57 }
58 
59 void iexp::initTR (void) {
60  initDC ();
61 }
62 
63 void iexp::calcTR (nr_double_t t) {
64  nr_double_t i1 = getPropertyDouble ("I1");
65  nr_double_t i2 = getPropertyDouble ("I2");
66  nr_double_t t1 = getPropertyDouble ("T1");
67  nr_double_t t2 = getPropertyDouble ("T2");
68  nr_double_t tr = getPropertyDouble ("Tr");
69  nr_double_t tf = getPropertyDouble ("Tf");
70  nr_double_t it = 0;
71  nr_double_t s = getNet()->getSrcFactor ();
72 
73  if (t <= t1) { // before pulse
74  it = i1;
75  }
76  else if (t > t1 && t <= t2) { // rising edge
77  it = i1 + (i2 - i1) * (1 - std::exp (-(t - t1) / tr));
78  }
79  else { // falling edge
80  it += i1;
81  it += (i2 - i1) * (1 - std::exp (-(t - t1) / tr));
82  it -= (i2 - i1) * (1 - std::exp (-(t - t2) / tf));
83  }
84  setI (NODE_1, +it * s); setI (NODE_2, -it * s);
85 }
86 
87 // properties
88 PROP_REQ [] = {
89  { "I1", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE },
90  { "I2", PROP_REAL, { 1, PROP_NO_STR }, PROP_NO_RANGE },
91  { "T1", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE },
92  { "T2", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_POS_RANGE },
93  PROP_NO_PROP };
94 PROP_OPT [] = {
95  { "Tr", PROP_REAL, { 1e-9, PROP_NO_STR }, PROP_POS_RANGE },
96  { "Tf", PROP_REAL, { 1e-9, PROP_NO_STR }, PROP_POS_RANGE },
97  PROP_NO_PROP };
98 struct define_t iexp::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 setISource(bool i)
Definition: circuit.h:194
#define PROP_DEF
Definition: netdefs.h:189
PROP_NO_SUBSTRATE
Definition: iexp.cpp:99
nr_double_t getPropertyDouble(const char *)
Definition: object.cpp:176
#define PROP_REAL
Definition: netdefs.h:174
t
Definition: parse_vcd.y:290
#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
void initAC(void)
Definition: iexp.cpp:54
i1
Definition: parse_citi.y:148
void clearI(void)
Definition: circuit.cpp:730
i
Definition: parse_mdl.y:516
#define PROP_COMPONENT
Definition: netdefs.h:116
net * getNet(void)
Definition: circuit.h:173
Definition: iexp.cpp:98
void setI(int, nr_complex_t)
Definition: circuit.cpp:397
i2
Definition: parse_citi.y:160
void initDC(void)
Definition: iexp.cpp:48
void allocMatrixMNA(void)
Definition: circuit.cpp:267
void initSP(void)
placehoder for S-Parameter initialisation function
Definition: iexp.cpp:40
#define NODE_1
Definition: circuit.h:34
void calcTR(nr_double_t)
Definition: iexp.cpp:63
nr_complex_t exp(const nr_complex_t z)
Compute complex exponential.
Definition: complex.cpp:205
void initTR(void)
Definition: iexp.cpp:59
void setS(int, int, nr_complex_t)
Definition: circuit.cpp:587
PROP_REQ[]
Definition: iexp.cpp:88
PROP_OPT[]
Definition: iexp.cpp:94