My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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: vrect.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 "vrect.h"
31 
32 vrect::vrect () : circuit (2) {
33  type = CIR_VRECT;
34  setVSource (true);
35  setVoltageSources (1);
36 }
37 
38 void vrect::initSP (void) {
39  allocMatrixS ();
40  setS (NODE_1, NODE_1, 0.0);
41  setS (NODE_1, NODE_2, 1.0);
42  setS (NODE_2, NODE_1, 1.0);
43  setS (NODE_2, NODE_2, 0.0);
44 }
45 
46 void vrect::initDC (void) {
47  nr_double_t th = getPropertyDouble ("TH");
48  nr_double_t tl = getPropertyDouble ("TL");
49  nr_double_t tr = getPropertyDouble ("Tr");
50  nr_double_t tf = getPropertyDouble ("Tf");
51  if (tr > th) tr = th;
52  if (tf > tl) tf = tl;
53  nr_double_t a = (th + (tf - tr) / 2) / (th + tl);
54  nr_double_t u = getPropertyDouble ("U") * a;
55  allocMatrixMNA ();
57 }
58 
59 void vrect::initAC (void) {
60  initDC ();
61  setE (VSRC_1, 0);
62 }
63 
64 void vrect::initTR (void) {
65  initDC ();
66 }
67 
68 void vrect::calcTR (nr_double_t t) {
69  nr_double_t u = getPropertyDouble ("U");
70  nr_double_t th = getPropertyDouble ("TH");
71  nr_double_t tl = getPropertyDouble ("TL");
72  nr_double_t tr = getPropertyDouble ("Tr");
73  nr_double_t tf = getPropertyDouble ("Tf");
74  nr_double_t td = getPropertyDouble ("Td");
75  nr_double_t ut = 0;
76  nr_double_t s = getNet()->getSrcFactor ();
77 
78  if (tr > th) tr = th;
79  if (tf > tl) tf = tl;
80 
81  if (t > td) { // after delay
82  t = t - td;
83  t = t - (th + tl) * floor (t / (th + tl));
84  if (t < tr) { // rising edge
85  ut = + u / tr * t;
86  }
87  else if (t < th) { // high pulse
88  ut = u;
89  }
90  else if (t < th + tf) { // falling edge
91  ut = - u / tf * (t - (th + tf));
92  }
93  }
94  setE (VSRC_1, ut * s);
95 }
96 
97 // properties
98 PROP_REQ [] = {
99  { "U", PROP_REAL, { 1, PROP_NO_STR }, PROP_NO_RANGE },
100  { "TH", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_POS_RANGE },
101  { "TL", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_POS_RANGE },
102  PROP_NO_PROP };
103 PROP_OPT [] = {
104  { "Tr", PROP_REAL, { 1e-9, PROP_NO_STR }, PROP_POS_RANGE },
105  { "Tf", PROP_REAL, { 1e-9, PROP_NO_STR }, PROP_POS_RANGE },
106  { "Td", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE },
107  PROP_NO_PROP };
108 struct define_t vrect::cirdef =