Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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$
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 using namespace qucs;
33 
34 mutual::mutual () : circuit (4) {
35  type = CIR_MUTUAL;
36 }
37 
38 void mutual::calcSP (nr_double_t frequency) {
39 #if 0
40  setMatrixS (ytos (calcMatrixY (frequency)));
41 #else
42  nr_double_t l1 = getPropertyDouble ("L1");
43  nr_double_t l2 = getPropertyDouble ("L2");
44  nr_double_t k = getPropertyDouble ("k");
45  nr_double_t o = 2 * M_PI * frequency;
46  nr_double_t a = k * k - 1;
47  nr_complex_t d = nr_complex_t (o * o * l1 * l2 * a / 2 / z0 + 2 * z0, o * (l1 + l2));
49  r = nr_complex_t (2 * z0, o * l2) / d;
50  setS (NODE_1, NODE_4, r); setS (NODE_4, NODE_1, r);
51  r = 1.0 - r;
52  setS (NODE_1, NODE_1, r); setS (NODE_4, NODE_4, r);
53  r = nr_complex_t (2 * z0, o * l1) / d;
54  setS (NODE_2, NODE_3, r); setS (NODE_3, NODE_2, r);
55  r = 1.0 - r;
56  setS (NODE_2, NODE_2, r); setS (NODE_3, NODE_3, r);
57  r = nr_complex_t (0, o * k * std::sqrt (l1 * l2)) / d;
58  setS (NODE_1, NODE_2, r); setS (NODE_2, NODE_1, r);
59  setS (NODE_3, NODE_4, r); setS (NODE_4, NODE_3, r);
60  r = -r;
61  setS (NODE_1, NODE_3, r); setS (NODE_3, NODE_1, r);
62  setS (NODE_2, NODE_4, r); setS (NODE_4, NODE_2, r);
63 #endif
64 }
65 
66 matrix mutual::calcMatrixY (nr_double_t frequency) {
67  nr_double_t l1 = getPropertyDouble ("L1");
68  nr_double_t l2 = getPropertyDouble ("L2");
69  nr_double_t k = getPropertyDouble ("k");
70  nr_double_t o = 2 * M_PI * frequency;
71  nr_double_t a = 1 - k * k;
72  nr_complex_t z1 = nr_complex_t (0, o * l1 * a);
73  nr_complex_t z2 = nr_complex_t (0, o * l2 * a);
74  nr_complex_t y3 = nr_complex_t (0, k / (o * std::sqrt (l1 * l2) * a));
75 
76  matrix y = matrix (4);
77  y.set (NODE_1, NODE_1, +1.0 / z1); y.set (NODE_4, NODE_4, +1.0 / z1);
78  y.set (NODE_1, NODE_4, -1.0 / z1); y.set (NODE_4, NODE_1, -1.0 / z1);
79  y.set (NODE_2, NODE_2, +1.0 / z2); y.set (NODE_3, NODE_3, +1.0 / z2);
80  y.set (NODE_2, NODE_3, -1.0 / z2); y.set (NODE_3, NODE_2, -1.0 / z2);
81  y.set (NODE_1, NODE_3, -y3); y.set (NODE_3, NODE_1, -y3);
82  y.set (NODE_2, NODE_4, -y3); y.set (NODE_4, NODE_2, -y3);
83  y.set (NODE_1, NODE_2, +y3); y.set (NODE_2, NODE_1, +y3);
84  y.set (NODE_3, NODE_4, +y3); y.set (NODE_4, NODE_3, +y3);
85  return y;
86 }
87 
88 void mutual::initAC (void) {
90  allocMatrixMNA ();
91 }
92 
93 void mutual::calcAC (nr_double_t frequency) {
94  setMatrixY (calcMatrixY (frequency));
95 }
96 
97 void mutual::initDC (void) {
99  allocMatrixMNA ();
102 }
103 
104 void mutual::initTR (void) {
105  initDC ();
106  setStates (8);
107 }
108 
109 #define fState11 0 // flux state
110 #define vState11 1 // voltage state
111 #define fState22 2
112 #define vState22 3
113 #define fState12 4
114 #define vState12 5
115 #define fState21 6
116 #define vState21 7
117 
118 void mutual::calcTR (nr_double_t) {
119  nr_double_t k = getPropertyDouble ("k");
120  nr_double_t l1 = getPropertyDouble ("L1");
121  nr_double_t l2 = getPropertyDouble ("L2");
122  nr_double_t i1 = real (getJ (VSRC_1));
123  nr_double_t i2 = real (getJ (VSRC_2));
124  nr_double_t r11, r12, r21, r22, v11, v22, v12, v21;
125  nr_double_t M12 = k * std::sqrt (l1 * l2);
126 
127  // self inductances
128  setState (fState11, i1 * l1);
129  integrate (fState11, l1, r11, v11);
130  setState (fState22, i2 * l2);
131  integrate (fState22, l2, r22, v22);
132 
133  // mutual inductances
134  setState (fState12, i2 * M12);
135  integrate (fState12, M12, r12, v12);
136  setState (fState21, i1 * M12);
137  integrate (fState21, M12, r21, v21);
138 
139  setD (VSRC_1, VSRC_1, -r11); setD (VSRC_1, VSRC_2, -r12);
140  setD (VSRC_2, VSRC_2, -r22); setD (VSRC_2, VSRC_1, -r21);
141  setE (VSRC_1, v11 + v12);
142  setE (VSRC_2, v22 + v21);
143 }
144 
145 // properties
146 PROP_REQ [] = {
147  { "L1", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_POS_RANGEX },
148  { "L2", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_POS_RANGEX },
149  { "k", PROP_REAL, { 0.9, PROP_NO_STR }, PROP_RNGXX (-1, 1) },
150  PROP_NO_PROP };
151 PROP_OPT [] = {
152  PROP_NO_PROP };
153 struct define_t mutual::cirdef =
void calcTR(nr_double_t)
Definition: mutual.cpp:118
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
#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
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
PROP_REQ[]
Definition: mutual.cpp:146
void initDC(void)
Definition: mutual.cpp:97
#define PROP_NO_STR
Definition: netdefs.h:125
#define PROP_LINEAR
Definition: netdefs.h:120
static const nr_double_t z0
Definition: circuit.h:320
r
Definition: parse_mdl.y:515
qucs::matrix calcMatrixY(nr_double_t)
Definition: mutual.cpp:66
i1
Definition: parse_citi.y:148
void calcAC(nr_double_t)
Definition: mutual.cpp:93
#define fState22
Definition: mutual.cpp:111
#define NODE_4
Definition: circuit.h:37
#define VSRC_1
Definition: circuit.h:40
#define PROP_RNGXX(f, t)
Definition: netdefs.h:141
nr_complex_t sqrt(const nr_complex_t z)
Compute principal value of square root.
Definition: complex.cpp:271
#define fState12
Definition: mutual.cpp:113
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
void setMatrixY(matrix)
Definition: circuit.cpp:685
#define NODE_3
Definition: circuit.h:36
#define M_PI
Archimedes' constant ( )
Definition: consts.h:47
void setMatrixS(matrix)
Definition: circuit.cpp:643
i2
Definition: parse_citi.y:160
void allocMatrixMNA(void)
Definition: circuit.cpp:267
PROP_NO_SUBSTRATE
Definition: mutual.cpp:154
#define PROP_POS_RANGEX
Definition: netdefs.h:131
#define fState21
Definition: mutual.cpp:115
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
PROP_OPT[]
Definition: mutual.cpp:151
void setS(int, int, nr_complex_t)
Definition: circuit.cpp:587
void initTR(void)
Definition: mutual.cpp:104
#define VSRC_2
Definition: circuit.h:41
void setState(int, state_type_t, int n=0)
Definition: states.cpp:109
void initAC(void)
Definition: mutual.cpp:88
void calcSP(nr_double_t)
Definition: mutual.cpp:38
#define fState11
Definition: mutual.cpp:109