Qucs-core  0.0.19
mutual2.cpp
Go to the documentation of this file.
00001 /*
00002  * mutual2.cpp - three mutual inductors class implementation
00003  *
00004  * Copyright (C) 2005, 2008 Stefan Jahn <stefan@lkcc.org>
00005  *
00006  * This is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2, or (at your option)
00009  * any later version.
00010  *
00011  * This software is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this package; see the file COPYING.  If not, write to
00018  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  *
00021  * $Id$
00022  *
00023  */
00024 
00025 #if HAVE_CONFIG_H
00026 # include <config.h>
00027 #endif
00028 
00029 #include "component.h"
00030 #include "mutual2.h"
00031 
00032 using namespace qucs;
00033 
00034 mutual2::mutual2 () : circuit (6) {
00035   type = CIR_MUTUAL2;
00036 }
00037 
00038 void mutual2::calcSP (nr_double_t frequency) {
00039   setMatrixS (ytos (calcMatrixY (frequency)));
00040 }
00041 
00042 matrix mutual2::calcMatrixY (nr_double_t frequency) {
00043   nr_double_t k12 = getPropertyDouble ("k12");
00044   nr_double_t k13 = getPropertyDouble ("k13");
00045   nr_double_t k23 = getPropertyDouble ("k23");
00046   nr_double_t l1 = getPropertyDouble ("L1");
00047   nr_double_t l2 = getPropertyDouble ("L2");
00048   nr_double_t l3 = getPropertyDouble ("L3");
00049   nr_double_t o = 2 * pi * frequency;
00050   nr_double_t a = 1 - k12 * k12 - k13 * k13 - k23 * k23 + 2 * k12 * k13 * k23;
00051   nr_complex_t y11 = nr_complex_t (0, (k23 * k23 - 1) / l1 / a / o);
00052   nr_complex_t y22 = nr_complex_t (0, (k12 * k12 - 1) / l3 / a / o);
00053   nr_complex_t y44 = nr_complex_t (0, (k13 * k13 - 1) / l2 / a / o);
00054   nr_complex_t y12 = nr_complex_t (0, (k13 - k12 * k23) / std::sqrt (l1 * l3) / a / o);
00055   nr_complex_t y15 = nr_complex_t (0, (k12 - k13 * k23) / std::sqrt (l1 * l2) / a / o);
00056   nr_complex_t y25 = nr_complex_t (0, (k23 - k12 * k13) / std::sqrt (l2 * l3) / a / o);
00057 
00058   matrix y = matrix (6);
00059   y.set (NODE_1, NODE_1, +y11); y.set (NODE_6, NODE_6, +y11);
00060   y.set (NODE_1, NODE_6, -y11); y.set (NODE_6, NODE_1, -y11);
00061   y.set (NODE_2, NODE_2, +y22); y.set (NODE_3, NODE_3, +y22);
00062   y.set (NODE_2, NODE_3, -y22); y.set (NODE_3, NODE_2, -y22);
00063   y.set (NODE_4, NODE_4, +y44); y.set (NODE_5, NODE_5, +y44);
00064   y.set (NODE_4, NODE_5, -y44); y.set (NODE_5, NODE_4, -y44);
00065   y.set (NODE_1, NODE_2, +y12); y.set (NODE_2, NODE_1, +y12);
00066   y.set (NODE_3, NODE_6, +y12); y.set (NODE_6, NODE_3, +y12);
00067   y.set (NODE_1, NODE_3, -y12); y.set (NODE_3, NODE_1, -y12);
00068   y.set (NODE_2, NODE_6, -y12); y.set (NODE_6, NODE_2, -y12);
00069   y.set (NODE_1, NODE_5, +y15); y.set (NODE_5, NODE_1, +y15);
00070   y.set (NODE_4, NODE_6, +y15); y.set (NODE_6, NODE_4, +y15);
00071   y.set (NODE_1, NODE_4, -y15); y.set (NODE_4, NODE_1, -y15);
00072   y.set (NODE_5, NODE_6, -y15); y.set (NODE_6, NODE_5, -y15);
00073   y.set (NODE_2, NODE_5, +y25); y.set (NODE_5, NODE_2, +y25);
00074   y.set (NODE_4, NODE_3, +y25); y.set (NODE_3, NODE_4, +y25);
00075   y.set (NODE_2, NODE_4, -y25); y.set (NODE_4, NODE_2, -y25);
00076   y.set (NODE_5, NODE_3, -y25); y.set (NODE_3, NODE_5, -y25);
00077   return y;
00078 }
00079 
00080 void mutual2::initAC (void) {
00081   setVoltageSources (0);
00082   allocMatrixMNA ();
00083 }
00084 
00085 void mutual2::calcAC (nr_double_t frequency) {
00086   setMatrixY (calcMatrixY (frequency));
00087 }
00088 
00089 void mutual2::initDC (void) {
00090   setVoltageSources (3);
00091   allocMatrixMNA ();
00092   voltageSource (VSRC_1, NODE_1, NODE_6);
00093   voltageSource (VSRC_2, NODE_5, NODE_4);
00094   voltageSource (VSRC_3, NODE_2, NODE_3);
00095 }
00096 
00097 void mutual2::initTR (void) {
00098   initDC ();
00099   setStates (18);
00100 }
00101 
00102 #define fState11  0 // flux state
00103 #define vState11  1 // voltage state
00104 #define fState12  2
00105 #define vState12  3
00106 #define fState13  4
00107 #define vState13  5
00108 #define fState21  6
00109 #define vState21  7
00110 #define fState22  8
00111 #define vState22  9
00112 #define fState23 10
00113 #define vState23 11
00114 #define fState31 12
00115 #define vState31 13
00116 #define fState32 14
00117 #define vState32 15
00118 #define fState33 16
00119 #define vState33 17
00120 
00121 void mutual2::calcTR (nr_double_t) {
00122   nr_double_t k12 = getPropertyDouble ("k12");
00123   nr_double_t k13 = getPropertyDouble ("k13");
00124   nr_double_t k23 = getPropertyDouble ("k23");
00125   nr_double_t l1  = getPropertyDouble ("L1");
00126   nr_double_t l2  = getPropertyDouble ("L2");
00127   nr_double_t l3  = getPropertyDouble ("L3");
00128   nr_double_t M12 = k12 * std::sqrt (l1 * l2);
00129   nr_double_t M13 = k13 * std::sqrt (l1 * l3);
00130   nr_double_t M23 = k23 * std::sqrt (l2 * l3);
00131   nr_double_t r11, r12, r13, r21, r22, r23, r31, r32, r33;
00132   nr_double_t v11, v12, v13, v21, v22, v23, v31, v32, v33;
00133   nr_double_t i1 = real (getJ (VSRC_1));
00134   nr_double_t i2 = real (getJ (VSRC_2));
00135   nr_double_t i3 = real (getJ (VSRC_3));
00136 
00137   setState  (fState11, i1 * l1);
00138   integrate (fState11, l1, r11, v11);
00139   setState  (fState22, i2 * l2);
00140   integrate (fState22, l2, r22, v22);
00141   setState  (fState33, i3 * l3);
00142   integrate (fState33, l3, r33, v33);
00143 
00144   setState  (fState12, i2 * M12);
00145   integrate (fState12, M12, r12, v12);
00146   setState  (fState13, i3 * M13);
00147   integrate (fState13, M13, r13, v13);
00148   setState  (fState21, i1 * M12);
00149   integrate (fState21, M12, r21, v21);
00150   setState  (fState23, i3 * M23);
00151   integrate (fState23, M23, r23, v23);
00152   setState  (fState31, i1 * M13);
00153   integrate (fState31, M13, r31, v31);
00154   setState  (fState32, i2 * M23);
00155   integrate (fState32, M23, r32, v32);
00156 
00157   setD (VSRC_1, VSRC_1, -r11);
00158   setD (VSRC_1, VSRC_2, -r12);
00159   setD (VSRC_1, VSRC_3, -r13);
00160   setD (VSRC_2, VSRC_1, -r21);
00161   setD (VSRC_2, VSRC_2, -r22);
00162   setD (VSRC_2, VSRC_3, -r23);
00163   setD (VSRC_3, VSRC_1, -r31);
00164   setD (VSRC_3, VSRC_2, -r32);
00165   setD (VSRC_3, VSRC_3, -r33);
00166   setE (VSRC_1, v11 + v12 + v13);
00167   setE (VSRC_2, v21 + v22 + v23);
00168   setE (VSRC_3, v31 + v32 + v33);
00169 }
00170 
00171 // properties
00172 PROP_REQ [] = {
00173   { "L1", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_POS_RANGEX },
00174   { "L2", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_POS_RANGEX },
00175   { "L3", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_POS_RANGEX },
00176   { "k12", PROP_REAL, { 0.9, PROP_NO_STR }, PROP_RNGXX (-1, 1) },
00177   { "k13", PROP_REAL, { 0.9, PROP_NO_STR }, PROP_RNGXX (-1, 1) },
00178   { "k23", PROP_REAL, { 0.9, PROP_NO_STR }, PROP_RNGXX (-1, 1) },
00179   PROP_NO_PROP };
00180 PROP_OPT [] = {
00181   PROP_NO_PROP };
00182 struct define_t mutual2::cirdef =
00183   { "MUT2", 6, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };