Qucs-core  0.0.19
gyrator.cpp
Go to the documentation of this file.
00001 /*
00002  * gyrator.cpp - gyrator class implementation
00003  *
00004  * Copyright (C) 2004, 2005, 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 "gyrator.h"
00031 
00032 using namespace qucs;
00033 
00034 gyrator::gyrator () : circuit (4) {
00035   type = CIR_GYRATOR;
00036 #if AUGMENTED
00037   setVoltageSources (2);
00038 #endif
00039 }
00040 
00041 void gyrator::initSP (void) {
00042   nr_double_t R = getPropertyDouble ("R");
00043   nr_double_t z = getPropertyDouble ("Zref");
00044   nr_double_t r = R / z;
00045   nr_double_t s1 = r * r / (r * r + 4.0);
00046   nr_double_t s2 = 2.0 * r / (r * r + 4.0);
00047   allocMatrixS ();
00048   setS (NODE_1, NODE_1, s1); setS (NODE_2, NODE_2, s1);
00049   setS (NODE_3, NODE_3, s1); setS (NODE_4, NODE_4, s1);
00050   setS (NODE_1, NODE_4, 1.0 - s1);
00051   setS (NODE_2, NODE_3, 1.0 - s1);
00052   setS (NODE_3, NODE_2, 1.0 - s1);
00053   setS (NODE_4, NODE_1, 1.0 - s1);
00054   setS (NODE_1, NODE_2, +s2); setS (NODE_2, NODE_4, +s2);
00055   setS (NODE_3, NODE_1, +s2); setS (NODE_4, NODE_3, +s2);
00056   setS (NODE_1, NODE_3, -s2); setS (NODE_2, NODE_1, -s2);
00057   setS (NODE_3, NODE_4, -s2); setS (NODE_4, NODE_2, -s2);
00058 }
00059 
00060 void gyrator::initDC (void) {
00061   nr_double_t r = getPropertyDouble ("R");
00062   allocMatrixMNA ();
00063 #if AUGMENTED
00064   setB (NODE_1, VSRC_1, +1.0); setB (NODE_2, VSRC_1, +0.0);
00065   setB (NODE_3, VSRC_1, +0.0); setB (NODE_4, VSRC_1, -1.0);
00066   setB (NODE_2, VSRC_1, +0.0); setB (NODE_2, VSRC_2, +1.0);
00067   setB (NODE_3, VSRC_2, -1.0); setB (NODE_4, VSRC_2, +0.0);
00068   setC (VSRC_1, NODE_1, +0.0); setC (VSRC_1, NODE_2, +1/r);
00069   setC (VSRC_1, NODE_3, -1/r); setC (VSRC_1, NODE_4, +0.0);
00070   setC (VSRC_2, NODE_1, -1/r); setC (VSRC_2, NODE_2, +0.0);
00071   setC (VSRC_2, NODE_3, +0.0); setC (VSRC_2, NODE_4, +1/r);
00072   setD (VSRC_1, VSRC_1, -1.0); setD (VSRC_2, VSRC_2, -1.0);
00073   setD (VSRC_1, VSRC_2, +0.0); setD (VSRC_2, VSRC_1, +0.0);
00074   setE (VSRC_1, +0.0);
00075   setE (VSRC_2, +0.0);
00076 #else
00077   setY (NODE_1, NODE_2, +1/r); setY (NODE_1, NODE_3, -1/r);
00078   setY (NODE_2, NODE_1, -1/r); setY (NODE_2, NODE_4, +1/r);
00079   setY (NODE_3, NODE_1, +1/r); setY (NODE_3, NODE_4, -1/r);
00080   setY (NODE_4, NODE_2, -1/r); setY (NODE_4, NODE_3, +1/r);
00081 #endif
00082 }
00083 
00084 void gyrator::initAC (void) {
00085   initDC ();
00086 }
00087 
00088 void gyrator::initTR (void) {
00089   initDC ();
00090 }
00091 
00092 // properties
00093 PROP_REQ [] = {
00094   { "R", PROP_REAL, { 50, PROP_NO_STR }, PROP_NO_RANGE }, PROP_NO_PROP };
00095 PROP_OPT [] = {
00096   { "Zref", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
00097   PROP_NO_PROP };
00098 struct define_t gyrator::cirdef =
00099   { "Gyrator", 4, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };