Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ccvs.cpp
Go to the documentation of this file.
1 /*
2  * ccvs.cpp - ccvs 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 "ccvs.h"
31 
32 using namespace qucs;
33 
34 ccvs::ccvs () : circuit (4) {
35  type = CIR_CCVS;
37 }
38 
39 void ccvs::calcSP (nr_double_t frequency) {
40 
41  nr_double_t g = getPropertyDouble ("G") / z0;
42  nr_double_t t = getPropertyDouble ("T");
43 
44  nr_complex_t z1 = qucs::polar (g / 2.0, M_PI - 2.0 * M_PI * frequency * t);
45  nr_complex_t z2 = qucs::polar (g / 2.0, - 2.0 * M_PI * frequency * t);
46 
47  setS (NODE_1, NODE_1, 0.0); setS (NODE_1, NODE_2, 0.0);
48  setS (NODE_1, NODE_3, 0.0); setS (NODE_1, NODE_4, 1.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, 1.0); setS (NODE_4, NODE_2, 0.0);
54  setS (NODE_4, NODE_3, 0.0); setS (NODE_4, NODE_4, 0.0);
55 }
56 
57 void ccvs::initDC (void) {
58  allocMatrixMNA ();
59  setB (NODE_1, VSRC_1, +1.0); setB (NODE_2, VSRC_1, +0.0);
60  setB (NODE_3, VSRC_1, +0.0); setB (NODE_4, VSRC_1, -1.0);
61  setB (NODE_1, VSRC_2, +0.0); setB (NODE_2, VSRC_2, -1.0);
62  setB (NODE_3, VSRC_2, +1.0); setB (NODE_4, VSRC_2, +0.0);
63  setC (VSRC_1, NODE_1, +0.0); setC (VSRC_1, NODE_2, +1.0);
64  setC (VSRC_1, NODE_3, -1.0); setC (VSRC_1, NODE_4, +0.0);
65  setC (VSRC_2, NODE_1, +1.0); setC (VSRC_2, NODE_2, +0.0);
66  setC (VSRC_2, NODE_3, +0.0); setC (VSRC_2, NODE_4, -1.0);
67  setD (VSRC_1, VSRC_1, - getPropertyDouble ("G"));
68  setD (VSRC_2, VSRC_2, 0.0);
69  setD (VSRC_1, VSRC_2, 0.0); setD (VSRC_2, VSRC_1, 0.0);
70  setE (VSRC_1, 0.0);
71  setE (VSRC_2, 0.0);
72 }
73 
74 void ccvs::initAC (void) {
75  initDC ();
76 }
77 
78 void ccvs::calcAC (nr_double_t frequency) {
79  nr_double_t t = getPropertyDouble ("T");
81  - 2.0 * M_PI * frequency * t);
82  setD (VSRC_1, VSRC_1, -g);
83 }
84 
85 void ccvs::initTR (void) {
86  nr_double_t t = getPropertyDouble ("T");
87  initDC ();
88  deleteHistory ();
89  if (t > 0.0) {
90  setHistory (true);
91  initHistory (t);
92  setC (VSRC_2, NODE_1, +0.0); setC (VSRC_2, NODE_2, +1.0);
93  setC (VSRC_2, NODE_3, -1.0); setC (VSRC_2, NODE_4, +0.0);
94  setC (VSRC_1, NODE_1, +1.0); setC (VSRC_1, NODE_2, +0.0);
95  setC (VSRC_1, NODE_3, +0.0); setC (VSRC_1, NODE_4, -1.0);
96  setD (VSRC_1, VSRC_1, 0.0);
97  }
98 }
99 
100 void ccvs::calcTR (nr_double_t t) {
101  nr_double_t T = getPropertyDouble ("T");
102  if (T > 0.0) {
103  T = t - T;
104  nr_double_t g = getPropertyDouble ("G");
105  nr_double_t i = getJ (VSRC_1, T);
106  setE (VSRC_2, g * i);
107  }
108 }
109 
110 // properties
111 PROP_REQ [] = {
112  { "G", PROP_REAL, { 1, PROP_NO_STR }, PROP_NO_RANGE }, PROP_NO_PROP };
113 PROP_OPT [] = {
114  { "T", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE }, PROP_NO_PROP };
115 struct define_t ccvs::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_NO_SUBSTRATE
Definition: ccvs.cpp:116
nr_double_t getPropertyDouble(const char *)
Definition: object.cpp:176
void setD(int, int, nr_complex_t)
Definition: circuit.cpp:373
#define PROP_REAL
Definition: netdefs.h:174
t
Definition: parse_vcd.y:290
void initAC(void)
Definition: ccvs.cpp:74
#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 setB(int, int, nr_complex_t)
Definition: circuit.cpp:349
#define PROP_LINEAR
Definition: netdefs.h:120
static const nr_double_t z0
Definition: circuit.h:320
PROP_OPT[]
Definition: ccvs.cpp:113
#define NODE_4
Definition: circuit.h:37
#define VSRC_1
Definition: circuit.h:40
i
Definition: parse_mdl.y:516
void calcTR(nr_double_t)
Definition: ccvs.cpp:100
nr_double_t getJ(int, nr_double_t)
Definition: circuit.cpp:951
#define PROP_COMPONENT
Definition: netdefs.h:116
void deleteHistory(void)
Definition: circuit.cpp:886
void setE(int, nr_complex_t)
Definition: circuit.cpp:385
#define NODE_3
Definition: circuit.h:36
#define M_PI
Archimedes' constant ( )
Definition: consts.h:47
Definition: ccvs.cpp:115
void calcSP(nr_double_t)
Definition: ccvs.cpp:39
void allocMatrixMNA(void)
Definition: circuit.cpp:267
#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
#define VSRC_2
Definition: circuit.h:41
void initHistory(nr_double_t)
Definition: circuit.cpp:869
void initDC(void)
Definition: ccvs.cpp:57
void calcAC(nr_double_t)
Definition: ccvs.cpp:78
PROP_REQ[]
Definition: ccvs.cpp:111
void initTR(void)
Definition: ccvs.cpp:85