Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
coupler.cpp
Go to the documentation of this file.
1 /*
2  * coupler.cpp - ideal coupler class implementation
3  *
4  * Copyright (C) 2006, 2008 Stefan Jahn <stefan@lkcc.org>
5  *
6  * This is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * This software is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this package; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  * $Id$
22  *
23  */
24 
25 #if HAVE_CONFIG_H
26 # include <config.h>
27 #endif
28 
29 #include "component.h"
30 #include "coupler.h"
31 
32 using namespace qucs;
33 
34 coupler::coupler () : circuit (4) {
35  type = CIR_COUPLER;
36 }
37 
38 void coupler::initSP (void) {
39  allocMatrixS ();
40  nr_double_t k = getPropertyDouble ("k");
41  nr_double_t z = getPropertyDouble ("Z");
42  nr_double_t p = rad (getPropertyDouble ("phi"));
43  nr_double_t r = (z0 - z) / (z0 + z);
44  nr_double_t k2 = k * k;
45  nr_double_t r2 = r * r;
46  nr_complex_t a = k2 * (qucs::polar (1.0, 2 * p) + 1.0);
47  nr_complex_t b = r2 * (1.0 - a);
48  nr_complex_t c = k2 * (qucs::polar (1.0, 2 * p) - 1.0);
49  nr_complex_t d = 1.0 - 2.0 * r2 * (1.0 + c) + b * b;
50  nr_complex_t s = r * (a * b + c + qucs::polar (2 * r2 * k2, 2 * p)) / d;
51  setS (NODE_1, NODE_1, s); setS (NODE_2, NODE_2, s);
52  setS (NODE_3, NODE_3, s); setS (NODE_4, NODE_4, s);
53  s = std::sqrt (1 - k2) * (1.0 - r2) * (1.0 - b) / d;
54  setS (NODE_1, NODE_2, s); setS (NODE_2, NODE_1, s);
55  setS (NODE_3, NODE_4, s); setS (NODE_4, NODE_3, s);
56  s = qucs::polar (k, p) * (1.0 - r2) * (1.0 + b) / d;
57  setS (NODE_1, NODE_3, s); setS (NODE_3, NODE_1, s);
58  setS (NODE_2, NODE_4, s); setS (NODE_4, NODE_2, s);
59  s = 2 * std::sqrt (1.0 - k2) * qucs::polar (k, p) * r * (1.0 - r2) / d;
60  setS (NODE_1, NODE_4, s); setS (NODE_4, NODE_1, s);
61  setS (NODE_2, NODE_3, s); setS (NODE_3, NODE_2, s);
62 }
63 
64 void coupler::initDC (void) {
67  allocMatrixMNA ();
70 }
71 
72 void coupler::initAC (void) {
74  allocMatrixMNA ();
75  nr_double_t k = getPropertyDouble ("k");
76  nr_double_t z = getPropertyDouble ("Z");
77  nr_double_t p = rad (getPropertyDouble ("phi"));
78  nr_double_t b = 2 * std::sqrt (1 - k * k);
79  nr_complex_t a = k * k * (qucs::polar (1.0, 2 * p) + 1.0);
80  nr_complex_t c = qucs::polar (2 * k, p);
81  nr_complex_t d = z * (a * a - c * c);
83  y = a * (2.0 - a) / d;
84  setY (NODE_1, NODE_1, y); setY (NODE_2, NODE_2, y);
85  setY (NODE_3, NODE_3, y); setY (NODE_4, NODE_4, y);
86  y = -a * b / d;
87  setY (NODE_1, NODE_2, y); setY (NODE_2, NODE_1, y);
88  setY (NODE_3, NODE_4, y); setY (NODE_4, NODE_3, y);
89  y = c * (a - 2.0) / d;
90  setY (NODE_1, NODE_3, y); setY (NODE_3, NODE_1, y);
91  setY (NODE_2, NODE_4, y); setY (NODE_4, NODE_2, y);
92  y = b * c / d;
93  setY (NODE_1, NODE_4, y); setY (NODE_4, NODE_1, y);
94  setY (NODE_2, NODE_3, y); setY (NODE_3, NODE_2, y);
95 }
96 
97 void coupler::initTR (void) {
98  initDC ();
99 }
100 
101 // properties
102 PROP_REQ [] = {
104  { "phi", PROP_REAL, { 0, PROP_NO_STR }, PROP_RNGII (-180, +180) },
105  PROP_NO_PROP };
106 PROP_OPT [] = {
107  { "Z", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
108  PROP_NO_PROP };
109 struct define_t coupler::cirdef =
std::complex< nr_double_t > nr_complex_t
Definition: complex.h:31
#define PROP_POS_RANGE
Definition: netdefs.h:129
#define NODE_2
Definition: circuit.h:35
#define PROP_RNGII(f, t)
Definition: netdefs.h:138
#define PROP_DEF
Definition: netdefs.h:189
nr_double_t getPropertyDouble(const char *)
Definition: object.cpp:176
#define PROP_REAL
Definition: netdefs.h:174
void setInternalVoltageSource(bool i)
Definition: circuit.h:184
#define PROP_NO_PROP
Definition: netdefs.h:122
void setVoltageSources(int)
Definition: circuit.cpp:607
#define PROP_NO_RANGE
Definition: netdefs.h:126
#define M_SQRT1_2
Inverse of Square root of 2 ( )
Definition: consts.h:95
#define PROP_NO_STR
Definition: netdefs.h:125
void allocMatrixS(void)
Definition: circuit.cpp:251
#define PROP_LINEAR
Definition: netdefs.h:120
static const nr_double_t z0
Definition: circuit.h:320
r
Definition: parse_mdl.y:515
PROP_NO_SUBSTRATE
Definition: coupler.cpp:110
void initSP(void)
placehoder for S-Parameter initialisation function
Definition: coupler.cpp:38
#define NODE_4
Definition: circuit.h:37
#define VSRC_1
Definition: circuit.h:40
nr_complex_t sqrt(const nr_complex_t z)
Compute principal value of square root.
Definition: complex.cpp:271
void initDC(void)
Definition: coupler.cpp:64
#define PROP_COMPONENT
Definition: netdefs.h:116
PROP_REQ[]
Definition: coupler.cpp:102
void initAC(void)
Definition: coupler.cpp:72
#define NODE_3
Definition: circuit.h:36
#define rad(x)
Convert degree to radian.
Definition: constants.h:118
type
Definition: parse_vcd.y:164
void setY(int, int, nr_complex_t)
Definition: circuit.cpp:452
void allocMatrixMNA(void)
Definition: circuit.cpp:267
y
Definition: parse_mdl.y:499
PROP_OPT[]
Definition: coupler.cpp:106
#define NODE_1
Definition: circuit.h:34
void voltageSource(int, int, int, nr_double_t value=0.0)
Definition: circuit.cpp:748
void setS(int, int, nr_complex_t)
Definition: circuit.cpp:587
nr_complex_t polar(const nr_double_t mag, const nr_double_t ang)
Construct a complex number using polar notation.
Definition: complex.cpp:551
#define VSRC_2
Definition: circuit.h:41
void initTR(void)
Definition: coupler.cpp:97