Branch data Line data Source code
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 : 0 : coupler::coupler () : circuit (4) {
35 : 0 : type = CIR_COUPLER;
36 : 0 : }
37 : :
38 : 0 : void coupler::initSP (void) {
39 [ # # ]: 0 : allocMatrixS ();
40 [ # # ]: 0 : nr_double_t k = getPropertyDouble ("k");
41 [ # # ]: 0 : nr_double_t z = getPropertyDouble ("Z");
42 [ # # ]: 0 : nr_double_t p = rad (getPropertyDouble ("phi"));
43 : 0 : nr_double_t r = (z0 - z) / (z0 + z);
44 : 0 : nr_double_t k2 = k * k;
45 : 0 : nr_double_t r2 = r * r;
46 [ # # ]: 0 : nr_complex_t a = k2 * (qucs::polar (1.0, 2 * p) + 1.0);
47 : 0 : nr_complex_t b = r2 * (1.0 - a);
48 [ # # ]: 0 : nr_complex_t c = k2 * (qucs::polar (1.0, 2 * p) - 1.0);
49 [ # # ][ # # ]: 0 : nr_complex_t d = 1.0 - 2.0 * r2 * (1.0 + c) + b * b;
50 [ # # ][ # # ]: 0 : nr_complex_t s = r * (a * b + c + qucs::polar (2 * r2 * k2, 2 * p)) / d;
[ # # ][ # # ]
[ # # ]
51 [ # # ][ # # ]: 0 : setS (NODE_1, NODE_1, s); setS (NODE_2, NODE_2, s);
52 [ # # ][ # # ]: 0 : setS (NODE_3, NODE_3, s); setS (NODE_4, NODE_4, s);
53 [ # # ]: 0 : s = std::sqrt (1 - k2) * (1.0 - r2) * (1.0 - b) / d;
54 [ # # ][ # # ]: 0 : setS (NODE_1, NODE_2, s); setS (NODE_2, NODE_1, s);
55 [ # # ][ # # ]: 0 : setS (NODE_3, NODE_4, s); setS (NODE_4, NODE_3, s);
56 [ # # ][ # # ]: 0 : s = qucs::polar (k, p) * (1.0 - r2) * (1.0 + b) / d;
[ # # ]
57 [ # # ][ # # ]: 0 : setS (NODE_1, NODE_3, s); setS (NODE_3, NODE_1, s);
58 [ # # ][ # # ]: 0 : setS (NODE_2, NODE_4, s); setS (NODE_4, NODE_2, s);
59 [ # # ][ # # ]: 0 : s = 2 * std::sqrt (1.0 - k2) * qucs::polar (k, p) * r * (1.0 - r2) / d;
60 [ # # ][ # # ]: 0 : setS (NODE_1, NODE_4, s); setS (NODE_4, NODE_1, s);
61 [ # # ][ # # ]: 0 : setS (NODE_2, NODE_3, s); setS (NODE_3, NODE_2, s);
62 : 0 : }
63 : :
64 : 0 : void coupler::initDC (void) {
65 : 0 : setVoltageSources (2);
66 : 0 : setInternalVoltageSource (1);
67 : 0 : allocMatrixMNA ();
68 : 0 : voltageSource (VSRC_1, NODE_1, NODE_2);
69 : 0 : voltageSource (VSRC_2, NODE_3, NODE_4);
70 : 0 : }
71 : :
72 : 0 : void coupler::initAC (void) {
73 [ # # ]: 0 : setVoltageSources (0);
74 [ # # ]: 0 : allocMatrixMNA ();
75 [ # # ]: 0 : nr_double_t k = getPropertyDouble ("k");
76 [ # # ]: 0 : nr_double_t z = getPropertyDouble ("Z");
77 [ # # ]: 0 : nr_double_t p = rad (getPropertyDouble ("phi"));
78 : 0 : nr_double_t b = 2 * std::sqrt (1 - k * k);
79 [ # # ]: 0 : nr_complex_t a = k * k * (qucs::polar (1.0, 2 * p) + 1.0);
80 [ # # ]: 0 : nr_complex_t c = qucs::polar (2 * k, p);
81 [ # # ][ # # ]: 0 : nr_complex_t d = z * (a * a - c * c);
[ # # ]
82 : 0 : nr_complex_t y;
83 [ # # ][ # # ]: 0 : y = a * (2.0 - a) / d;
84 [ # # ][ # # ]: 0 : setY (NODE_1, NODE_1, y); setY (NODE_2, NODE_2, y);
85 [ # # ][ # # ]: 0 : setY (NODE_3, NODE_3, y); setY (NODE_4, NODE_4, y);
86 [ # # ]: 0 : y = -a * b / d;
87 [ # # ][ # # ]: 0 : setY (NODE_1, NODE_2, y); setY (NODE_2, NODE_1, y);
88 [ # # ][ # # ]: 0 : setY (NODE_3, NODE_4, y); setY (NODE_4, NODE_3, y);
89 [ # # ][ # # ]: 0 : y = c * (a - 2.0) / d;
90 [ # # ][ # # ]: 0 : setY (NODE_1, NODE_3, y); setY (NODE_3, NODE_1, y);
91 [ # # ][ # # ]: 0 : setY (NODE_2, NODE_4, y); setY (NODE_4, NODE_2, y);
92 [ # # ]: 0 : y = b * c / d;
93 [ # # ][ # # ]: 0 : setY (NODE_1, NODE_4, y); setY (NODE_4, NODE_1, y);
94 [ # # ][ # # ]: 0 : setY (NODE_2, NODE_3, y); setY (NODE_3, NODE_2, y);
95 : 0 : }
96 : :
97 : 0 : void coupler::initTR (void) {
98 : 0 : initDC ();
99 : 0 : }
100 : :
101 : : // properties
102 : : PROP_REQ [] = {
103 : : { "k", PROP_REAL, { M_SQRT1_2, PROP_NO_STR }, PROP_NO_RANGE },
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 =
110 : : { "Coupler", 4, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };
|