-
Notifications
You must be signed in to change notification settings - Fork 214
/
Copy pathqf_transform.cpp
81 lines (66 loc) · 1.86 KB
/
qf_transform.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "qf_common.h"
#include "qf_poly.h"
#include "qf_comp.h"
#include "qf_filter.h"
// Transforms a Tee type network of reactances into an equivalent Pi type
bool qf_filter::tee2pi (qf_lcmp& topo, qf_lcmp::iterator i) {
qf_val v;
qf_double_t xa, xb, xc, xs;
Rarray nx (3);
qf_cmp_type type;
qf_val val;
(*i) -> get (val);
type = v.type;
// Tee and Pi transforms are only available for CAP, IND et RES
if ((type != CAP) && (type != IND) && (type != RES)) return false;
xa = v.val.front ();
delete (*i);
i = topo.erase (i);
(*i) -> get (val);
// Verifies coherency
if (v.type != type) return false;
// Verifies topology;
if ((! v. shnt) || (! val.to_gnd)) return false;
xb = v.val.front ();
delete (*i);
i = topo.erase (i);
(*i) -> get (val);
// Verifies coherency
if (v.type != type) return false;
xc = v.val.front ();
delete (*i);
// Calculate and substitute elements value
if (type == CAP) {
xs = xa + xb + xc;
nx[0] = xa * xb / xs;
nx[1] = xa * xc / xs;
nx[2] = xb * xc / xs;
qf_cap* cap = new qf_cap (nx[0], true, true);
topo. insert (i, cap);
cap = new qf_cap (nx[1], false, false);
topo. insert (i, cap);
cap = new qf_cap (nx[2], true, true);
topo. insert (i, cap);
return true;
}
xs = xa * xb + xa * xc + xb * xc;
nx[0] = xs / xa;
nx[1] = xs / xb;
nx[2] = xs / xc;
if (type == IND) {
qf_ind* ind = new qf_ind (nx[0], true, true);
topo. insert (i, ind);
ind = new qf_ind (nx[1], false, false);
topo. insert (i, ind);
ind = new qf_ind (nx[2], true, true);
topo. insert (i, ind);
return true;
}
qf_res* res = new qf_res (nx[0], true, true);
topo. insert (i, res);
res = new qf_res (nx[1], false, false);
topo. insert (i, res);
res = new qf_res (nx[2], true, true);
topo. insert (i, res);
return true;
}