Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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$
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 mutual2::mutual2 () : circuit (6) {
35  type = CIR_MUTUAL2;
36 }
37 
38 void mutual2::calcSP (nr_double_t frequency) {
39  setMatrixS (ytos (calcMatrixY (frequency)));
40 }
41 
42 matrix mutual2::calcMatrixY (nr_double_t frequency) {
43  nr_double_t k12 = getPropertyDouble ("k12");
44  nr_double_t k13 = getPropertyDouble ("k13");
45  nr_double_t k23 = getPropertyDouble ("k23");
46  nr_double_t l1 = getPropertyDouble ("L1");
47  nr_double_t l2 = getPropertyDouble ("L2");
48  nr_double_t l3 = getPropertyDouble ("L3");
49  nr_double_t o = 2 * M_PI * frequency;
50  nr_double_t a = 1 - k12 * k12 - k13 * k13 - k23 * k23 + 2 * k12 * k13 * k23;
51  nr_complex_t y11 = nr_complex_t (0, (k23 * k23 - 1) / l1 / a / o);
52  nr_complex_t y22 = nr_complex_t (0, (k12 * k12 - 1) / l3 / a / o);
53  nr_complex_t y44 = nr_complex_t (0, (k13 * k13 - 1) / l2 / a / o);
54  nr_complex_t y12 = nr_complex_t (0, (k13 - k12 * k23) / std::sqrt (l1 * l3) / a / o);
55  nr_complex_t y15 = nr_complex_t (0, (k12 - k13 * k23) / std::sqrt (l1 * l2) / a / o);
56  nr_complex_t y25 = nr_complex_t (0, (k23 - k12 * k13) / std::sqrt (l2 * l3) / a / o);
57 
58  matrix y = matrix (6);
59  y.set (NODE_1, NODE_1, +y11); y.set (NODE_6, NODE_6, +y11);
60  y.set (NODE_1, NODE_6, -y11); y.set (NODE_6, NODE_1, -y11);
61  y.set (NODE_2, NODE_2, +y22); y.set (NODE_3, NODE_3, +y22);
62  y.set (NODE_2, NODE_3, -y22); y.set (NODE_3, NODE_2, -y22);
63  y.set (NODE_4, NODE_4, +y44); y.set (NODE_5, NODE_5, +y44);
64  y.set (NODE_4, NODE_5, -y44); y.set (NODE_5, NODE_4, -y44);
65  y.set (NODE_1, NODE_2, +y12); y.set (NODE_2, NODE_1, +y12);
66  y.set (NODE_3, NODE_6, +y12); y.set (NODE_6, NODE_3, +y12);
67  y.set (NODE_1, NODE_3, -y12); y.set (NODE_3, NODE_1, -y12);
68  y.set (NODE_2, NODE_6, -y12); y.set (NODE_6, NODE_2, -y12);
69  y.set (NODE_1, NODE_5, +y15); y.set (NODE_5, NODE_1, +y15);
70  y.set (NODE_4, NODE_6, +y15); y.set (NODE_6, NODE_4, +y15);
71  y.set (NODE_1, NODE_4, -y15); y.set (NODE_4, NODE_1, -y15);
72  y.set (NODE_5, NODE_6, -y15); y.set (NODE_6, NODE_5, -y15);
73  y.set (NODE_2, NODE_5, +y25); y.set (NODE_5, NODE_2, +y25);
74  y.set (NODE_4, NODE_3, +y25); y.set (NODE_3, NODE_4, +y25);
75  y.set (NODE_2, NODE_4, -y25); y.set (NODE_4, NODE_2, -y25);
76  y.set (NODE_5, NODE_3, -y25); y.set (NODE_3, NODE_5, -y25);
77  return y;
78 }
79 
80 void mutual2::initAC (void) {
82  allocMatrixMNA ();
83 }
84 
85 void mutual2::calcAC (nr_double_t frequency) {
86  setMatrixY (calcMatrixY (frequency));
87 }
88 
89 void mutual2::initDC (void) {
91  allocMatrixMNA ();
95 }
96 
97 void mutual2::initTR (void) {
98  initDC ();
99  setStates (18);
100 }
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 void mutual2::calcTR (nr_double_t) {
122  nr_double_t k12 = getPropertyDouble ("k12");
123  nr_double_t k13 = getPropertyDouble ("k13");
124  nr_double_t k23 = getPropertyDouble ("k23");
125  nr_double_t l1 = getPropertyDouble ("L1");
126  nr_double_t l2 = getPropertyDouble ("L2");
127  nr_double_t l3 = getPropertyDouble ("L3");
128  nr_double_t M12 = k12 * std::sqrt (l1 * l2);
129  nr_double_t M13 = k13 * std::sqrt (l1 * l3);
130  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  nr_double_t i1 = real (getJ (VSRC_1));
134  nr_double_t i2 = real (getJ (VSRC_2));
135  nr_double_t i3 = real (getJ (VSRC_3));
136 
137  setState (fState11, i1 * l1);
138  integrate (fState11, l1, r11, v11);
139  setState (fState22, i2 * l2);
140  integrate (fState22, l2, r22, v22);
141  setState (fState33, i3 * l3);
142  integrate (fState33, l3, r33, v33);
143 
144  setState (fState12, i2 * M12);
145  integrate (fState12, M12, r12, v12);
146  setState (fState13, i3 * M13);
147  integrate (fState13, M13, r13, v13);
148  setState (fState21, i1 * M12);
149  integrate (fState21, M12, r21, v21);
150  setState (fState23, i3 * M23);
151  integrate (fState23, M23, r23, v23);
152  setState (fState31, i1 * M13);
153  integrate (fState31, M13, r31, v31);
154  setState (fState32, i2 * M23);
155  integrate (fState32, M23, r32, v32);
156 
157  setD (VSRC_1, VSRC_1, -r11);
158  setD (VSRC_1, VSRC_2, -r12);
159  setD (VSRC_1, VSRC_3, -r13);
160  setD (VSRC_2, VSRC_1, -r21);
161  setD (VSRC_2, VSRC_2, -r22);
162  setD (VSRC_2, VSRC_3, -r23);
163  setD (VSRC_3, VSRC_1, -r31);
164  setD (VSRC_3, VSRC_2, -r32);
165  setD (VSRC_3, VSRC_3, -r33);
166  setE (VSRC_1, v11 + v12 + v13);
167  setE (VSRC_2, v21 + v22 + v23);
168  setE (VSRC_3, v31 + v32 + v33);
169 }
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 =
std::complex< nr_double_t > nr_complex_t
Definition: complex.h:31
matrix ytos(matrix y, qucs::vector z0)
Admittance matrix to scattering parameters.
Definition: matrix.cpp:1133
PROP_NO_SUBSTRATE
Definition: mutual2.cpp:183
#define NODE_2
Definition: circuit.h:35
matrix real(matrix a)
Real part matrix.
Definition: matrix.cpp:568
#define PROP_DEF
Definition: netdefs.h:189
void integrate(int, nr_double_t, nr_double_t &, nr_double_t &)
Definition: integrator.cpp:67
#define fState31
Definition: mutual2.cpp:114
void calcSP(nr_double_t)
Definition: mutual2.cpp:38
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
void setStates(int n)
Definition: states.h:52
#define PROP_NO_PROP
Definition: netdefs.h:122
void setVoltageSources(int)
Definition: circuit.cpp:607
#define fState11
Definition: mutual2.cpp:102
#define PROP_NO_STR
Definition: netdefs.h:125
#define PROP_LINEAR
Definition: netdefs.h:120
i1
Definition: parse_citi.y:148
#define NODE_6
Definition: circuit.h:39
#define NODE_4
Definition: circuit.h:37
#define VSRC_1
Definition: circuit.h:40
#define PROP_RNGXX(f, t)
Definition: netdefs.h:141
void initAC(void)
Definition: mutual2.cpp:80
nr_complex_t sqrt(const nr_complex_t z)
Compute principal value of square root.
Definition: complex.cpp:271
void calcAC(nr_double_t)
Definition: mutual2.cpp:85
nr_double_t getJ(int, nr_double_t)
Definition: circuit.cpp:951
#define PROP_COMPONENT
Definition: netdefs.h:116
void setE(int, nr_complex_t)
Definition: circuit.cpp:385
#define fState23
Definition: mutual2.cpp:112
qucs::matrix calcMatrixY(nr_double_t)
Definition: mutual2.cpp:42
#define VSRC_3
Definition: circuit.h:42
void setMatrixY(matrix)
Definition: circuit.cpp:685
void calcTR(nr_double_t)
Definition: mutual2.cpp:121
#define NODE_3
Definition: circuit.h:36
#define M_PI
Archimedes' constant ( )
Definition: consts.h:47
PROP_REQ[]
Definition: mutual2.cpp:172
void setMatrixS(matrix)
Definition: circuit.cpp:643
i2
Definition: parse_citi.y:160
#define fState33
Definition: mutual2.cpp:118
void allocMatrixMNA(void)
Definition: circuit.cpp:267
void initDC(void)
Definition: mutual2.cpp:89
#define PROP_POS_RANGEX
Definition: netdefs.h:131
PROP_OPT[]
Definition: mutual2.cpp:180
y
Definition: parse_mdl.y:499
#define NODE_1
Definition: circuit.h:34
void voltageSource(int, int, int, nr_double_t value=0.0)
Definition: circuit.cpp:748
#define fState12
Definition: mutual2.cpp:104
#define VSRC_2
Definition: circuit.h:41
#define fState13
Definition: mutual2.cpp:106
void setState(int, state_type_t, int n=0)
Definition: states.cpp:109
#define NODE_5
Definition: circuit.h:38
#define fState21
Definition: mutual2.cpp:108
void initTR(void)
Definition: mutual2.cpp:97
#define fState32
Definition: mutual2.cpp:116
#define fState22
Definition: mutual2.cpp:110