Qucs-core  0.0.19
ccvs.cpp
Go to the documentation of this file.
00001 /*
00002  * ccvs.cpp - ccvs 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 "ccvs.h"
00031 
00032 using namespace qucs;
00033 
00034 ccvs::ccvs () : circuit (4) {
00035   type = CIR_CCVS;
00036   setVoltageSources (2);
00037 }
00038 
00039 void ccvs::calcSP (nr_double_t frequency) {
00040 
00041   nr_double_t g = getPropertyDouble ("G") / z0;
00042   nr_double_t t = getPropertyDouble ("T");
00043 
00044   nr_complex_t z1 = qucs::polar (g / 2.0, pi - 2.0 * pi * frequency * t);
00045   nr_complex_t z2 = qucs::polar (g / 2.0, - 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, 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, 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 ccvs::initDC (void) {
00058   allocMatrixMNA ();
00059   setB (NODE_1, VSRC_1, +1.0); setB (NODE_2, VSRC_1, +0.0);
00060   setB (NODE_3, VSRC_1, +0.0); setB (NODE_4, VSRC_1, -1.0);
00061   setB (NODE_1, VSRC_2, +0.0); setB (NODE_2, VSRC_2, -1.0);
00062   setB (NODE_3, VSRC_2, +1.0); setB (NODE_4, VSRC_2, +0.0);
00063   setC (VSRC_1, NODE_1, +0.0); setC (VSRC_1, NODE_2, +1.0);
00064   setC (VSRC_1, NODE_3, -1.0); setC (VSRC_1, NODE_4, +0.0);
00065   setC (VSRC_2, NODE_1, +1.0); setC (VSRC_2, NODE_2, +0.0);
00066   setC (VSRC_2, NODE_3, +0.0); setC (VSRC_2, NODE_4, -1.0);
00067   setD (VSRC_1, VSRC_1, - getPropertyDouble ("G"));
00068   setD (VSRC_2, VSRC_2, 0.0);
00069   setD (VSRC_1, VSRC_2, 0.0); setD (VSRC_2, VSRC_1, 0.0);
00070   setE (VSRC_1, 0.0);
00071   setE (VSRC_2, 0.0);
00072 }
00073 
00074 void ccvs::initAC (void) {
00075   initDC ();
00076 }
00077 
00078 void ccvs::calcAC (nr_double_t frequency) {
00079   nr_double_t t = getPropertyDouble ("T");
00080   nr_complex_t g = qucs::polar (getPropertyDouble ("G"),
00081                           - 2.0 * pi * frequency * t);
00082   setD (VSRC_1, VSRC_1, -g);
00083 }
00084 
00085 void ccvs::initTR (void) {
00086   nr_double_t t = getPropertyDouble ("T");
00087   initDC ();
00088   deleteHistory ();
00089   if (t > 0.0) {
00090     setHistory (true);
00091     initHistory (t);
00092     setC (VSRC_2, NODE_1, +0.0); setC (VSRC_2, NODE_2, +1.0);
00093     setC (VSRC_2, NODE_3, -1.0); setC (VSRC_2, NODE_4, +0.0);
00094     setC (VSRC_1, NODE_1, +1.0); setC (VSRC_1, NODE_2, +0.0);
00095     setC (VSRC_1, NODE_3, +0.0); setC (VSRC_1, NODE_4, -1.0);
00096     setD (VSRC_1, VSRC_1, 0.0);
00097   }
00098 }
00099 
00100 void ccvs::calcTR (nr_double_t t) {
00101   nr_double_t T = getPropertyDouble ("T");
00102   if (T > 0.0) {
00103     T = t - T;
00104     nr_double_t g = getPropertyDouble ("G");
00105     nr_double_t i = getJ (VSRC_1, T);
00106     setE (VSRC_2, g * i);
00107   }
00108 }
00109 
00110 // properties
00111 PROP_REQ [] = {
00112   { "G", PROP_REAL, { 1, PROP_NO_STR }, PROP_NO_RANGE }, PROP_NO_PROP };
00113 PROP_OPT [] = {
00114   { "T", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE }, PROP_NO_PROP };
00115 struct define_t ccvs::cirdef =
00116   { "CCVS", 4, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };