Qucs-core  0.0.19
coupler.cpp
Go to the documentation of this file.
00001 /*
00002  * coupler.cpp - ideal coupler class implementation
00003  *
00004  * Copyright (C) 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 "coupler.h"
00031 
00032 using namespace qucs;
00033 
00034 coupler::coupler () : circuit (4) {
00035   type = CIR_COUPLER;
00036 }
00037 
00038 void coupler::initSP (void) {
00039   allocMatrixS ();
00040   nr_double_t k = getPropertyDouble ("k");
00041   nr_double_t z = getPropertyDouble ("Z");
00042   nr_double_t p = deg2rad (getPropertyDouble ("phi"));
00043   nr_double_t r = (z0 - z) / (z0 + z);
00044   nr_double_t k2 = k * k;
00045   nr_double_t r2 = r * r;
00046   nr_complex_t a = k2 * (qucs::polar (1.0, 2 * p) + 1.0);
00047   nr_complex_t b = r2 * (1.0 - a);
00048   nr_complex_t c = k2 * (qucs::polar (1.0, 2 * p) - 1.0);
00049   nr_complex_t d = 1.0 - 2.0 * r2 * (1.0 + c) + b * b;
00050   nr_complex_t s = r * (a * b + c + qucs::polar (2 * r2 * k2, 2 * p)) / d;
00051   setS (NODE_1, NODE_1, s); setS (NODE_2, NODE_2, s);
00052   setS (NODE_3, NODE_3, s); setS (NODE_4, NODE_4, s);
00053   s = std::sqrt (1 - k2) * (1.0 - r2) * (1.0 - b) / d;
00054   setS (NODE_1, NODE_2, s); setS (NODE_2, NODE_1, s);
00055   setS (NODE_3, NODE_4, s); setS (NODE_4, NODE_3, s);
00056   s = qucs::polar (k, p) * (1.0 - r2) * (1.0 + b) / d;
00057   setS (NODE_1, NODE_3, s); setS (NODE_3, NODE_1, s);
00058   setS (NODE_2, NODE_4, s); setS (NODE_4, NODE_2, s);
00059   s = 2 * std::sqrt (1.0 - k2) * qucs::polar (k, p) * r * (1.0 - r2) / d;
00060   setS (NODE_1, NODE_4, s); setS (NODE_4, NODE_1, s);
00061   setS (NODE_2, NODE_3, s); setS (NODE_3, NODE_2, s);
00062 }
00063 
00064 void coupler::initDC (void) {
00065   setVoltageSources (2);
00066   setInternalVoltageSource (1);
00067   allocMatrixMNA ();
00068   voltageSource (VSRC_1, NODE_1, NODE_2);
00069   voltageSource (VSRC_2, NODE_3, NODE_4);
00070 }
00071 
00072 void coupler::initAC (void) {
00073   setVoltageSources (0);
00074   allocMatrixMNA ();
00075   nr_double_t k = getPropertyDouble ("k");
00076   nr_double_t z = getPropertyDouble ("Z");
00077   nr_double_t p = deg2rad (getPropertyDouble ("phi"));
00078   nr_double_t b = 2 * std::sqrt (1 - k * k);
00079   nr_complex_t a = k * k * (qucs::polar (1.0, 2 * p) + 1.0);
00080   nr_complex_t c = qucs::polar (2 * k, p);
00081   nr_complex_t d = z * (a * a - c * c);
00082   nr_complex_t y;
00083   y = a * (2.0 - a) / d;
00084   setY (NODE_1, NODE_1, y); setY (NODE_2, NODE_2, y);
00085   setY (NODE_3, NODE_3, y); setY (NODE_4, NODE_4, y);
00086   y = -a * b / d;
00087   setY (NODE_1, NODE_2, y); setY (NODE_2, NODE_1, y);
00088   setY (NODE_3, NODE_4, y); setY (NODE_4, NODE_3, y);
00089   y = c * (a - 2.0) / d;
00090   setY (NODE_1, NODE_3, y); setY (NODE_3, NODE_1, y);
00091   setY (NODE_2, NODE_4, y); setY (NODE_4, NODE_2, y);
00092   y = b * c / d;
00093   setY (NODE_1, NODE_4, y); setY (NODE_4, NODE_1, y);
00094   setY (NODE_2, NODE_3, y); setY (NODE_3, NODE_2, y);
00095 }
00096 
00097 void coupler::initTR (void) {
00098   initDC ();
00099 }
00100 
00101 // properties
00102 PROP_REQ [] = {
00103   { "k", PROP_REAL, { sqrt1_2, PROP_NO_STR }, PROP_NO_RANGE },
00104   { "phi", PROP_REAL, { 0, PROP_NO_STR }, PROP_RNGII (-180, +180) },
00105   PROP_NO_PROP };
00106 PROP_OPT [] = {
00107   { "Z", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
00108   PROP_NO_PROP };
00109 struct define_t coupler::cirdef =
00110   { "Coupler", 4, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };