Qucs-core  0.0.19
hybrid.cpp
Go to the documentation of this file.
00001 /*
00002  * hybrid.cpp - hybrid class implementation
00003  *
00004  * Copyright (C) 2011 Michael Margraf <michael.margraf@alumni.tu-berlin.de>
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 "hybrid.h"
00031 
00032 using namespace qucs;
00033 
00034 hybrid::hybrid () : circuit (4) {
00035   type = CIR_HYBRID;
00036 }
00037 
00038 
00039 //All functions below are obtained from
00040 //http://qucs.sourceforge.net/tech/node56.html
00041 
00042 void hybrid::initSP (void) {
00043 
00044   nr_complex_t p = qucs::polar (1.0, deg2rad (getPropertyDouble ("phi")));
00045   //nr_double_t  k = std::sqrt(1-pow((1/sqrt2),2));
00046   nr_double_t  k = (1/sqrt2); //last line reduces to this for 1/std::sqrt(2)
00047 
00048   allocMatrixS ();
00049 //S11 = S22 = S33 = S44 = 0
00050   setS (NODE_1, NODE_1, 0.0); setS (NODE_2, NODE_2, 0.0);
00051   setS (NODE_3, NODE_3, 0.0); setS (NODE_4, NODE_4, 0.0);
00052 //S14 = S23 = S32 = S41 = 0
00053   setS (NODE_1, NODE_4, 0.0); setS (NODE_2, NODE_3, 0.0);
00054   setS (NODE_3, NODE_2, 0.0); setS (NODE_4, NODE_1, 0.0);
00055 //S12 = S21 = S34 = S43 = std::sqrt(1-k^2)
00056   setS (NODE_1, NODE_2, k); setS (NODE_2, NODE_1, k);
00057   setS (NODE_3, NODE_4, k); setS (NODE_4, NODE_3, k);
00058 //S13 = S31 = S24 = S42 = k*exp(j * p)
00059   setS (NODE_1, NODE_3, k * p);  setS (NODE_3, NODE_1, k * p);
00060   setS (NODE_2, NODE_4, k * p);  setS (NODE_4, NODE_2, k * p);
00061 }
00062 
00063 void hybrid::initDC (void) {
00064   setVoltageSources (2);
00065   setInternalVoltageSource (1);
00066   allocMatrixMNA ();
00067   voltageSource (VSRC_1, NODE_1, NODE_3);
00068   voltageSource (VSRC_2, NODE_2, NODE_4);
00069 }
00070 
00071 void hybrid::initAC (void) {
00072 
00073     nr_double_t  k = 1 / sqrt2;
00074     nr_complex_t y;
00075     nr_complex_t A = k*k*(nr_complex_t(1,0)+qucs::polar(1.0, 2.0*deg2rad (getPropertyDouble ("phi"))));
00076     nr_double_t B  = 2 * std::sqrt(1-(k*k));
00077     nr_complex_t C = qucs::polar (2*k, deg2rad (getPropertyDouble ("phi")));
00078     nr_complex_t D = getPropertyDouble ("Zref") * ((A*A)-(C*C));
00079 
00080     setVoltageSources (0);
00081     allocMatrixMNA ();
00082 //    d *= getPropertyDouble ("Zref");
00083 
00084     y = (A*(nr_complex_t(2,0)-A))/D;
00085     setY (NODE_1, NODE_1, y); setY (NODE_2, NODE_2, y);
00086     setY (NODE_3, NODE_3, y); setY (NODE_4, NODE_4, y);
00087 
00088     y = (nr_complex_t(-1,0)*A*B)/D;
00089     setY (NODE_1, NODE_2, y); setY (NODE_2, NODE_1, y);
00090     setY (NODE_3, NODE_4, y); setY (NODE_4, NODE_3, y);
00091 
00092     y = (C*(nr_complex_t(-2,0)+A))/D;
00093     setY (NODE_1, NODE_3, y); setY (NODE_3, NODE_1, y);
00094     setY (NODE_2, NODE_4, y); setY (NODE_4, NODE_2, y);
00095 
00096     y= (B*C)/D;
00097     setY (NODE_1, NODE_4, y); setY (NODE_4, NODE_1, y);
00098     setY (NODE_2, NODE_3, y); setY (NODE_3, NODE_2, y);
00099 
00100 
00101 
00102 }
00103 
00104 void hybrid::initTR (void) {
00105   initDC ();
00106 }
00107 
00108 // properties
00109 PROP_REQ [] = {
00110   { "phi", PROP_REAL, { 0, PROP_NO_STR },  PROP_RNGII (-180, +180) },
00111   PROP_NO_PROP };
00112 PROP_OPT [] = {
00113   { "Zref", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
00114   PROP_NO_PROP };
00115 struct define_t hybrid::cirdef =
00116   { "Hybrid", 4, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };
00117