Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
irect.cpp
Go to the documentation of this file.
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 irect::irect () : circuit (2) {
35  type = CIR_IRECT;
36  setISource (true);
37 }
38 
39 void irect::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 irect::initDC (void) {
48  nr_double_t th = getPropertyDouble ("TH");
49  nr_double_t tl = getPropertyDouble ("TL");
50  nr_double_t tr = getPropertyDouble ("Tr");
51  nr_double_t tf = getPropertyDouble ("Tf");
52  if (tr > th) tr = th;
53  if (tf > tl) tf = tl;
54  nr_double_t a = (th + (tf - tr) / 2) / (th + tl);
55  nr_double_t i = getPropertyDouble ("I") * a;
56  allocMatrixMNA ();
57  setI (NODE_1, +i); setI (NODE_2, -i);
58 }
59 
60 void irect::initAC (void) {
61  allocMatrixMNA ();
62  clearI ();
63 }
64 
65 void irect::initTR (void) {
66  initDC ();
67 }
68 
69 void irect::calcTR (nr_double_t t) {
70  nr_double_t i = getPropertyDouble ("I");
71  nr_double_t th = getPropertyDouble ("TH");
72  nr_double_t tl = getPropertyDouble ("TL");
73  nr_double_t tr = getPropertyDouble ("Tr");
74  nr_double_t tf = getPropertyDouble ("Tf");
75  nr_double_t td = getPropertyDouble ("Td");
76  nr_double_t it = 0;
77  nr_double_t s = getNet()->getSrcFactor ();
78 
79  if (tr > th) tr = th;
80  if (tf > tl) tf = tl;
81 
82  if (t > td) { // after delay
83  t = t - td;
84  t = t - (th + tl) * qucs::floor (t / (th + tl));
85  if (t < tr) { // rising edge
86  it = + i / tr * t;
87  }
88  else if (t < th) { // high pulse
89  it = i;
90  }
91  else if (t < th + tf) { // falling edge
92  it = - i / tf * (t - (th + tf));
93  }
94  }
95  setI (NODE_1, +it * s); setI (NODE_2, -it * s);
96 }
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 =
#define PROP_POS_RANGE
Definition: netdefs.h:129
Definition: irect.cpp:109
#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
void initAC(void)
Definition: irect.cpp:60
nr_double_t getPropertyDouble(const char *)
Definition: object.cpp:176
#define PROP_REAL
Definition: netdefs.h:174
t
Definition: parse_vcd.y:290
PROP_NO_SUBSTRATE
Definition: irect.cpp:110
#define PROP_NO_PROP
Definition: netdefs.h:122
PROP_REQ[]
Definition: irect.cpp:99
#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 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
void initSP(void)
placehoder for S-Parameter initialisation function
Definition: irect.cpp:39
nr_complex_t floor(const nr_complex_t z)
Complex floor.
Definition: complex.cpp:623
void setI(int, nr_complex_t)
Definition: circuit.cpp:397
void initTR(void)
Definition: irect.cpp:65
PROP_OPT[]
Definition: irect.cpp:104
void allocMatrixMNA(void)
Definition: circuit.cpp:267
#define NODE_1
Definition: circuit.h:34
void initDC(void)
Definition: irect.cpp:47
void setS(int, int, nr_complex_t)
Definition: circuit.cpp:587
void calcTR(nr_double_t)
Definition: irect.cpp:69