My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vccs.cpp
Go to the documentation of this file.
1 /*
2  * vccs.cpp - vccs class implementation
3  *
4  * Copyright (C) 2003, 2004, 2005, 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: vccs.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 "vccs.h"
31 
32 vccs::vccs () : circuit (4) {
33  type = CIR_VCCS;
34 }
35 
36 void vccs::calcSP (nr_double_t frequency) {
37  nr_double_t g = getPropertyDouble ("G") * z0;
38  nr_double_t t = getPropertyDouble ("T");
39 
40  nr_complex_t z1 = polar (2.0 * g, M_PI - 2.0 * M_PI * frequency * t);
41  nr_complex_t z2 = polar (2.0 * g, - 2.0 * M_PI * frequency * t);
42 
43  setS (NODE_1, NODE_1, 1.0); setS (NODE_1, NODE_2, 0.0);
44  setS (NODE_1, NODE_3, 0.0); setS (NODE_1, NODE_4, 0.0);
45  setS (NODE_2, NODE_1, z1); setS (NODE_2, NODE_2, 1.0);
46  setS (NODE_2, NODE_3, 0.0); setS (NODE_2, NODE_4, z2);
47  setS (NODE_3, NODE_1, z2); setS (NODE_3, NODE_2, 0.0);
48  setS (NODE_3, NODE_3, 1.0); setS (NODE_3, NODE_4, z1);
49  setS (NODE_4, NODE_1, 0.0); setS (NODE_4, NODE_2, 0.0);
50  setS (NODE_4, NODE_3, 0.0); setS (NODE_4, NODE_4, 1.0);
51 }
52 
53 void vccs::initDC (void) {
54  setISource (false);
55  allocMatrixMNA ();
56  nr_double_t g = getPropertyDouble ("G");
57  setY (NODE_2, NODE_1, +g); setY (NODE_3, NODE_4, +g);
58  setY (NODE_3, NODE_1, -g); setY (NODE_2, NODE_4, -g);
59 }
60 
61 void vccs::initAC (void) {
62  initDC ();
63 }
64 
65 void vccs::calcAC (nr_double_t frequency) {
66  nr_double_t t = getPropertyDouble ("T");
68  - 2.0 * M_PI * frequency * t);
69  setY (NODE_2, NODE_1, +g); setY (NODE_3, NODE_4, +g);
70  setY (NODE_3, NODE_1, -g); setY (NODE_2, NODE_4, -g);
71 }
72 
73 void vccs::initTR (void) {
74  nr_double_t t = getPropertyDouble ("T");
75  initDC ();
76  deleteHistory ();
77  if (t > 0.0) {
78  setISource (true);
79  setHistory (true);
80  initHistory (t);
81  clearY ();
82  }
83 }
84 
85 void vccs::calcTR (nr_double_t t) {
86  nr_double_t T = getPropertyDouble ("T");
87  if (T > 0.0) {
88  T = t - T;
89  nr_double_t g = getPropertyDouble ("G");
90  nr_double_t v = getV (NODE_1, T) - getV (NODE_4, T);
91  setI (NODE_2, -g * v);
92  setI (NODE_3, +g * v);
93  }
94 }
95 
96 // properties
97 PROP_REQ [] = {
98  { "G", PROP_REAL, { 1, PROP_NO_STR }, PROP_NO_RANGE }, PROP_NO_PROP };
99 PROP_OPT [] = {
100  { "T", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE }, PROP_NO_PROP };
101 struct define_t vccs::cirdef =