My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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: mutualx.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 "mutualx.h"
31 
32 mutualx::mutualx () : circuit () {
33  type = CIR_MUTUALX;
34  setVariableSized (true);
35 }
36 
37 void mutualx::calcSP (nr_double_t frequency) {
38  setMatrixS (ytos (calcMatrixY (frequency)));
39 }
40 
41 matrix mutualx::calcMatrixY (nr_double_t frequency) {
42 #if 1
43  matrix ts = ztos (calcMatrixZ (frequency));
44  matrix ty = stoy (ts);
45 #else
46  matrix ty = ztoy (calcMatrixZ (frequency));
47 #endif
48  int r, c;
49  int inductors = getSize () / 2;
50  matrix y = matrix (inductors * 2);
51 
52  for (r = 0; r < inductors; r++) {
53  for (c = 0; c < inductors; c++) {
54  y.set (2 * r + 0, 2 * c + 0, +ty (r, c));
55  y.set (2 * r + 1, 2 * c + 1, +ty (r, c));
56  y.set (2 * r + 0, 2 * c + 1, -ty (r, c));
57  y.set (2 * r + 1, 2 * c + 0, -ty (r, c));
58  }
59  }
60  return y;
61 }
62 
63 matrix mutualx::calcMatrixZ (nr_double_t frequency) {
64  int inductors = getSize () / 2;
65  int r, c, state;
66  vector * L = getPropertyVector ("L");
67  vector * C = getPropertyVector ("k");
68  nr_double_t o = 2 * M_PI * frequency;
69  matrix z = matrix (inductors);
70 
71  // fill Z-Matrix entries
72  for (state = 0, r = 0; r < inductors; r++) {
73  for (c = 0; c < inductors; c++, state++) {
74  nr_double_t l1 = real (L->get (r));
75  nr_double_t l2 = real (L->get (c));
76  nr_double_t k = real (C->get (state)) * sqrt (l1 * l2);
77  z.set (r, c, rect (0.0, k * o));
78  }
79  }
80  return z;
81 }
82 
83 void mutualx::initAC (void) {
84  initDC ();
85 }
86 
87 void mutualx::calcAC (nr_double_t frequency) {
88  int inductors = getSize () / 2;
89  int r, c, state;
90  vector * L = getPropertyVector ("L");
91  vector * C = getPropertyVector ("k");
92  nr_double_t o = 2 * M_PI * frequency;
93 
94  // fill D-Matrix
95  for (state = 0, r = 0; r < inductors; r++) {
96  for (c = 0; c < inductors; c++, state++) {
97  nr_double_t l1 = real (L->get (r));
98  nr_double_t l2 = real (L->get (c));
99  nr_double_t k = real (C->get (state)) * sqrt (l1 * l2);
100  setD (VSRC_1 + r, VSRC_1 + c, rect (0.0, k * o));
101  }
102  }
103 }
104 
105 void mutualx::initDC (void) {
106  int inductors = getSize () / 2;
107  setVoltageSources (inductors);
108  allocMatrixMNA ();
109  // fill C and B-Matrix entries
110  for (int i = 0; i < inductors; i++)
111  voltageSource (VSRC_1 + i, NODE_1 + i * 2, NODE_2 + i * 2);
112 }
113 
114 void mutualx::initTR (void) {
115  int inductors = getSize () / 2;
116  initDC ();
117  setStates (inductors * inductors * 2);
118 }
119 
120 void mutualx::calcTR (nr_double_t) {
121  int inductors = getSize () / 2;
122  int r, c, state;
123  vector * L = getPropertyVector ("L");
124  vector * C = getPropertyVector ("k");
125 
126  nr_double_t * veq = new nr_double_t[inductors * inductors];
127  nr_double_t * req = new nr_double_t[inductors * inductors];
128 
129  // integration for self and mutual inductances
130  for (state = 0, r = 0; r < inductors; r++) {
131  for (c = 0; c < inductors; c++, state++) {
132  nr_double_t l1 = real (L->get (r));
133  nr_double_t l2 = real (L->get (c));
134  nr_double_t i = real (getJ (VSRC_1 + c));
135  nr_double_t k = real (C->get (state)) * sqrt (l1 * l2);
136  setState (2 * state, i * k);
137  integrate (2 * state, k, req[state], veq[state]);
138  }
139  }
140 
141  // fill D-Matrix entries and extended RHS
142  for (state = 0, r = 0; r < inductors; r++) {
143  nr_double_t v = 0;
144  for (c = 0; c < inductors; c++, state++) {
145  setD (VSRC_1 + r, VSRC_1 + c, -req[state]);
146  v += veq[state];
147  }
148  setE (VSRC_1 + r, v);
149  }
150 
151  delete[] veq;
152  delete[] req;
153 }
154 
155 // properties
156 PROP_REQ [] = {
157  { "L", PROP_LIST, { 1e-9, PROP_NO_STR }, PROP_POS_RANGE },
158  { "k", PROP_LIST, { 0.9, PROP_NO_STR }, PROP_RNGII (-1, +1) },
159  PROP_NO_PROP };
160 PROP_OPT [] = {
161  PROP_NO_PROP };
162 struct define_t mutualx::cirdef =
163  { "MUTX",