Qucs-core
0.0.19
|
00001 /* 00002 * cccs.cpp - cccs class implementation 00003 * 00004 * Copyright (C) 2003, 2004, 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 "cccs.h" 00031 00032 using namespace qucs; 00033 00034 cccs::cccs () : circuit (4) { 00035 type = CIR_CCCS; 00036 setVoltageSources (1); 00037 } 00038 00039 void cccs::calcSP (nr_double_t frequency) { 00040 00041 nr_double_t g = getPropertyDouble ("G"); 00042 nr_double_t t = getPropertyDouble ("T"); 00043 00044 nr_complex_t z1 = qucs::polar (g, pi - 2.0 * pi * frequency * t); 00045 nr_complex_t z2 = qucs::polar (g, - 2.0 * pi * frequency * t); 00046 00047 setS (NODE_1, NODE_1, 0.0); setS (NODE_1, NODE_2, 0.0); 00048 setS (NODE_1, NODE_3, 0.0); setS (NODE_1, NODE_4, 1.0); 00049 setS (NODE_2, NODE_1, z1); setS (NODE_2, NODE_2, 1.0); 00050 setS (NODE_2, NODE_3, 0.0); setS (NODE_2, NODE_4, z2); 00051 setS (NODE_3, NODE_1, z2); setS (NODE_3, NODE_2, 0.0); 00052 setS (NODE_3, NODE_3, 1.0); setS (NODE_3, NODE_4, z1); 00053 setS (NODE_4, NODE_1, 1.0); setS (NODE_4, NODE_2, 0.0); 00054 setS (NODE_4, NODE_3, 0.0); setS (NODE_4, NODE_4, 0.0); 00055 } 00056 00057 void cccs::initDC (void) { 00058 setISource (false); 00059 allocMatrixMNA (); 00060 nr_double_t g = getPropertyDouble ("G"); 00061 setC (VSRC_1, NODE_1, +1.0); setC (VSRC_1, NODE_2, +0.0); 00062 setC (VSRC_1, NODE_3, +0.0); setC (VSRC_1, NODE_4, -1.0); 00063 setB (NODE_1, VSRC_1, +1/g); setB (NODE_2, VSRC_1, +1.0); 00064 setB (NODE_3, VSRC_1, -1.0); setB (NODE_4, VSRC_1, -1/g); 00065 setD (VSRC_1, VSRC_1, 0.0); 00066 setE (VSRC_1, 0.0); 00067 } 00068 00069 void cccs::initAC (void) { 00070 initDC (); 00071 } 00072 00073 void cccs::calcAC (nr_double_t frequency) { 00074 nr_double_t g = getPropertyDouble ("G"); 00075 nr_double_t t = getPropertyDouble ("T"); 00076 nr_complex_t r = qucs::polar (1.0 / g, - 2.0 * pi * frequency * t); 00077 setB (NODE_1, VSRC_1, +r); setB (NODE_4, VSRC_1, -r); 00078 } 00079 00080 void cccs::initTR (void) { 00081 nr_double_t t = getPropertyDouble ("T"); 00082 initDC (); 00083 deleteHistory (); 00084 if (t > 0.0) { 00085 setISource (true); 00086 setHistory (true); 00087 initHistory (t); 00088 setB (NODE_1, VSRC_1, +1.0); setB (NODE_2, VSRC_1, +0.0); 00089 setB (NODE_3, VSRC_1, -0.0); setB (NODE_4, VSRC_1, -1.0); 00090 } 00091 } 00092 00093 void cccs::calcTR (nr_double_t t) { 00094 nr_double_t T = getPropertyDouble ("T"); 00095 if (T > 0.0) { 00096 T = t - T; 00097 nr_double_t g = getPropertyDouble ("G"); 00098 nr_double_t i = getJ (VSRC_1, T); 00099 setI (NODE_2, -g * i); 00100 setI (NODE_3, +g * i); 00101 } 00102 } 00103 00104 // properties 00105 PROP_REQ [] = { 00106 { "G", PROP_REAL, { 1, PROP_NO_STR }, PROP_NO_RANGE }, PROP_NO_PROP }; 00107 PROP_OPT [] = { 00108 { "T", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE }, PROP_NO_PROP }; 00109 struct define_t cccs::cirdef = 00110 { "CCCS", 4, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };