Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vcvs.cpp
Go to the documentation of this file.
1 /*
2  * vcvs.cpp - vcvs class implementation
3  *
4  * Copyright (C) 2003, 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 "vcvs.h"
31 
32 using namespace qucs;
33 
34 vcvs::vcvs () : circuit (4) {
35  type = CIR_VCVS;
37 }
38 
39 void vcvs::calcSP (nr_double_t frequency) {
40 
41  nr_double_t g = getPropertyDouble ("G");
42  nr_double_t T = getPropertyDouble ("T");
43 
44  nr_complex_t z1 = qucs::polar (g, M_PI - 2.0 * M_PI * frequency * T);
45  nr_complex_t z2 = qucs::polar (g, - 2.0 * M_PI * frequency * T);
46 
47  setS (NODE_1, NODE_1, 1.0); setS (NODE_1, NODE_2, 0.0);
48  setS (NODE_1, NODE_3, 0.0); setS (NODE_1, NODE_4, 0.0);
49  setS (NODE_2, NODE_1, z2); setS (NODE_2, NODE_2, 0.0);
50  setS (NODE_2, NODE_3, 1.0); setS (NODE_2, NODE_4, z1);
51  setS (NODE_3, NODE_1, z1); setS (NODE_3, NODE_2, 1.0);
52  setS (NODE_3, NODE_3, 0.0); setS (NODE_3, NODE_4, z2);
53  setS (NODE_4, NODE_1, 0.0); setS (NODE_4, NODE_2, 0.0);
54  setS (NODE_4, NODE_3, 0.0); setS (NODE_4, NODE_4, 1.0);
55 }
56 
57 void vcvs::initDC (void) {
58  nr_double_t g = getPropertyDouble ("G");
59  allocMatrixMNA ();
60  setC (VSRC_1, NODE_1, +g); setC (VSRC_1, NODE_2, -1.0);
61  setC (VSRC_1, NODE_3, +1.0); setC (VSRC_1, NODE_4, -g);
62  setB (NODE_1, VSRC_1, +0); setB (NODE_2, VSRC_1, -1.0);
63  setB (NODE_3, VSRC_1, +1.0); setB (NODE_4, VSRC_1, +0);
64  setD (VSRC_1, VSRC_1, 0.0);
65  setE (VSRC_1, 0.0);
66 }
67 
68 void vcvs::initAC (void) {
69  initDC ();
70 }
71 
72 void vcvs::calcAC (nr_double_t frequency) {
73  nr_double_t T = getPropertyDouble ("T");
75  - 2.0 * M_PI * frequency * T);
76  setC (VSRC_1, NODE_1, +g); setC (VSRC_1, NODE_4, -g);
77 }
78 
79 void vcvs::initTR (void) {
80  nr_double_t T = getPropertyDouble ("T");
81  initDC ();
82  deleteHistory ();
83  if (T > 0.0) {
84  setHistory (true);
85  initHistory (T);
86  setC (VSRC_1, NODE_1, 0.0); setC (VSRC_1, NODE_4, 0.0);
87  }
88 }
89 
90 void vcvs::calcTR (nr_double_t t) {
91  nr_double_t T = getPropertyDouble ("T");
92  if (T > 0.0) {
93  T = t - T;
94  nr_double_t g = getPropertyDouble ("G");
95  nr_double_t v = getV (NODE_4, T) - getV (NODE_1, T);
96  setE (VSRC_1, g * v);
97  }
98 }
99 
100 // properties
101 PROP_REQ [] = {
102  { "G", PROP_REAL, { 1, PROP_NO_STR }, PROP_NO_RANGE }, PROP_NO_PROP };
103 PROP_OPT [] = {
104  { "T", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE }, PROP_NO_PROP };
105 struct define_t vcvs::cirdef =
std::complex< nr_double_t > nr_complex_t
Definition: complex.h:31
#define PROP_POS_RANGE
Definition: netdefs.h:129
void setHistory(bool h)
Definition: circuit.h:213
#define NODE_2
Definition: circuit.h:35
#define PROP_DEF
Definition: netdefs.h:189
PROP_REQ[]
Definition: vcvs.cpp:101
nr_double_t getPropertyDouble(const char *)
Definition: object.cpp:176
void setD(int, int, nr_complex_t)
Definition: circuit.cpp:373
Definition: vcvs.cpp:105
#define PROP_REAL
Definition: netdefs.h:174
PROP_OPT[]
Definition: vcvs.cpp:103
void calcAC(nr_double_t)
Definition: vcvs.cpp:72
t
Definition: parse_vcd.y:290
#define PROP_NO_PROP
Definition: netdefs.h:122
void setVoltageSources(int)
Definition: circuit.cpp:607
#define PROP_NO_RANGE
Definition: netdefs.h:126
#define PROP_NO_STR
Definition: netdefs.h:125
void initTR(void)
Definition: vcvs.cpp:79
void setB(int, int, nr_complex_t)
Definition: circuit.cpp:349
#define PROP_LINEAR
Definition: netdefs.h:120
void calcTR(nr_double_t)
Definition: vcvs.cpp:90
#define NODE_4
Definition: circuit.h:37
#define VSRC_1
Definition: circuit.h:40
#define PROP_COMPONENT
Definition: netdefs.h:116
void deleteHistory(void)
Definition: circuit.cpp:886
void initAC(void)
Definition: vcvs.cpp:68
void setE(int, nr_complex_t)
Definition: circuit.cpp:385
void initDC(void)
Definition: vcvs.cpp:57
#define NODE_3
Definition: circuit.h:36
#define M_PI
Archimedes' constant ( )
Definition: consts.h:47
void calcSP(nr_double_t)
Definition: vcvs.cpp:39
v
Definition: parse_zvr.y:141
void allocMatrixMNA(void)
Definition: circuit.cpp:267
nr_double_t getV(int, nr_double_t)
Definition: circuit.cpp:941
#define NODE_1
Definition: circuit.h:34
void setS(int, int, nr_complex_t)
Definition: circuit.cpp:587
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
void setC(int, int, nr_complex_t)
Definition: circuit.cpp:361
void initHistory(nr_double_t)
Definition: circuit.cpp:869
#define PROP_NO_SUBSTRATE
Definition: netdefs.h:118