My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gyrator.cpp
Go to the documentation of this file.
1 /*
2  * gyrator.cpp - gyrator class implementation
3  *
4  * Copyright (C) 2004, 2005, 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: gyrator.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 "gyrator.h"
31 
32 gyrator::gyrator () : circuit (4) {
33  type = CIR_GYRATOR;
34 #if AUGMENTED
35  setVoltageSources (2);
36 #endif
37 }
38 
39 void gyrator::initSP (void) {
40  nr_double_t R = getPropertyDouble ("R");
41  nr_double_t z = getPropertyDouble ("Zref");
42  nr_double_t r = R / z;
43  nr_double_t s1 = r * r / (r * r + 4.0);
44  nr_double_t s2 = 2.0 * r / (r * r + 4.0);
45  allocMatrixS ();
46  setS (NODE_1, NODE_1, s1); setS (NODE_2, NODE_2, s1);
47  setS (NODE_3, NODE_3, s1); setS (NODE_4, NODE_4, s1);
48  setS (NODE_1, NODE_4, 1.0 - s1);
49  setS (NODE_2, NODE_3, 1.0 - s1);
50  setS (NODE_3, NODE_2, 1.0 - s1);
51  setS (NODE_4, NODE_1, 1.0 - s1);
52  setS (NODE_1, NODE_2, +s2); setS (NODE_2, NODE_4, +s2);
53  setS (NODE_3, NODE_1, +s2); setS (NODE_4, NODE_3, +s2);
54  setS (NODE_1, NODE_3, -s2); setS (NODE_2, NODE_1, -s2);
55  setS (NODE_3, NODE_4, -s2); setS (NODE_4, NODE_2, -s2);
56 }
57 
58 void gyrator::initDC (void) {
59  nr_double_t r = getPropertyDouble ("R");
60  allocMatrixMNA ();
61 #if AUGMENTED
62  setB (NODE_1, VSRC_1, +1.0); setB (NODE_2, VSRC_1, +0.0);
63  setB (NODE_3, VSRC_1, +0.0); setB (NODE_4, VSRC_1, -1.0);
64  setB (NODE_2, VSRC_1, +0.0); setB (NODE_2, VSRC_2, +1.0);
65  setB (NODE_3, VSRC_2, -1.0); setB (NODE_4, VSRC_2, +0.0);
66  setC (VSRC_1, NODE_1, +0.0); setC (VSRC_1, NODE_2, +1/r);
67  setC (VSRC_1, NODE_3, -1/r); setC (VSRC_1, NODE_4, +0.0);
68  setC (VSRC_2, NODE_1, -1/r); setC (VSRC_2, NODE_2, +0.0);
69  setC (VSRC_2, NODE_3, +0.0); setC (VSRC_2, NODE_4, +1/r);
70  setD (VSRC_1, VSRC_1, -1.0); setD (VSRC_2, VSRC_2, -1.0);
71  setD (VSRC_1, VSRC_2, +0.0); setD (VSRC_2, VSRC_1, +0.0);
72  setE (VSRC_1, +0.0);
73  setE (VSRC_2, +0.0);
74 #else
75  setY (NODE_1, NODE_2, +1/r); setY (NODE_1, NODE_3, -1/r);
76  setY (NODE_2, NODE_1, -1/r); setY (NODE_2, NODE_4, +1/r);
77  setY (NODE_3, NODE_1, +1/r); setY (NODE_3, NODE_4, -1/r);
78  setY (NODE_4, NODE_2, -1/r); setY (NODE_4, NODE_3, +1/r);
79 #endif
80 }
81 
82 void gyrator::initAC (void) {
83  initDC ();
84 }
85 
86 void gyrator::initTR (void) {
87  initDC ();
88 }
89 
90 // properties
91 PROP_REQ [] = {
92  { "R", PROP_REAL, { 50, PROP_NO_STR }, PROP_NO_RANGE }, PROP_NO_PROP };
93 PROP_OPT [] = {
94  { "Zref", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
95  PROP_NO_PROP };
96 struct define_t gyrator::cirdef =