Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vrect.cpp
Go to the documentation of this file.
1 /*
2  * vrect.cpp - rectangular pulse voltage 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 "vrect.h"
31 
32 using namespace qucs;
33 
34 vrect::vrect () : circuit (2) {
35  type = CIR_VRECT;
36  setVSource (true);
38 }
39 
40 void vrect::initSP (void) {
41  allocMatrixS ();
42  setS (NODE_1, NODE_1, 0.0);
43  setS (NODE_1, NODE_2, 1.0);
44  setS (NODE_2, NODE_1, 1.0);
45  setS (NODE_2, NODE_2, 0.0);
46 }
47 
48 void vrect::initDC (void) {
49  nr_double_t th = getPropertyDouble ("TH");
50  nr_double_t tl = getPropertyDouble ("TL");
51  nr_double_t tr = getPropertyDouble ("Tr");
52  nr_double_t tf = getPropertyDouble ("Tf");
53  if (tr > th) tr = th;
54  if (tf > tl) tf = tl;
55  nr_double_t a = (th + (tf - tr) / 2) / (th + tl);
56  nr_double_t u = getPropertyDouble ("U") * a;
57  allocMatrixMNA ();
59 }
60 
61 void vrect::initAC (void) {
62  initDC ();
63  setE (VSRC_1, 0);
64 }
65 
66 void vrect::initTR (void) {
67  initDC ();
68 }
69 
70 void vrect::calcTR (nr_double_t t) {
71  nr_double_t u = getPropertyDouble ("U");
72  nr_double_t th = getPropertyDouble ("TH");
73  nr_double_t tl = getPropertyDouble ("TL");
74  nr_double_t tr = getPropertyDouble ("Tr");
75  nr_double_t tf = getPropertyDouble ("Tf");
76  nr_double_t td = getPropertyDouble ("Td");
77  nr_double_t ut = 0;
78  nr_double_t s = getNet()->getSrcFactor ();
79 
80  if (tr > th) tr = th;
81  if (tf > tl) tf = tl;
82 
83  if (t > td) { // after delay
84  t = t - td;
85  t = t - (th + tl) * qucs::floor (t / (th + tl));
86  if (t < tr) { // rising edge
87  ut = + u / tr * t;
88  }
89  else if (t < th) { // high pulse
90  ut = u;
91  }
92  else if (t < th + tf) { // falling edge
93  ut = - u / tf * (t - (th + tf));
94  }
95  }
96  setE (VSRC_1, ut * s);
97 }
98 
99 // properties
100 PROP_REQ [] = {
101  { "U", PROP_REAL, { 1, PROP_NO_STR }, PROP_NO_RANGE },
102  { "TH", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_POS_RANGE },
103  { "TL", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_POS_RANGE },
104  PROP_NO_PROP };
105 PROP_OPT [] = {
106  { "Tr", PROP_REAL, { 1e-9, PROP_NO_STR }, PROP_POS_RANGE },
107  { "Tf", PROP_REAL, { 1e-9, PROP_NO_STR }, PROP_POS_RANGE },
108  { "Td", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE },
109  PROP_NO_PROP };
110 struct define_t vrect::cirdef =
#define PROP_POS_RANGE
Definition: netdefs.h:129
#define NODE_2
Definition: circuit.h:35
void initTR(void)
Definition: vrect.cpp:66
nr_double_t getSrcFactor(void)
Definition: net.h:87
#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
Definition: vrect.cpp:110
#define PROP_NO_PROP
Definition: netdefs.h:122
void setVoltageSources(int)
Definition: circuit.cpp:607
#define PROP_NO_RANGE
Definition: netdefs.h:126
PROP_OPT[]
Definition: vrect.cpp:105
#define PROP_NO_STR
Definition: netdefs.h:125
void allocMatrixS(void)
Definition: circuit.cpp:251
#define PROP_LINEAR
Definition: netdefs.h:120
PROP_REQ[]
Definition: vrect.cpp:100
#define VSRC_1
Definition: circuit.h:40
#define PROP_COMPONENT
Definition: netdefs.h:116
net * getNet(void)
Definition: circuit.h:173
void setE(int, nr_complex_t)
Definition: circuit.cpp:385
void initAC(void)
Definition: vrect.cpp:61
void setVSource(bool v)
Definition: circuit.h:192
nr_complex_t floor(const nr_complex_t z)
Complex floor.
Definition: complex.cpp:623
void initDC(void)
Definition: vrect.cpp:48
void allocMatrixMNA(void)
Definition: circuit.cpp:267
#define NODE_1
Definition: circuit.h:34
void voltageSource(int, int, int, nr_double_t value=0.0)
Definition: circuit.cpp:748
void setS(int, int, nr_complex_t)
Definition: circuit.cpp:587
void calcTR(nr_double_t)
Definition: vrect.cpp:70
void initSP(void)
placehoder for S-Parameter initialisation function
Definition: vrect.cpp:40
#define PROP_NO_SUBSTRATE
Definition: netdefs.h:118