Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cccs.cpp
Go to the documentation of this file.
1 /*
2  * cccs.cpp - cccs 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 "cccs.h"
31 
32 using namespace qucs;
33 
34 cccs::cccs () : circuit (4) {
35  type = CIR_CCCS;
36  setVoltageSources (1);
37 }
38 
39 void cccs::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, 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, z1); setS (NODE_2, NODE_2, 1.0);
50  setS (NODE_2, NODE_3, 0.0); setS (NODE_2, NODE_4, z2);
51  setS (NODE_3, NODE_1, z2); setS (NODE_3, NODE_2, 0.0);
52  setS (NODE_3, NODE_3, 1.0); setS (NODE_3, NODE_4, z1);
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 cccs::initDC (void) {
58  setISource (false);
59  allocMatrixMNA ();
60  nr_double_t g = getPropertyDouble ("G");
61  setC (VSRC_1, NODE_1, +1.0); setC (VSRC_1, NODE_2, +0.0);
62  setC (VSRC_1, NODE_3, +0.0); setC (VSRC_1, NODE_4, -1.0);
63  setB (NODE_1, VSRC_1, +1/g); setB (NODE_2, VSRC_1, +1.0);
64  setB (NODE_3, VSRC_1, -1.0); setB (NODE_4, VSRC_1, -1/g);
65  setD (VSRC_1, VSRC_1, 0.0);
66  setE (VSRC_1, 0.0);
67 }
68 
69 void cccs::initAC (void) {
70  initDC ();
71 }
72 
73 void cccs::calcAC (nr_double_t frequency) {
74  nr_double_t g = getPropertyDouble ("G");
75  nr_double_t t = getPropertyDouble ("T");
76  nr_complex_t r = qucs::polar (1.0 / g, - 2.0 * M_PI * frequency * t);
77  setB (NODE_1, VSRC_1, +r); setB (NODE_4, VSRC_1, -r);
78 }
79 
80 void cccs::initTR (void) {
81  nr_double_t t = getPropertyDouble ("T");
82  initDC ();
83  deleteHistory ();
84  if (t > 0.0) {
85  setISource (true);
86  setHistory (true);
87  initHistory (t);
88  setB (NODE_1, VSRC_1, +1.0); setB (NODE_2, VSRC_1, +0.0);
89  setB (NODE_3, VSRC_1, -0.0); setB (NODE_4, VSRC_1, -1.0);
90  }
91 }
92 
93 void cccs::calcTR (nr_double_t t) {
94  nr_double_t T = getPropertyDouble ("T");
95  if (T > 0.0) {
96  T = t - T;
97  nr_double_t g = getPropertyDouble ("G");
98  nr_double_t i = getJ (VSRC_1, T);
99  setI (NODE_2, -g * i);
100  setI (NODE_3, +g * i);
101  }
102 }
103 
104 // properties
105 PROP_REQ [] = {
106  { "G", PROP_REAL, { 1, PROP_NO_STR }, PROP_NO_RANGE }, PROP_NO_PROP };
107 PROP_OPT [] = {
108  { "T", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE }, PROP_NO_PROP };
109 struct define_t cccs::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
void calcTR(nr_double_t)
Definition: cccs.cpp:93
#define NODE_2
Definition: circuit.h:35
void setISource(bool i)
Definition: circuit.h:194
#define PROP_DEF
Definition: netdefs.h:189
PROP_OPT[]
Definition: cccs.cpp:107
Definition: cccs.cpp:109
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
#define PROP_NO_PROP
Definition: netdefs.h:122
#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
r
Definition: parse_mdl.y:515
void calcAC(nr_double_t)
Definition: cccs.cpp:73
PROP_NO_SUBSTRATE
Definition: cccs.cpp:110
void initTR(void)
Definition: cccs.cpp:80
#define NODE_4
Definition: circuit.h:37
#define VSRC_1
Definition: circuit.h:40
i
Definition: parse_mdl.y:516
void initDC(void)
Definition: cccs.cpp:57
nr_double_t getJ(int, nr_double_t)
Definition: circuit.cpp:951
void initAC(void)
Definition: cccs.cpp:69
#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
void setI(int, nr_complex_t)
Definition: circuit.cpp:397
type
Definition: parse_vcd.y:164
void allocMatrixMNA(void)
Definition: circuit.cpp:267
PROP_REQ[]
Definition: cccs.cpp:105
#define NODE_1
Definition: circuit.h:34
void calcSP(nr_double_t)
Definition: cccs.cpp:39
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