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