My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
circulator.cpp
Go to the documentation of this file.
1 /*
2  * circulator.cpp - circulator class implementation
3  *
4  * Copyright (C) 2003, 2004, 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: circulator.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 "circulator.h"
31 
32 circulator::circulator () : circuit (3) {
33  type = CIR_CIRCULATOR;
34  setVoltageSources (3);
35 }
36 
37 void circulator::calcSP (nr_double_t) {
38  nr_double_t z1 = getPropertyDouble ("Z1");
39  nr_double_t z2 = getPropertyDouble ("Z2");
40  nr_double_t z3 = getPropertyDouble ("Z3");
41  nr_double_t r1 = (z0 - z1) / (z0 + z1);
42  nr_double_t r2 = (z0 - z2) / (z0 + z2);
43  nr_double_t r3 = (z0 - z3) / (z0 + z3);
44  nr_double_t d = 1 - r1 * r2 * r3;
45  setS (NODE_1, NODE_1, (r2 * r3 - r1) / d);
46  setS (NODE_2, NODE_2, (r1 * r3 - r2) / d);
47  setS (NODE_3, NODE_3, (r1 * r2 - r3) / d);
48  setS (NODE_1, NODE_2, sqrt (z2 / z1) * (z1 + z0) /
49  (z2 + z0) * r3 * (1 - r1 * r1) / d);
50  setS (NODE_2, NODE_3, sqrt (z3 / z2) * (z2 + z0) /
51  (z3 + z0) * r1 * (1 - r2 * r2) / d);
52  setS (NODE_3, NODE_1, sqrt (z1 / z3) * (z3 + z0) /
53  (z1 + z0) * r2 * (1 - r3 * r3) / d);
54  setS (NODE_2, NODE_1, sqrt (z1 / z2) * (z2 + z0) /
55  (z1 + z0) * (1 - r2 * r2) / d);
56  setS (NODE_1, NODE_3, sqrt (z3 / z1) * (z1 + z0) /
57  (z3 + z0) * (1 - r1 * r1) / d);
58  setS (NODE_3, NODE_2, sqrt (z2 / z3) * (z3 + z0) /
59  (z2 + z0) * (1 - r3 * r3) / d);
60 }
61 
62 void circulator::initDC (void) {
63  nr_double_t z1 = getPropertyDouble ("Z1");
64  nr_double_t z2 = getPropertyDouble ("Z2");
65  nr_double_t z3 = getPropertyDouble ("Z3");
66  nr_double_t r1 = (z0 - z1) / (z0 + z1);
67  nr_double_t r2 = (z0 - z2) / (z0 + z2);
68  nr_double_t r3 = (z0 - z3) / (z0 + z3);
69  nr_double_t d = 1 - r1 * r2 * r3;
70 
71  nr_double_t s11 = (r2 * r3 - r1) / d;
72  nr_double_t s22 = (r1 * r3 - r2) / d;
73  nr_double_t s33 = (r1 * r2 - r3) / d;
74  nr_double_t s12 = sqrt (z2/z1) * (z1+z0) / (z2+z0) * r3 * (1-r1*r1) / d;
75  nr_double_t s23 = sqrt (z3/z2) * (z2+z0) / (z3+z0) * r1 * (1-r2*r2) / d;
76  nr_double_t s31 = sqrt (z1/z3) * (z3+z0) / (z1+z0) * r2 * (1-r3*r3) / d;
77  nr_double_t s21 = sqrt (z1/z2) * (z2+z0) / (z1+z0) * (1-r2*r2) / d;
78  nr_double_t s13 = sqrt (z3/z1) * (z1+z0) / (z3+z0) * (1-r1*r1) / d;
79  nr_double_t s32 = sqrt (z2/z3) * (z3+z0) / (z2+z0) * (1-r3*r3) / d;
80 
81  allocMatrixMNA ();
82 
83  setB (NODE_1, VSRC_1, +1.0); setB (NODE_1, VSRC_2, +0.0);
84  setB (NODE_1, VSRC_3, +0.0);
85  setB (NODE_2, VSRC_1, +0.0); setB (NODE_2, VSRC_2, +1.0);
86  setB (NODE_2, VSRC_3, +0.0);
87  setB (NODE_3, VSRC_1, +0.0); setB (NODE_3, VSRC_2, +0.0);
88  setB (NODE_3, VSRC_3, +1.0);
89 
90  setC (VSRC_1, NODE_1, s11 - 1.0); setC (VSRC_1, NODE_2, s12);
91  setC (VSRC_1, NODE_3, s13);
92  setC (VSRC_2, NODE_1, s21); setC (VSRC_2, NODE_2, s22 - 1.0);
93  setC (VSRC_2, NODE_3, s23);
94  setC (VSRC_3, NODE_1, s31); setC (VSRC_3, NODE_2, s32);
95  setC (VSRC_3, NODE_3, s33 - 1.0);
96 
97  setD (VSRC_1, VSRC_1, z0 * (s11 + 1.0)); setD (VSRC_1, VSRC_2, z0 * s12);
98  setD (VSRC_1, VSRC_3, z0 * s13);
99  setD (VSRC_2, VSRC_1, z0 * s21); setD (VSRC_2, VSRC_2, z0 * (s22 + 1.0));
100  setD (VSRC_2, VSRC_3, z0 * s23);
101  setD (VSRC_3, VSRC_1, z0 * s31); setD (VSRC_3, VSRC_2, z0 * s32);
102  setD (VSRC_3, VSRC_3, z0 * (s33 + 1.0));
103 
104  setE (VSRC_1, +0.0); setE (VSRC_2, +0.0); setE (VSRC_3, +0.0);
105 }
106 
107 void circulator::initAC (void) {
108  initDC ();
109 }
110 
111 void circulator::initTR (void) {
112  initDC ();
113 }
114 
115 // properties
116 PROP_REQ [] = {
117  PROP_NO_PROP };
118 PROP_OPT [] = {
119  { "Z1", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
120  { "Z2", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
121  { "Z3", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
122  PROP_NO_PROP };
123 struct define_t circulator::cirdef =
124  { "Circulator",