Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hybrid.cpp
Go to the documentation of this file.
1 /*
2  * hybrid.cpp - hybrid class implementation
3  *
4  * Copyright (C) 2011 Michael Margraf <michael.margraf@alumni.tu-berlin.de>
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 "hybrid.h"
31 
32 using namespace qucs;
33 
34 hybrid::hybrid () : circuit (4) {
35  type = CIR_HYBRID;
36 }
37 
38 
39 //All functions below are obtained from
40 //http://qucs.sourceforge.net/tech/node56.html
41 
42 void hybrid::initSP (void) {
43 
44  nr_complex_t p = qucs::polar (1.0, rad (getPropertyDouble ("phi")));
45  //nr_double_t k = std::sqrt(1-pow((1/M_SQRT2),2));
46  nr_double_t k = (1/M_SQRT2); //last line reduces to this for 1/std::sqrt(2)
47 
48  allocMatrixS ();
49 //S11 = S22 = S33 = S44 = 0
50  setS (NODE_1, NODE_1, 0.0); setS (NODE_2, NODE_2, 0.0);
51  setS (NODE_3, NODE_3, 0.0); setS (NODE_4, NODE_4, 0.0);
52 //S14 = S23 = S32 = S41 = 0
53  setS (NODE_1, NODE_4, 0.0); setS (NODE_2, NODE_3, 0.0);
54  setS (NODE_3, NODE_2, 0.0); setS (NODE_4, NODE_1, 0.0);
55 //S12 = S21 = S34 = S43 = std::sqrt(1-k^2)
56  setS (NODE_1, NODE_2, k); setS (NODE_2, NODE_1, k);
57  setS (NODE_3, NODE_4, k); setS (NODE_4, NODE_3, k);
58 //S13 = S31 = S24 = S42 = k*exp(j * p)
59  setS (NODE_1, NODE_3, k * p); setS (NODE_3, NODE_1, k * p);
60  setS (NODE_2, NODE_4, k * p); setS (NODE_4, NODE_2, k * p);
61 }
62 
63 void hybrid::initDC (void) {
64  setVoltageSources (2);
65  setInternalVoltageSource (1);
66  allocMatrixMNA ();
67  voltageSource (VSRC_1, NODE_1, NODE_3);
68  voltageSource (VSRC_2, NODE_2, NODE_4);
69 }
70 
71 void hybrid::initAC (void) {
72 
73  nr_double_t k = 1 / M_SQRT2;
75  nr_complex_t A = k*k*(nr_complex_t(1,0)+qucs::polar(1.0, 2.0*rad (getPropertyDouble ("phi"))));
76  nr_double_t B = 2 * std::sqrt(1-(k*k));
77  nr_complex_t C = qucs::polar (2*k, rad (getPropertyDouble ("phi")));
78  nr_complex_t D = getPropertyDouble ("Zref") * ((A*A)-(C*C));
79 
80  setVoltageSources (0);
81  allocMatrixMNA ();
82 // d *= getPropertyDouble ("Zref");
83 
84  y = (A*(nr_complex_t(2,0)-A))/D;
85  setY (NODE_1, NODE_1, y); setY (NODE_2, NODE_2, y);
86  setY (NODE_3, NODE_3, y); setY (NODE_4, NODE_4, y);
87 
88  y = (nr_complex_t(-1,0)*A*B)/D;
89  setY (NODE_1, NODE_2, y); setY (NODE_2, NODE_1, y);
90  setY (NODE_3, NODE_4, y); setY (NODE_4, NODE_3, y);
91 
92  y = (C*(nr_complex_t(-2,0)+A))/D;
93  setY (NODE_1, NODE_3, y); setY (NODE_3, NODE_1, y);
94  setY (NODE_2, NODE_4, y); setY (NODE_4, NODE_2, y);
95 
96  y= (B*C)/D;
97  setY (NODE_1, NODE_4, y); setY (NODE_4, NODE_1, y);
98  setY (NODE_2, NODE_3, y); setY (NODE_3, NODE_2, y);
99 
100 
101 
102 }
103 
104 void hybrid::initTR (void) {
105  initDC ();
106 }
107 
108 // properties
109 PROP_REQ [] = {
110  { "phi", PROP_REAL, { 0, PROP_NO_STR }, PROP_RNGII (-180, +180) },
111  PROP_NO_PROP };
112 PROP_OPT [] = {
113  { "Zref", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
114  PROP_NO_PROP };
115 struct define_t hybrid::cirdef =
117 
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
void initTR(void)
Definition: hybrid.cpp:104
#define PROP_DEF
Definition: netdefs.h:189
PROP_OPT[]
Definition: acsolver.cpp:232
#define C(c)
Definition: eqndefined.cpp:73
#define PROP_REAL
Definition: netdefs.h:174
#define PROP_NO_PROP
Definition: netdefs.h:122
#define PROP_NO_STR
Definition: netdefs.h:125
#define PROP_LINEAR
Definition: netdefs.h:120
#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
#define PROP_COMPONENT
Definition: netdefs.h:116
#define NODE_3
Definition: circuit.h:36
void initDC(void)
Definition: hybrid.cpp:63
#define rad(x)
Convert degree to radian.
Definition: constants.h:118
type
Definition: parse_vcd.y:164
void initSP(void)
placehoder for S-Parameter initialisation function
Definition: hybrid.cpp:42
#define B(con)
Definition: evaluate.cpp:70
PROP_NO_SUBSTRATE
Definition: hybrid.cpp:116
void initAC(void)
Definition: hybrid.cpp:71
#define A(a)
Definition: eqndefined.cpp:72
y
Definition: parse_mdl.y:499
#define NODE_1
Definition: circuit.h:34
#define D(con)
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
PROP_REQ[]
Definition: acsolver.cpp:229
#define VSRC_2
Definition: circuit.h:41
#define M_SQRT2
Square root of 2 ( )
Definition: consts.h:91