My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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: cccs.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 "cccs.h"
31 
32 cccs::cccs () : circuit (4) {
33  type = CIR_CCCS;
34  setVoltageSources (1);
35 }
36 
37 void cccs::calcSP (nr_double_t frequency) {
38 
39  nr_double_t g = getPropertyDouble ("G");
40  nr_double_t t = getPropertyDouble ("T");
41 
42  nr_complex_t z1 = polar (g, M_PI - 2.0 * M_PI * frequency * t);
43  nr_complex_t z2 = polar (g, - 2.0 * M_PI * frequency * t);
44 
45  setS (NODE_1, NODE_1, 0.0); setS (NODE_1, NODE_2, 0.0);
46  setS (NODE_1, NODE_3, 0.0); setS (NODE_1, NODE_4, 1.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, 1.0); setS (NODE_4, NODE_2, 0.0);
52  setS (NODE_4, NODE_3, 0.0); setS (NODE_4, NODE_4, 0.0);
53 }
54 
55 void cccs::initDC (void) {
56  setISource (false);
57  allocMatrixMNA ();
58  nr_double_t g = getPropertyDouble ("G");
59  setC (VSRC_1, NODE_1, +1.0); setC (VSRC_1, NODE_2, +0.0);
60  setC (VSRC_1, NODE_3, +0.0); setC (VSRC_1, NODE_4, -1.0);
61  setB (NODE_1, VSRC_1, +1/g); setB (NODE_2, VSRC_1, +1.0);
62  setB (NODE_3, VSRC_1, -1.0); setB (NODE_4, VSRC_1, -1/g);
63  setD (VSRC_1, VSRC_1, 0.0);
64  setE (VSRC_1, 0.0);
65 }
66 
67 void cccs::initAC (void) {
68  initDC ();
69 }
70 
71 void cccs::calcAC (nr_double_t frequency) {
72  nr_double_t g = getPropertyDouble ("G");
73  nr_double_t t = getPropertyDouble ("T");
74  nr_complex_t r = polar (1.0 / g, - 2.0 * M_PI * frequency * t);
75  setB (NODE_1, VSRC_1, +r); setB (NODE_4, VSRC_1, -r);
76 }
77 
78 void cccs::initTR (void) {
79  nr_double_t t = getPropertyDouble ("T");
80  initDC ();
81  deleteHistory ();
82  if (t > 0.0) {
83  setISource (true);
84  setHistory (true);
85  initHistory (t);
86  setB (NODE_1, VSRC_1, +1.0); setB (NODE_2, VSRC_1, +0.0);
87  setB (NODE_3, VSRC_1, -0.0); setB (NODE_4, VSRC_1, -1.0);
88  }
89 }
90 
91 void cccs::calcTR (nr_double_t t) {
92  nr_double_t T = getPropertyDouble ("T");
93  if (T > 0.0) {
94  T = t - T;
95  nr_double_t g = getPropertyDouble ("G");
96  nr_double_t i = getJ (VSRC_1, T);
97  setI (NODE_2, -g * i);
98  setI (NODE_3, +g * i);
99  }
100 }
101 
102 // properties
103 PROP_REQ [] = {
104  { "G", PROP_REAL, { 1, PROP_NO_STR }, PROP_NO_RANGE }, PROP_NO_PROP };
105 PROP_OPT [] = {
106  { "T", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE }, PROP_NO_PROP };
107 struct define_t cccs::cirdef =