Qucs-core  0.0.19
circulator.cpp
Go to the documentation of this file.
00001 /*
00002  * circulator.cpp - circulator class implementation
00003  *
00004  * Copyright (C) 2003, 2004, 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 "circulator.h"
00031 
00032 using namespace qucs;
00033 
00034 circulator::circulator () : circuit (3) {
00035   type = CIR_CIRCULATOR;
00036   setVoltageSources (3);
00037 }
00038 
00039 void circulator::calcSP (nr_double_t) {
00040   nr_double_t z1 = getPropertyDouble ("Z1");
00041   nr_double_t z2 = getPropertyDouble ("Z2");
00042   nr_double_t z3 = getPropertyDouble ("Z3");
00043   nr_double_t r1 = (z0 - z1) / (z0 + z1);
00044   nr_double_t r2 = (z0 - z2) / (z0 + z2);
00045   nr_double_t r3 = (z0 - z3) / (z0 + z3);
00046   nr_double_t d  = 1 - r1 * r2 * r3;
00047   setS (NODE_1, NODE_1, (r2 * r3 - r1) / d);
00048   setS (NODE_2, NODE_2, (r1 * r3 - r2) / d);
00049   setS (NODE_3, NODE_3, (r1 * r2 - r3) / d);
00050   setS (NODE_1, NODE_2, std::sqrt (z2 / z1) * (z1 + z0) /
00051         (z2 + z0) * r3 * (1 - r1 * r1) / d);
00052   setS (NODE_2, NODE_3, std::sqrt (z3 / z2) * (z2 + z0) /
00053         (z3 + z0) * r1 * (1 - r2 * r2) / d);
00054   setS (NODE_3, NODE_1, std::sqrt (z1 / z3) * (z3 + z0) /
00055         (z1 + z0) * r2 * (1 - r3 * r3) / d);
00056   setS (NODE_2, NODE_1, std::sqrt (z1 / z2) * (z2 + z0) /
00057         (z1 + z0) * (1 - r2 * r2) / d);
00058   setS (NODE_1, NODE_3, std::sqrt (z3 / z1) * (z1 + z0) /
00059         (z3 + z0) * (1 - r1 * r1) / d);
00060   setS (NODE_3, NODE_2, std::sqrt (z2 / z3) * (z3 + z0) /
00061         (z2 + z0) * (1 - r3 * r3) / d);
00062 }
00063 
00064 void circulator::initDC (void) {
00065   nr_double_t z1 = getPropertyDouble ("Z1");
00066   nr_double_t z2 = getPropertyDouble ("Z2");
00067   nr_double_t z3 = getPropertyDouble ("Z3");
00068   nr_double_t r1 = (z0 - z1) / (z0 + z1);
00069   nr_double_t r2 = (z0 - z2) / (z0 + z2);
00070   nr_double_t r3 = (z0 - z3) / (z0 + z3);
00071   nr_double_t d  = 1 - r1 * r2 * r3;
00072 
00073   nr_double_t s11 = (r2 * r3 - r1) / d;
00074   nr_double_t s22 = (r1 * r3 - r2) / d;
00075   nr_double_t s33 = (r1 * r2 - r3) / d;
00076   nr_double_t s12 = std::sqrt (z2/z1) * (z1+z0) / (z2+z0) * r3 * (1-r1*r1) / d;
00077   nr_double_t s23 = std::sqrt (z3/z2) * (z2+z0) / (z3+z0) * r1 * (1-r2*r2) / d;
00078   nr_double_t s31 = std::sqrt (z1/z3) * (z3+z0) / (z1+z0) * r2 * (1-r3*r3) / d;
00079   nr_double_t s21 = std::sqrt (z1/z2) * (z2+z0) / (z1+z0) * (1-r2*r2) / d;
00080   nr_double_t s13 = std::sqrt (z3/z1) * (z1+z0) / (z3+z0) * (1-r1*r1) / d;
00081   nr_double_t s32 = std::sqrt (z2/z3) * (z3+z0) / (z2+z0) * (1-r3*r3) / d;
00082 
00083   allocMatrixMNA ();
00084 
00085   setB (NODE_1, VSRC_1, +1.0); setB (NODE_1, VSRC_2, +0.0);
00086   setB (NODE_1, VSRC_3, +0.0);
00087   setB (NODE_2, VSRC_1, +0.0); setB (NODE_2, VSRC_2, +1.0);
00088   setB (NODE_2, VSRC_3, +0.0);
00089   setB (NODE_3, VSRC_1, +0.0); setB (NODE_3, VSRC_2, +0.0);
00090   setB (NODE_3, VSRC_3, +1.0);
00091 
00092   setC (VSRC_1, NODE_1, s11 - 1.0); setC (VSRC_1, NODE_2, s12);
00093   setC (VSRC_1, NODE_3, s13);
00094   setC (VSRC_2, NODE_1, s21); setC (VSRC_2, NODE_2, s22 - 1.0);
00095   setC (VSRC_2, NODE_3, s23);
00096   setC (VSRC_3, NODE_1, s31); setC (VSRC_3, NODE_2, s32);
00097   setC (VSRC_3, NODE_3, s33 - 1.0);
00098 
00099   setD (VSRC_1, VSRC_1, z0 * (s11 + 1.0)); setD (VSRC_1, VSRC_2, z0 * s12);
00100   setD (VSRC_1, VSRC_3, z0 * s13);
00101   setD (VSRC_2, VSRC_1, z0 * s21); setD (VSRC_2, VSRC_2, z0 * (s22 + 1.0));
00102   setD (VSRC_2, VSRC_3, z0 * s23);
00103   setD (VSRC_3, VSRC_1, z0 * s31); setD (VSRC_3, VSRC_2, z0 * s32);
00104   setD (VSRC_3, VSRC_3, z0 * (s33 + 1.0));
00105 
00106   setE (VSRC_1, +0.0); setE (VSRC_2, +0.0); setE (VSRC_3, +0.0);
00107 }
00108 
00109 void circulator::initAC (void) {
00110   initDC ();
00111 }
00112 
00113 void circulator::initTR (void) {
00114   initDC ();
00115 }
00116 
00117 // properties
00118 PROP_REQ [] = {
00119   PROP_NO_PROP };
00120 PROP_OPT [] = {
00121   { "Z1", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
00122   { "Z2", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
00123   { "Z3", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
00124   PROP_NO_PROP };
00125 struct define_t circulator::cirdef =
00126   { "Circulator",
00127     3, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };