My Project
0.0.16
QUCS Mapping
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
DownLoad
QUCS-src
qucs-0.0.16
qucs-core
src
components
mutual.cpp
Go to the documentation of this file.
1
/*
2
* mutual.cpp - two mutual inductors class implementation
3
*
4
* Copyright (C) 2005, 2006, 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: mutual.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 "
mutual.h
"
31
32
mutual::mutual () :
circuit
(4) {
33
type =
CIR_MUTUAL
;
34
}
35
36
void
mutual::calcSP
(nr_double_t frequency) {
37
#if 0
38
setMatrixS
(
ytos
(calcMatrixY (frequency)));
39
#else
40
nr_double_t l1 =
getPropertyDouble
(
"L1"
);
41
nr_double_t l2 =
getPropertyDouble
(
"L2"
);
42
nr_double_t k =
getPropertyDouble
(
"k"
);
43
nr_double_t o = 2 *
M_PI
* frequency;
44
nr_double_t a = k * k - 1;
45
nr_complex_t
d =
rect
(o * o * l1 * l2 * a / 2 /
z0
+ 2 *
z0
, o * (l1 + l2));
46
nr_complex_t
r;
47
r =
rect
(2 *
z0
, o * l2) / d;
48
setS
(
NODE_1
,
NODE_4
, r);
setS
(
NODE_4
,
NODE_1
, r);
49
r = 1.0 - r;
50
setS
(
NODE_1
,
NODE_1
, r);
setS
(
NODE_4
,
NODE_4
, r);
51
r =
rect
(2 *
z0
, o * l1) / d;
52
setS
(
NODE_2
,
NODE_3
, r);
setS
(
NODE_3
,
NODE_2
, r);
53
r = 1.0 - r;
54
setS
(
NODE_2
,
NODE_2
, r);
setS
(
NODE_3
,
NODE_3
, r);
55
r =
rect
(0, o * k *
sqrt
(l1 * l2)) / d;
56
setS
(
NODE_1
,
NODE_2
, r);
setS
(
NODE_2
,
NODE_1
, r);
57
setS
(
NODE_3
,
NODE_4
, r);
setS
(
NODE_4
,
NODE_3
, r);
58
r = -r;
59
setS
(
NODE_1
,
NODE_3
, r);
setS
(
NODE_3
,
NODE_1
, r);
60
setS
(
NODE_2
,
NODE_4
, r);
setS
(
NODE_4
,
NODE_2
, r);
61
#endif
62
}
63
64
matrix
mutual::calcMatrixY (nr_double_t frequency) {
65
nr_double_t l1 =
getPropertyDouble
(
"L1"
);
66
nr_double_t l2 =
getPropertyDouble
(
"L2"
);
67
nr_double_t k =
getPropertyDouble
(
"k"
);
68
nr_double_t o = 2 *
M_PI
* frequency;
69
nr_double_t a = 1 - k * k;
70
nr_complex_t
z1 =
rect
(0, o * l1 * a);
71
nr_complex_t
z2 =
rect
(0, o * l2 * a);
72
nr_complex_t
y3 =
rect
(0, k / (o *
sqrt
(l1 * l2) * a));
73
74
matrix
y =
matrix
(4);
75
y.
set
(
NODE_1
,
NODE_1
, +1.0 / z1); y.
set
(
NODE_4
,
NODE_4
, +1.0 / z1);
76
y.
set
(
NODE_1
,
NODE_4
, -1.0 / z1); y.
set
(
NODE_4
,
NODE_1
, -1.0 / z1);
77
y.
set
(
NODE_2
,
NODE_2
, +1.0 / z2); y.
set
(
NODE_3
,
NODE_3
, +1.0 / z2);
78
y.
set
(
NODE_2
,
NODE_3
, -1.0 / z2); y.
set
(
NODE_3
,
NODE_2
, -1.0 / z2);
79
y.
set
(
NODE_1
,
NODE_3
, -y3); y.
set
(
NODE_3
,
NODE_1
, -y3);
80
y.
set
(
NODE_2
,
NODE_4
, -y3); y.
set
(
NODE_4
,
NODE_2
, -y3);
81
y.
set
(
NODE_1
,
NODE_2
, +y3); y.
set
(
NODE_2
,
NODE_1
, +y3);
82
y.
set
(
NODE_3
,
NODE_4
, +y3); y.
set
(
NODE_4
,
NODE_3
, +y3);
83
return
y;
84
}
85
86
void
mutual::initAC
(
void
) {
87
setVoltageSources
(0);
88
allocMatrixMNA
();
89
}
90
91
void
mutual::calcAC
(nr_double_t frequency) {
92
setMatrixY
(calcMatrixY (frequency));
93
}
94
95
void
mutual::initDC
(
void
) {
96
setVoltageSources
(2);
97
allocMatrixMNA
();
98
voltageSource
(
VSRC_1
,
NODE_1
,
NODE_4
);
99
voltageSource
(
VSRC_2
,
NODE_2
,
NODE_3
);
100
}
101
102
void
mutual::initTR
(
void
) {
103
initDC
();
104
setStates
(8);
105
}
106
107
#define fState11 0 // flux state
108
#define vState11 1 // voltage state
109
#define fState22 2
110
#define vState22 3
111
#define fState12 4
112
#define vState12 5
113
#define fState21 6
114
#define vState21 7
115
116
void
mutual::calcTR
(nr_double_t) {
117
nr_double_t k =
getPropertyDouble
(
"k"
);
118
nr_double_t l1 =
getPropertyDouble
(
"L1"
);
119
nr_double_t l2 =
getPropertyDouble
(
"L2"
);
120
nr_double_t i1 =
real
(
getJ
(
VSRC_1
));
121
nr_double_t i2 =
real
(
getJ
(
VSRC_2
));
122
nr_double_t r11, r12, r21, r22, v11, v22, v12, v21;
123
nr_double_t M12 = k *
sqrt
(l1 * l2);
124
125
// self inductances
126
setState
(
fState11
, i1 * l1);
127
integrate
(
fState11
, l1, r11, v11);
128
setState
(
fState22
, i2 * l2);
129
integrate
(
fState22
, l2, r22, v22);
130
131
// mutual inductances
132
setState
(
fState12
, i2 * M12);
133
integrate
(
fState12
, M12, r12, v12);
134
setState
(
fState21
, i1 * M12);
135
integrate
(
fState21
, M12, r21, v21);
136
137
setD
(
VSRC_1
,
VSRC_1
, -r11);
setD
(
VSRC_1
,
VSRC_2
, -r12);
138
setD
(
VSRC_2
,
VSRC_2
, -r22);
setD
(
VSRC_2
,
VSRC_1
, -r21);
139
setE
(
VSRC_1
, v11 + v12);
140
setE
(
VSRC_2
, v22 + v21);
141
}
142
143
// properties
144
PROP_REQ
[] = {
145
{
"L1"
,
PROP_REAL
, { 1
e
-3,
PROP_NO_STR
},
PROP_POS_RANGEX
},
146
{
"L2"
,
PROP_REAL
, { 1
e
-3,
PROP_NO_STR
},
PROP_POS_RANGEX
},
147
{
"k"
,
PROP_REAL
, { 0.9,
PROP_NO_STR
},
PROP_RNGXX
(-1, 1) },
148
PROP_NO_PROP
};
149
PROP_OPT
[] = {
150
PROP_NO_PROP
};
151
struct
define_t
mutual
::cirdef =
152
{
"MUT"
, 4,
PROP_COMPONENT
,
PROP_NO_SUBSTRATE
,
PROP_LINEAR
,
PROP_DEF
};
Generated on Tue Dec 25 2012 14:30:40 for My Project by
1.8.2