Branch data Line data Source code
1 : : /*
2 : : * mutual2.cpp - three mutual inductors class implementation
3 : : *
4 : : * Copyright (C) 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$
22 : : *
23 : : */
24 : :
25 : : #if HAVE_CONFIG_H
26 : : # include <config.h>
27 : : #endif
28 : :
29 : : #include "component.h"
30 : : #include "mutual2.h"
31 : :
32 : : using namespace qucs;
33 : :
34 : 0 : mutual2::mutual2 () : circuit (6) {
35 : 0 : type = CIR_MUTUAL2;
36 : 0 : }
37 : :
38 : 0 : void mutual2::calcSP (nr_double_t frequency) {
39 [ # # ][ # # ]: 0 : setMatrixS (ytos (calcMatrixY (frequency)));
[ # # ][ # # ]
[ # # ]
40 : 0 : }
41 : :
42 : 0 : matrix mutual2::calcMatrixY (nr_double_t frequency) {
43 [ # # ]: 0 : nr_double_t k12 = getPropertyDouble ("k12");
44 [ # # ]: 0 : nr_double_t k13 = getPropertyDouble ("k13");
45 [ # # ]: 0 : nr_double_t k23 = getPropertyDouble ("k23");
46 [ # # ]: 0 : nr_double_t l1 = getPropertyDouble ("L1");
47 [ # # ]: 0 : nr_double_t l2 = getPropertyDouble ("L2");
48 [ # # ]: 0 : nr_double_t l3 = getPropertyDouble ("L3");
49 : 0 : nr_double_t o = 2 * M_PI * frequency;
50 : 0 : nr_double_t a = 1 - k12 * k12 - k13 * k13 - k23 * k23 + 2 * k12 * k13 * k23;
51 : 0 : nr_complex_t y11 = nr_complex_t (0, (k23 * k23 - 1) / l1 / a / o);
52 : 0 : nr_complex_t y22 = nr_complex_t (0, (k12 * k12 - 1) / l3 / a / o);
53 : 0 : nr_complex_t y44 = nr_complex_t (0, (k13 * k13 - 1) / l2 / a / o);
54 : 0 : nr_complex_t y12 = nr_complex_t (0, (k13 - k12 * k23) / std::sqrt (l1 * l3) / a / o);
55 : 0 : nr_complex_t y15 = nr_complex_t (0, (k12 - k13 * k23) / std::sqrt (l1 * l2) / a / o);
56 : 0 : nr_complex_t y25 = nr_complex_t (0, (k23 - k12 * k13) / std::sqrt (l2 * l3) / a / o);
57 : :
58 [ # # ]: 0 : matrix y = matrix (6);
59 [ # # ][ # # ]: 0 : y.set (NODE_1, NODE_1, +y11); y.set (NODE_6, NODE_6, +y11);
60 [ # # ][ # # ]: 0 : y.set (NODE_1, NODE_6, -y11); y.set (NODE_6, NODE_1, -y11);
61 [ # # ][ # # ]: 0 : y.set (NODE_2, NODE_2, +y22); y.set (NODE_3, NODE_3, +y22);
62 [ # # ][ # # ]: 0 : y.set (NODE_2, NODE_3, -y22); y.set (NODE_3, NODE_2, -y22);
63 [ # # ][ # # ]: 0 : y.set (NODE_4, NODE_4, +y44); y.set (NODE_5, NODE_5, +y44);
64 [ # # ][ # # ]: 0 : y.set (NODE_4, NODE_5, -y44); y.set (NODE_5, NODE_4, -y44);
65 [ # # ][ # # ]: 0 : y.set (NODE_1, NODE_2, +y12); y.set (NODE_2, NODE_1, +y12);
66 [ # # ][ # # ]: 0 : y.set (NODE_3, NODE_6, +y12); y.set (NODE_6, NODE_3, +y12);
67 [ # # ][ # # ]: 0 : y.set (NODE_1, NODE_3, -y12); y.set (NODE_3, NODE_1, -y12);
68 [ # # ][ # # ]: 0 : y.set (NODE_2, NODE_6, -y12); y.set (NODE_6, NODE_2, -y12);
69 [ # # ][ # # ]: 0 : y.set (NODE_1, NODE_5, +y15); y.set (NODE_5, NODE_1, +y15);
70 [ # # ][ # # ]: 0 : y.set (NODE_4, NODE_6, +y15); y.set (NODE_6, NODE_4, +y15);
71 [ # # ][ # # ]: 0 : y.set (NODE_1, NODE_4, -y15); y.set (NODE_4, NODE_1, -y15);
72 [ # # ][ # # ]: 0 : y.set (NODE_5, NODE_6, -y15); y.set (NODE_6, NODE_5, -y15);
73 [ # # ][ # # ]: 0 : y.set (NODE_2, NODE_5, +y25); y.set (NODE_5, NODE_2, +y25);
74 [ # # ][ # # ]: 0 : y.set (NODE_4, NODE_3, +y25); y.set (NODE_3, NODE_4, +y25);
75 [ # # ][ # # ]: 0 : y.set (NODE_2, NODE_4, -y25); y.set (NODE_4, NODE_2, -y25);
76 [ # # ][ # # ]: 0 : y.set (NODE_5, NODE_3, -y25); y.set (NODE_3, NODE_5, -y25);
77 : 0 : return y;
78 : : }
79 : :
80 : 0 : void mutual2::initAC (void) {
81 : 0 : setVoltageSources (0);
82 : 0 : allocMatrixMNA ();
83 : 0 : }
84 : :
85 : 0 : void mutual2::calcAC (nr_double_t frequency) {
86 [ # # ]: 0 : setMatrixY (calcMatrixY (frequency));
87 : 0 : }
88 : :
89 : 0 : void mutual2::initDC (void) {
90 : 0 : setVoltageSources (3);
91 : 0 : allocMatrixMNA ();
92 : 0 : voltageSource (VSRC_1, NODE_1, NODE_6);
93 : 0 : voltageSource (VSRC_2, NODE_5, NODE_4);
94 : 0 : voltageSource (VSRC_3, NODE_2, NODE_3);
95 : 0 : }
96 : :
97 : 0 : void mutual2::initTR (void) {
98 : 0 : initDC ();
99 : 0 : setStates (18);
100 : 0 : }
101 : :
102 : : #define fState11 0 // flux state
103 : : #define vState11 1 // voltage state
104 : : #define fState12 2
105 : : #define vState12 3
106 : : #define fState13 4
107 : : #define vState13 5
108 : : #define fState21 6
109 : : #define vState21 7
110 : : #define fState22 8
111 : : #define vState22 9
112 : : #define fState23 10
113 : : #define vState23 11
114 : : #define fState31 12
115 : : #define vState31 13
116 : : #define fState32 14
117 : : #define vState32 15
118 : : #define fState33 16
119 : : #define vState33 17
120 : :
121 : 0 : void mutual2::calcTR (nr_double_t) {
122 [ # # ]: 0 : nr_double_t k12 = getPropertyDouble ("k12");
123 [ # # ]: 0 : nr_double_t k13 = getPropertyDouble ("k13");
124 [ # # ]: 0 : nr_double_t k23 = getPropertyDouble ("k23");
125 [ # # ]: 0 : nr_double_t l1 = getPropertyDouble ("L1");
126 [ # # ]: 0 : nr_double_t l2 = getPropertyDouble ("L2");
127 [ # # ]: 0 : nr_double_t l3 = getPropertyDouble ("L3");
128 : 0 : nr_double_t M12 = k12 * std::sqrt (l1 * l2);
129 : 0 : nr_double_t M13 = k13 * std::sqrt (l1 * l3);
130 : 0 : nr_double_t M23 = k23 * std::sqrt (l2 * l3);
131 : : nr_double_t r11, r12, r13, r21, r22, r23, r31, r32, r33;
132 : : nr_double_t v11, v12, v13, v21, v22, v23, v31, v32, v33;
133 [ # # ]: 0 : nr_double_t i1 = real (getJ (VSRC_1));
134 [ # # ]: 0 : nr_double_t i2 = real (getJ (VSRC_2));
135 [ # # ]: 0 : nr_double_t i3 = real (getJ (VSRC_3));
136 : :
137 : 0 : setState (fState11, i1 * l1);
138 [ # # ]: 0 : integrate (fState11, l1, r11, v11);
139 : 0 : setState (fState22, i2 * l2);
140 [ # # ]: 0 : integrate (fState22, l2, r22, v22);
141 : 0 : setState (fState33, i3 * l3);
142 [ # # ]: 0 : integrate (fState33, l3, r33, v33);
143 : :
144 : 0 : setState (fState12, i2 * M12);
145 [ # # ]: 0 : integrate (fState12, M12, r12, v12);
146 : 0 : setState (fState13, i3 * M13);
147 [ # # ]: 0 : integrate (fState13, M13, r13, v13);
148 : 0 : setState (fState21, i1 * M12);
149 [ # # ]: 0 : integrate (fState21, M12, r21, v21);
150 : 0 : setState (fState23, i3 * M23);
151 [ # # ]: 0 : integrate (fState23, M23, r23, v23);
152 : 0 : setState (fState31, i1 * M13);
153 [ # # ]: 0 : integrate (fState31, M13, r31, v31);
154 : 0 : setState (fState32, i2 * M23);
155 [ # # ]: 0 : integrate (fState32, M23, r32, v32);
156 : :
157 [ # # ]: 0 : setD (VSRC_1, VSRC_1, -r11);
158 [ # # ]: 0 : setD (VSRC_1, VSRC_2, -r12);
159 [ # # ]: 0 : setD (VSRC_1, VSRC_3, -r13);
160 [ # # ]: 0 : setD (VSRC_2, VSRC_1, -r21);
161 [ # # ]: 0 : setD (VSRC_2, VSRC_2, -r22);
162 [ # # ]: 0 : setD (VSRC_2, VSRC_3, -r23);
163 [ # # ]: 0 : setD (VSRC_3, VSRC_1, -r31);
164 [ # # ]: 0 : setD (VSRC_3, VSRC_2, -r32);
165 [ # # ]: 0 : setD (VSRC_3, VSRC_3, -r33);
166 [ # # ]: 0 : setE (VSRC_1, v11 + v12 + v13);
167 [ # # ]: 0 : setE (VSRC_2, v21 + v22 + v23);
168 [ # # ]: 0 : setE (VSRC_3, v31 + v32 + v33);
169 : 0 : }
170 : :
171 : : // properties
172 : : PROP_REQ [] = {
173 : : { "L1", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_POS_RANGEX },
174 : : { "L2", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_POS_RANGEX },
175 : : { "L3", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_POS_RANGEX },
176 : : { "k12", PROP_REAL, { 0.9, PROP_NO_STR }, PROP_RNGXX (-1, 1) },
177 : : { "k13", PROP_REAL, { 0.9, PROP_NO_STR }, PROP_RNGXX (-1, 1) },
178 : : { "k23", PROP_REAL, { 0.9, PROP_NO_STR }, PROP_RNGXX (-1, 1) },
179 : : PROP_NO_PROP };
180 : : PROP_OPT [] = {
181 : : PROP_NO_PROP };
182 : : struct define_t mutual2::cirdef =
183 : : { "MUT2", 6, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };
|