Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mutualx.cpp
Go to the documentation of this file.
1 /*
2  * mutualx.cpp - multiple mutual inductors class implementation
3  *
4  * Copyright (C) 2007, 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 "mutualx.h"
31 
32 using namespace qucs;
33 
34 mutualx::mutualx () : circuit () {
35  type = CIR_MUTUALX;
36  setVariableSized (true);
37 }
38 
39 void mutualx::calcSP (nr_double_t frequency) {
40  setMatrixS (ytos (calcMatrixY (frequency)));
41 }
42 
43 matrix mutualx::calcMatrixY (nr_double_t frequency) {
44 #if 1
45  matrix ts = ztos (calcMatrixZ (frequency));
46  matrix ty = stoy (ts);
47 #else
48  matrix ty = ztoy (calcMatrixZ (frequency));
49 #endif
50  int r, c;
51  int inductors = getSize () / 2;
52  matrix y = matrix (inductors * 2);
53 
54  for (r = 0; r < inductors; r++) {
55  for (c = 0; c < inductors; c++) {
56  y.set (2 * r + 0, 2 * c + 0, +ty (r, c));
57  y.set (2 * r + 1, 2 * c + 1, +ty (r, c));
58  y.set (2 * r + 0, 2 * c + 1, -ty (r, c));
59  y.set (2 * r + 1, 2 * c + 0, -ty (r, c));
60  }
61  }
62  return y;
63 }
64 
65 matrix mutualx::calcMatrixZ (nr_double_t frequency) {
66  int inductors = getSize () / 2;
67  int r, c, state;
68  qucs::vector * L = getPropertyVector ("L");
70  nr_double_t o = 2 * M_PI * frequency;
71  matrix z = matrix (inductors);
72 
73  // fill Z-Matrix entries
74  for (state = 0, r = 0; r < inductors; r++) {
75  for (c = 0; c < inductors; c++, state++) {
76  nr_double_t l1 = real (L->get (r));
77  nr_double_t l2 = real (L->get (c));
78  nr_double_t k = real (C->get (state)) * std::sqrt (l1 * l2);
79  z.set (r, c, nr_complex_t (0.0, k * o));
80  }
81  }
82  return z;
83 }
84 
85 void mutualx::initAC (void) {
86  initDC ();
87 }
88 
89 void mutualx::calcAC (nr_double_t frequency) {
90  int inductors = getSize () / 2;
91  int r, c, state;
92  qucs::vector * L = getPropertyVector ("L");
94  nr_double_t o = 2 * M_PI * frequency;
95 
96  // fill D-Matrix
97  for (state = 0, r = 0; r < inductors; r++) {
98  for (c = 0; c < inductors; c++, state++) {
99  nr_double_t l1 = real (L->get (r));
100  nr_double_t l2 = real (L->get (c));
101  nr_double_t k = real (C->get (state)) * std::sqrt (l1 * l2);
102  setD (VSRC_1 + r, VSRC_1 + c, nr_complex_t (0.0, k * o));
103  }
104  }
105 }
106 
107 void mutualx::initDC (void) {
108  int inductors = getSize () / 2;
109  setVoltageSources (inductors);
110  allocMatrixMNA ();
111  // fill C and B-Matrix entries
112  for (int i = 0; i < inductors; i++)
113  voltageSource (VSRC_1 + i, NODE_1 + i * 2, NODE_2 + i * 2);
114 }
115 
116 void mutualx::initTR (void) {
117  int inductors = getSize () / 2;
118  initDC ();
119  setStates (inductors * inductors * 2);
120 }
121 
122 void mutualx::calcTR (nr_double_t) {
123  int inductors = getSize () / 2;
124  int r, c, state;
125  qucs::vector * L = getPropertyVector ("L");
126  qucs::vector * C = getPropertyVector ("k");
127 
128  nr_double_t * veq = new nr_double_t[inductors * inductors];
129  nr_double_t * req = new nr_double_t[inductors * inductors];
130 
131  // integration for self and mutual inductances
132  for (state = 0, r = 0; r < inductors; r++) {
133  for (c = 0; c < inductors; c++, state++) {
134  nr_double_t l1 = real (L->get (r));
135  nr_double_t l2 = real (L->get (c));
136  nr_double_t i = real (getJ (VSRC_1 + c));
137  nr_double_t k = real (C->get (state)) * std::sqrt (l1 * l2);
138  setState (2 * state, i * k);
139  integrate (2 * state, k, req[state], veq[state]);
140  }
141  }
142 
143  // fill D-Matrix entries and extended RHS
144  for (state = 0, r = 0; r < inductors; r++) {
145  nr_double_t v = 0;
146  for (c = 0; c < inductors; c++, state++) {
147  setD (VSRC_1 + r, VSRC_1 + c, -req[state]);
148  v += veq[state];
149  }
150  setE (VSRC_1 + r, v);
151  }
152 
153  delete[] veq;
154  delete[] req;
155 }
156 
157 // properties
158 PROP_REQ [] = {
159  { "L", PROP_LIST, { 1e-9, PROP_NO_STR }, PROP_POS_RANGE },
160  { "k", PROP_LIST, { 0.9, PROP_NO_STR }, PROP_RNGII (-1, +1) },
161  PROP_NO_PROP };
162 PROP_OPT [] = {
163  PROP_NO_PROP };
164 struct define_t mutualx::cirdef =
165  { "MUTX",
std::complex< nr_double_t > nr_complex_t
Definition: complex.h:31
#define PROP_POS_RANGE
Definition: netdefs.h:129
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_RNGII(f, t)
Definition: netdefs.h:138
#define PROP_DEF
Definition: netdefs.h:189
void integrate(int, nr_double_t, nr_double_t &, nr_double_t &)
Definition: integrator.cpp:67
qucs::matrix calcMatrixZ(nr_double_t)
Definition: mutualx.cpp:65
#define C(c)
Definition: eqndefined.cpp:73
void setD(int, int, nr_complex_t)
Definition: circuit.cpp:373
void setStates(int n)
Definition: states.h:52
qucs::matrix calcMatrixY(nr_double_t)
Definition: mutualx.cpp:43
#define PROP_NO_PROP
Definition: netdefs.h:122
void setVoltageSources(int)
Definition: circuit.cpp:607
#define PROP_NO_STR
Definition: netdefs.h:125
PROP_OPT[]
Definition: mutualx.cpp:162
#define PROP_LINEAR
Definition: netdefs.h:120
void calcSP(nr_double_t)
Definition: mutualx.cpp:39
r
Definition: parse_mdl.y:515
int getSize(void)
Get the number of ports the circuit element has.
Definition: circuit.h:143
vector * getPropertyVector(const char *)
Definition: object.cpp:150
void initTR(void)
Definition: mutualx.cpp:116
#define VSRC_1
Definition: circuit.h:40
i
Definition: parse_mdl.y:516
void initAC(void)
Definition: mutualx.cpp:85
nr_complex_t sqrt(const nr_complex_t z)
Compute principal value of square root.
Definition: complex.cpp:271
matrix stoy(matrix s, qucs::vector z0)
Scattering parameters to admittance matrix.
Definition: matrix.cpp:1082
nr_double_t getJ(int, nr_double_t)
Definition: circuit.cpp:951
#define PROP_COMPONENT
Definition: netdefs.h:116
matrix ztos(matrix z, qucs::vector z0)
Convert impedance matrix scattering parameters.
Definition: matrix.cpp:1018
void calcTR(nr_double_t)
Definition: mutualx.cpp:122
void setE(int, nr_complex_t)
Definition: circuit.cpp:385
PROP_REQ[]
Definition: mutualx.cpp:158
void initDC(void)
Definition: mutualx.cpp:107
#define M_PI
Archimedes' constant ( )
Definition: consts.h:47
void setMatrixS(matrix)
Definition: circuit.cpp:643
v
Definition: parse_zvr.y:141
void allocMatrixMNA(void)
Definition: circuit.cpp:267
y
Definition: parse_mdl.y:499
void setVariableSized(bool v)
Definition: circuit.h:169
#define NODE_1
Definition: circuit.h:34
void voltageSource(int, int, int, nr_double_t value=0.0)
Definition: circuit.cpp:748
void calcAC(nr_double_t)
Definition: mutualx.cpp:89
#define PROP_LIST
Definition: netdefs.h:176
void setState(int, state_type_t, int n=0)
Definition: states.cpp:109
matrix ztoy(matrix z)
impedance matrix to admittance matrix.
Definition: matrix.cpp:1050
nr_complex_t get(int)
Definition: vector.cpp:179
#define PROP_NO_SUBSTRATE
Definition: netdefs.h:118