Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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$
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 using namespace qucs;
33 
34 circulator::circulator () : circuit (3) {
35  type = CIR_CIRCULATOR;
36  setVoltageSources (3);
37 }
38 
39 void circulator::calcSP (nr_double_t) {
40  nr_double_t z1 = getPropertyDouble ("Z1");
41  nr_double_t z2 = getPropertyDouble ("Z2");
42  nr_double_t z3 = getPropertyDouble ("Z3");
43  nr_double_t r1 = (z0 - z1) / (z0 + z1);
44  nr_double_t r2 = (z0 - z2) / (z0 + z2);
45  nr_double_t r3 = (z0 - z3) / (z0 + z3);
46  nr_double_t d = 1 - r1 * r2 * r3;
47  setS (NODE_1, NODE_1, (r2 * r3 - r1) / d);
48  setS (NODE_2, NODE_2, (r1 * r3 - r2) / d);
49  setS (NODE_3, NODE_3, (r1 * r2 - r3) / d);
50  setS (NODE_1, NODE_2, std::sqrt (z2 / z1) * (z1 + z0) /
51  (z2 + z0) * r3 * (1 - r1 * r1) / d);
52  setS (NODE_2, NODE_3, std::sqrt (z3 / z2) * (z2 + z0) /
53  (z3 + z0) * r1 * (1 - r2 * r2) / d);
54  setS (NODE_3, NODE_1, std::sqrt (z1 / z3) * (z3 + z0) /
55  (z1 + z0) * r2 * (1 - r3 * r3) / d);
56  setS (NODE_2, NODE_1, std::sqrt (z1 / z2) * (z2 + z0) /
57  (z1 + z0) * (1 - r2 * r2) / d);
58  setS (NODE_1, NODE_3, std::sqrt (z3 / z1) * (z1 + z0) /
59  (z3 + z0) * (1 - r1 * r1) / d);
60  setS (NODE_3, NODE_2, std::sqrt (z2 / z3) * (z3 + z0) /
61  (z2 + z0) * (1 - r3 * r3) / d);
62 }
63 
64 void circulator::initDC (void) {
65  nr_double_t z1 = getPropertyDouble ("Z1");
66  nr_double_t z2 = getPropertyDouble ("Z2");
67  nr_double_t z3 = getPropertyDouble ("Z3");
68  nr_double_t r1 = (z0 - z1) / (z0 + z1);
69  nr_double_t r2 = (z0 - z2) / (z0 + z2);
70  nr_double_t r3 = (z0 - z3) / (z0 + z3);
71  nr_double_t d = 1 - r1 * r2 * r3;
72 
73  nr_double_t s11 = (r2 * r3 - r1) / d;
74  nr_double_t s22 = (r1 * r3 - r2) / d;
75  nr_double_t s33 = (r1 * r2 - r3) / d;
76  nr_double_t s12 = std::sqrt (z2/z1) * (z1+z0) / (z2+z0) * r3 * (1-r1*r1) / d;
77  nr_double_t s23 = std::sqrt (z3/z2) * (z2+z0) / (z3+z0) * r1 * (1-r2*r2) / d;
78  nr_double_t s31 = std::sqrt (z1/z3) * (z3+z0) / (z1+z0) * r2 * (1-r3*r3) / d;
79  nr_double_t s21 = std::sqrt (z1/z2) * (z2+z0) / (z1+z0) * (1-r2*r2) / d;
80  nr_double_t s13 = std::sqrt (z3/z1) * (z1+z0) / (z3+z0) * (1-r1*r1) / d;
81  nr_double_t s32 = std::sqrt (z2/z3) * (z3+z0) / (z2+z0) * (1-r3*r3) / d;
82 
83  allocMatrixMNA ();
84 
85  setB (NODE_1, VSRC_1, +1.0); setB (NODE_1, VSRC_2, +0.0);
86  setB (NODE_1, VSRC_3, +0.0);
87  setB (NODE_2, VSRC_1, +0.0); setB (NODE_2, VSRC_2, +1.0);
88  setB (NODE_2, VSRC_3, +0.0);
89  setB (NODE_3, VSRC_1, +0.0); setB (NODE_3, VSRC_2, +0.0);
90  setB (NODE_3, VSRC_3, +1.0);
91 
92  setC (VSRC_1, NODE_1, s11 - 1.0); setC (VSRC_1, NODE_2, s12);
93  setC (VSRC_1, NODE_3, s13);
94  setC (VSRC_2, NODE_1, s21); setC (VSRC_2, NODE_2, s22 - 1.0);
95  setC (VSRC_2, NODE_3, s23);
96  setC (VSRC_3, NODE_1, s31); setC (VSRC_3, NODE_2, s32);
97  setC (VSRC_3, NODE_3, s33 - 1.0);
98 
99  setD (VSRC_1, VSRC_1, z0 * (s11 + 1.0)); setD (VSRC_1, VSRC_2, z0 * s12);
100  setD (VSRC_1, VSRC_3, z0 * s13);
101  setD (VSRC_2, VSRC_1, z0 * s21); setD (VSRC_2, VSRC_2, z0 * (s22 + 1.0));
102  setD (VSRC_2, VSRC_3, z0 * s23);
103  setD (VSRC_3, VSRC_1, z0 * s31); setD (VSRC_3, VSRC_2, z0 * s32);
104  setD (VSRC_3, VSRC_3, z0 * (s33 + 1.0));
105 
106  setE (VSRC_1, +0.0); setE (VSRC_2, +0.0); setE (VSRC_3, +0.0);
107 }
108 
109 void circulator::initAC (void) {
110  initDC ();
111 }
112 
113 void circulator::initTR (void) {
114  initDC ();
115 }
116 
117 // properties
118 PROP_REQ [] = {
119  PROP_NO_PROP };
120 PROP_OPT [] = {
121  { "Z1", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
122  { "Z2", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
123  { "Z3", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
124  PROP_NO_PROP };
125 struct define_t circulator::cirdef =
126  { "Circulator",
#define PROP_POS_RANGE
Definition: netdefs.h:129
#define NODE_2
Definition: circuit.h:35
#define PROP_DEF
Definition: netdefs.h:189
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
#define PROP_NO_PROP
Definition: netdefs.h:122
#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
void initDC(void)
Definition: circulator.cpp:64
#define VSRC_1
Definition: circuit.h:40
void initTR(void)
Definition: circulator.cpp:113
nr_complex_t sqrt(const nr_complex_t z)
Compute principal value of square root.
Definition: complex.cpp:271
#define PROP_COMPONENT
Definition: netdefs.h:116
void setE(int, nr_complex_t)
Definition: circuit.cpp:385
#define VSRC_3
Definition: circuit.h:42
void initAC(void)
Definition: circulator.cpp:109
PROP_OPT[]
Definition: circulator.cpp:120
#define NODE_3
Definition: circuit.h:36
void calcSP(nr_double_t)
Definition: circulator.cpp:39
PROP_REQ[]
Definition: circulator.cpp:118
type
Definition: parse_vcd.y:164
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
void setC(int, int, nr_complex_t)
Definition: circuit.cpp:361
#define VSRC_2
Definition: circuit.h:41