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