My Project
0.0.16
QUCS Mapping
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
DownLoad
QUCS-src
qucs-0.0.16
qucs-core
src
components
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: coupler.cpp 1825 2011-03-11 20:42:14Z ela $
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
coupler::coupler () :
circuit
(4) {
33
type =
CIR_COUPLER
;
34
}
35
36
void
coupler::initSP
(
void
) {
37
allocMatrixS
();
38
nr_double_t k =
getPropertyDouble
(
"k"
);
39
nr_double_t z =
getPropertyDouble
(
"Z"
);
40
nr_double_t p =
rad
(
getPropertyDouble
(
"phi"
));
41
nr_double_t r = (
z0
- z) / (
z0
+ z);
42
nr_double_t k2 = k * k;
43
nr_double_t r2 = r * r;
44
nr_complex_t
a = k2 * (
polar
(1.0, 2 * p) + 1.0);
45
nr_complex_t
b
= r2 * (1.0 - a);
46
nr_complex_t
c
= k2 * (
polar
(1.0, 2 * p) - 1.0);
47
nr_complex_t
d = 1.0 - 2.0 * r2 * (1.0 +
c
) + b * b;
48
nr_complex_t
s
= r * (a * b + c +
polar
(2 * r2 * k2, 2 * p)) / d;
49
setS
(
NODE_1
,
NODE_1
, s);
setS
(
NODE_2
,
NODE_2
, s);
50
setS
(
NODE_3
,
NODE_3
, s);
setS
(
NODE_4
,
NODE_4
, s);
51
s =
sqrt
(1 - k2) * (1.0 - r2) * (1.0 - b) / d;
52
setS
(
NODE_1
,
NODE_2
, s);
setS
(
NODE_2
,
NODE_1
, s);
53
setS
(
NODE_3
,
NODE_4
, s);
setS
(
NODE_4
,
NODE_3
, s);
54
s =
polar
(k, p) * (1.0 - r2) * (1.0 + b) / d;
55
setS
(
NODE_1
,
NODE_3
, s);
setS
(
NODE_3
,
NODE_1
, s);
56
setS
(
NODE_2
,
NODE_4
, s);
setS
(
NODE_4
,
NODE_2
, s);
57
s = 2 *
sqrt
(1.0 - k2) *
polar
(k, p) * r * (1.0 - r2) / d;
58
setS
(
NODE_1
,
NODE_4
, s);
setS
(
NODE_4
,
NODE_1
, s);
59
setS
(
NODE_2
,
NODE_3
, s);
setS
(
NODE_3
,
NODE_2
, s);
60
}
61
62
void
coupler::initDC
(
void
) {
63
setVoltageSources
(2);
64
setInternalVoltageSource
(1);
65
allocMatrixMNA
();
66
voltageSource
(
VSRC_1
,
NODE_1
,
NODE_2
);
67
voltageSource
(
VSRC_2
,
NODE_3
,
NODE_4
);
68
}
69
70
void
coupler::initAC
(
void
) {
71
setVoltageSources
(0);
72
allocMatrixMNA
();
73
nr_double_t k =
getPropertyDouble
(
"k"
);
74
nr_double_t z =
getPropertyDouble
(
"Z"
);
75
nr_double_t p =
rad
(
getPropertyDouble
(
"phi"
));
76
nr_double_t
b
= 2 *
sqrt
(1 - k * k);
77
nr_complex_t
a = k * k * (
polar
(1.0, 2 * p) + 1.0);
78
nr_complex_t
c
=
polar
(2 * k, p);
79
nr_complex_t
d = z * (a * a - c *
c
);
80
nr_complex_t
y;
81
y = a * (2.0 - a) / d;
82
setY
(
NODE_1
,
NODE_1
, y);
setY
(
NODE_2
,
NODE_2
, y);
83
setY
(
NODE_3
,
NODE_3
, y);
setY
(
NODE_4
,
NODE_4
, y);
84
y = -a * b / d;
85
setY
(
NODE_1
,
NODE_2
, y);
setY
(
NODE_2
,
NODE_1
, y);
86
setY
(
NODE_3
,
NODE_4
, y);
setY
(
NODE_4
,
NODE_3
, y);
87
y = c * (a - 2.0) / d;
88
setY
(
NODE_1
,
NODE_3
, y);
setY
(
NODE_3
,
NODE_1
, y);
89
setY
(
NODE_2
,
NODE_4
, y);
setY
(
NODE_4
,
NODE_2
, y);
90
y = b * c / d;
91
setY
(
NODE_1
,
NODE_4
, y);
setY
(
NODE_4
,
NODE_1
, y);
92
setY
(
NODE_2
,
NODE_3
, y);
setY
(
NODE_3
,
NODE_2
, y);
93
}
94
95
void
coupler::initTR
(
void
) {
96
initDC
();
97
}
98
99
// properties
100
PROP_REQ
[] = {
101
{
"k"
,
PROP_REAL
, {
M_SQRT1_2
,
PROP_NO_STR
},
PROP_NO_RANGE
},
102
{
"phi"
,
PROP_REAL
, { 0,
PROP_NO_STR
},
PROP_RNGII
(-180, +180) },
103
PROP_NO_PROP
};
104
PROP_OPT
[] = {
105
{
"Z"
,
PROP_REAL
, { 50,
PROP_NO_STR
},
PROP_POS_RANGE
},
106
PROP_NO_PROP
};
107
struct
define_t
coupler
::cirdef =
108
{
"Coupler"
, 4,
PROP_COMPONENT
,
PROP_NO_SUBSTRATE
,
PROP_LINEAR
,
PROP_DEF
};
Generated on Tue Dec 25 2012 14:30:38 for My Project by
1.8.2