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