Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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$
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 using namespace qucs;
33 
34 vccs::vccs () : circuit (4) {
35  type = CIR_VCCS;
36 }
37 
38 void vccs::calcSP (nr_double_t frequency) {
39  nr_double_t g = getPropertyDouble ("G") * z0;
40  nr_double_t t = getPropertyDouble ("T");
41 
42  nr_complex_t z1 = qucs::polar (2.0 * g, M_PI - 2.0 * M_PI * frequency * t);
43  nr_complex_t z2 = qucs::polar (2.0 * g, - 2.0 * M_PI * frequency * t);
44 
45  setS (NODE_1, NODE_1, 1.0); setS (NODE_1, NODE_2, 0.0);
46  setS (NODE_1, NODE_3, 0.0); setS (NODE_1, NODE_4, 0.0);
47  setS (NODE_2, NODE_1, z1); setS (NODE_2, NODE_2, 1.0);
48  setS (NODE_2, NODE_3, 0.0); setS (NODE_2, NODE_4, z2);
49  setS (NODE_3, NODE_1, z2); setS (NODE_3, NODE_2, 0.0);
50  setS (NODE_3, NODE_3, 1.0); setS (NODE_3, NODE_4, z1);
51  setS (NODE_4, NODE_1, 0.0); setS (NODE_4, NODE_2, 0.0);
52  setS (NODE_4, NODE_3, 0.0); setS (NODE_4, NODE_4, 1.0);
53 }
54 
55 void vccs::initDC (void) {
56  setISource (false);
57  allocMatrixMNA ();
58  nr_double_t g = getPropertyDouble ("G");
59  setY (NODE_2, NODE_1, +g); setY (NODE_3, NODE_4, +g);
60  setY (NODE_3, NODE_1, -g); setY (NODE_2, NODE_4, -g);
61 }
62 
63 void vccs::initAC (void) {
64  initDC ();
65 }
66 
67 void vccs::calcAC (nr_double_t frequency) {
68  nr_double_t t = getPropertyDouble ("T");
69  nr_complex_t g = qucs::polar (getPropertyDouble ("G"),
70  - 2.0 * M_PI * frequency * t);
71  setY (NODE_2, NODE_1, +g); setY (NODE_3, NODE_4, +g);
72  setY (NODE_3, NODE_1, -g); setY (NODE_2, NODE_4, -g);
73 }
74 
75 void vccs::initTR (void) {
76  nr_double_t t = getPropertyDouble ("T");
77  initDC ();
78  deleteHistory ();
79  if (t > 0.0) {
80  setISource (true);
81  setHistory (true);
82  initHistory (t);
83  clearY ();
84  }
85 }
86 
87 void vccs::calcTR (nr_double_t t) {
88  nr_double_t T = getPropertyDouble ("T");
89  if (T > 0.0) {
90  T = t - T;
91  nr_double_t g = getPropertyDouble ("G");
92  nr_double_t v = getV (NODE_1, T) - getV (NODE_4, T);
93  setI (NODE_2, -g * v);
94  setI (NODE_3, +g * v);
95  }
96 }
97 
98 // properties
99 PROP_REQ [] = {
100  { "G", PROP_REAL, { 1, PROP_NO_STR }, PROP_NO_RANGE }, PROP_NO_PROP };
101 PROP_OPT [] = {
102  { "T", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE }, PROP_NO_PROP };
103 struct define_t vccs::cirdef =
std::complex< nr_double_t > nr_complex_t
Definition: complex.h:31
#define PROP_POS_RANGE
Definition: netdefs.h:129
#define NODE_2
Definition: circuit.h:35
void initAC(void)
Definition: vccs.cpp:63
void calcTR(nr_double_t)
Definition: vccs.cpp:87
#define PROP_DEF
Definition: netdefs.h:189
PROP_OPT[]
Definition: acsolver.cpp:232
#define PROP_REAL
Definition: netdefs.h:174
void initDC(void)
Definition: vccs.cpp:55
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
#define PROP_LINEAR
Definition: netdefs.h:120
#define NODE_4
Definition: circuit.h:37
#define PROP_COMPONENT
Definition: netdefs.h:116
#define NODE_3
Definition: circuit.h:36
#define M_PI
Archimedes' constant ( )
Definition: consts.h:47
Definition: vccs.cpp:103
v
Definition: parse_zvr.y:141
void initTR(void)
Definition: vccs.cpp:75
#define NODE_1
Definition: circuit.h:34
void calcSP(nr_double_t)
Definition: vccs.cpp:38
nr_complex_t polar(const nr_double_t mag, const nr_double_t ang)
Construct a complex number using polar notation.
Definition: complex.cpp:551
PROP_REQ[]
Definition: acsolver.cpp:229
void calcAC(nr_double_t)
Definition: vccs.cpp:67
#define PROP_NO_SUBSTRATE
Definition: netdefs.h:118