Qucs-core
0.0.19
|
00001 /* 00002 * mutual.cpp - two mutual inductors class implementation 00003 * 00004 * Copyright (C) 2005, 2006, 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 "mutual.h" 00031 00032 using namespace qucs; 00033 00034 mutual::mutual () : circuit (4) { 00035 type = CIR_MUTUAL; 00036 } 00037 00038 void mutual::calcSP (nr_double_t frequency) { 00039 #if 0 00040 setMatrixS (ytos (calcMatrixY (frequency))); 00041 #else 00042 nr_double_t l1 = getPropertyDouble ("L1"); 00043 nr_double_t l2 = getPropertyDouble ("L2"); 00044 nr_double_t k = getPropertyDouble ("k"); 00045 nr_double_t o = 2 * pi * frequency; 00046 nr_double_t a = k * k - 1; 00047 nr_complex_t d = nr_complex_t (o * o * l1 * l2 * a / 2 / z0 + 2 * z0, o * (l1 + l2)); 00048 nr_complex_t r; 00049 r = nr_complex_t (2 * z0, o * l2) / d; 00050 setS (NODE_1, NODE_4, r); setS (NODE_4, NODE_1, r); 00051 r = 1.0 - r; 00052 setS (NODE_1, NODE_1, r); setS (NODE_4, NODE_4, r); 00053 r = nr_complex_t (2 * z0, o * l1) / d; 00054 setS (NODE_2, NODE_3, r); setS (NODE_3, NODE_2, r); 00055 r = 1.0 - r; 00056 setS (NODE_2, NODE_2, r); setS (NODE_3, NODE_3, r); 00057 r = nr_complex_t (0, o * k * std::sqrt (l1 * l2)) / d; 00058 setS (NODE_1, NODE_2, r); setS (NODE_2, NODE_1, r); 00059 setS (NODE_3, NODE_4, r); setS (NODE_4, NODE_3, r); 00060 r = -r; 00061 setS (NODE_1, NODE_3, r); setS (NODE_3, NODE_1, r); 00062 setS (NODE_2, NODE_4, r); setS (NODE_4, NODE_2, r); 00063 #endif 00064 } 00065 00066 matrix mutual::calcMatrixY (nr_double_t frequency) { 00067 nr_double_t l1 = getPropertyDouble ("L1"); 00068 nr_double_t l2 = getPropertyDouble ("L2"); 00069 nr_double_t k = getPropertyDouble ("k"); 00070 nr_double_t o = 2 * pi * frequency; 00071 nr_double_t a = 1 - k * k; 00072 nr_complex_t z1 = nr_complex_t (0, o * l1 * a); 00073 nr_complex_t z2 = nr_complex_t (0, o * l2 * a); 00074 nr_complex_t y3 = nr_complex_t (0, k / (o * std::sqrt (l1 * l2) * a)); 00075 00076 matrix y = matrix (4); 00077 y.set (NODE_1, NODE_1, +1.0 / z1); y.set (NODE_4, NODE_4, +1.0 / z1); 00078 y.set (NODE_1, NODE_4, -1.0 / z1); y.set (NODE_4, NODE_1, -1.0 / z1); 00079 y.set (NODE_2, NODE_2, +1.0 / z2); y.set (NODE_3, NODE_3, +1.0 / z2); 00080 y.set (NODE_2, NODE_3, -1.0 / z2); y.set (NODE_3, NODE_2, -1.0 / z2); 00081 y.set (NODE_1, NODE_3, -y3); y.set (NODE_3, NODE_1, -y3); 00082 y.set (NODE_2, NODE_4, -y3); y.set (NODE_4, NODE_2, -y3); 00083 y.set (NODE_1, NODE_2, +y3); y.set (NODE_2, NODE_1, +y3); 00084 y.set (NODE_3, NODE_4, +y3); y.set (NODE_4, NODE_3, +y3); 00085 return y; 00086 } 00087 00088 void mutual::initAC (void) { 00089 setVoltageSources (0); 00090 allocMatrixMNA (); 00091 } 00092 00093 void mutual::calcAC (nr_double_t frequency) { 00094 setMatrixY (calcMatrixY (frequency)); 00095 } 00096 00097 void mutual::initDC (void) { 00098 setVoltageSources (2); 00099 allocMatrixMNA (); 00100 voltageSource (VSRC_1, NODE_1, NODE_4); 00101 voltageSource (VSRC_2, NODE_2, NODE_3); 00102 } 00103 00104 void mutual::initTR (void) { 00105 initDC (); 00106 setStates (8); 00107 } 00108 00109 #define fState11 0 // flux state 00110 #define vState11 1 // voltage state 00111 #define fState22 2 00112 #define vState22 3 00113 #define fState12 4 00114 #define vState12 5 00115 #define fState21 6 00116 #define vState21 7 00117 00118 void mutual::calcTR (nr_double_t) { 00119 nr_double_t k = getPropertyDouble ("k"); 00120 nr_double_t l1 = getPropertyDouble ("L1"); 00121 nr_double_t l2 = getPropertyDouble ("L2"); 00122 nr_double_t i1 = real (getJ (VSRC_1)); 00123 nr_double_t i2 = real (getJ (VSRC_2)); 00124 nr_double_t r11, r12, r21, r22, v11, v22, v12, v21; 00125 nr_double_t M12 = k * std::sqrt (l1 * l2); 00126 00127 // self inductances 00128 setState (fState11, i1 * l1); 00129 integrate (fState11, l1, r11, v11); 00130 setState (fState22, i2 * l2); 00131 integrate (fState22, l2, r22, v22); 00132 00133 // mutual inductances 00134 setState (fState12, i2 * M12); 00135 integrate (fState12, M12, r12, v12); 00136 setState (fState21, i1 * M12); 00137 integrate (fState21, M12, r21, v21); 00138 00139 setD (VSRC_1, VSRC_1, -r11); setD (VSRC_1, VSRC_2, -r12); 00140 setD (VSRC_2, VSRC_2, -r22); setD (VSRC_2, VSRC_1, -r21); 00141 setE (VSRC_1, v11 + v12); 00142 setE (VSRC_2, v22 + v21); 00143 } 00144 00145 // properties 00146 PROP_REQ [] = { 00147 { "L1", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_POS_RANGEX }, 00148 { "L2", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_POS_RANGEX }, 00149 { "k", PROP_REAL, { 0.9, PROP_NO_STR }, PROP_RNGXX (-1, 1) }, 00150 PROP_NO_PROP }; 00151 PROP_OPT [] = { 00152 PROP_NO_PROP }; 00153 struct define_t mutual::cirdef = 00154 { "MUT", 4, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };