-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlink.cpp
More file actions
206 lines (164 loc) · 3.19 KB
/
link.cpp
File metadata and controls
206 lines (164 loc) · 3.19 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#include "link.h"
Link::Link() {
A = Matrix3cd::Identity();
unitary = true;
}
Link::Link(Matrix3cd initA, bool isUni) {
A = initA;
unitary = isUni;
}
Link::Link(SubGpType type, SubGp sub) {
Matrix2cd subA = sub.getA();
switch(type) {
case R:
A << subA(0,0), subA(0,1), 0,
subA(1,0), subA(1,1), 0,
0, 0, 1;
break;
case S:
A << subA(0,0), 0, subA(0,1),
0, 1, 0,
subA(1,0), 0, subA(1,1);
break;
case T:
A << 1, 0, 0,
0, subA(0,0), subA(0,1),
0, subA(1,0), subA(1,1);
break;
}
unitary = sub.isUnitary();
}
Link::Link(const Link& U3) {
A = U3.A;
unitary = U3.unitary;
}
Link::Link(const Link&& U3) {
A = U3.A;
unitary = U3.unitary;
}
Link Link::inv() const {
if(unitary) return Link(A.adjoint(), true);
else return Link(A.inverse());
}
complex<double> Link::det() const {
return A.determinant();
}
complex<double> Link::tr() const {
return A.trace();
}
SubGp Link::subGp(const SubGpType type) const {
Matrix2cd subA;
switch(type) {
case R:
subA << A(0,0), A(0,1),
A(1,0), A(1,1);
break;
case S:
subA << A(0,0), A(0,2),
A(2,0), A(2,2);
break;
case T:
subA << A(1,1), A(1,2),
A(2,1), A(2,2);
break;
}
return SubGp(subA, unitary);
}
void Link::gramSchmidt() {
RowVector3cd u, v, uxv;
u << A(0,0), A(0,1), A(0,2);
v << A(1,0), A(1,1), A(1,2);
u.stableNormalize();
v -= u * u.dot(v);
v.stableNormalize();
v -= u * u.dot(v);
v.stableNormalize();
uxv = u.cross(v);
uxv.stableNormalize();
A << u,
v,
uxv;
unitary = true;
}
Link Link::gramSchmidted() const {
RowVector3cd u, v, uxv;
u << A(0,0), A(0,1), A(0,2);
v << A(1,0), A(1,1), A(1,2);
u.stableNormalize();
v -= u * u.dot(v);
v.stableNormalize();
v -= u * u.dot(v);
v.stableNormalize();
uxv = u.cross(v);
uxv.stableNormalize();
Matrix3cd initA;
initA << u,
v,
uxv;
return Link(initA, true);
}
void Link::setA(const Matrix3cd newA, const bool isUni) {
A = newA;
unitary = isUni;
}
Matrix3cd Link::getA() const {
Matrix3cd copyA = A;
return copyA;
}
bool Link::isUnitary() const {
return unitary;
}
Link Link::operator=(const Link& U3) {
if (this != &U3) {
A = U3.A;
unitary = U3.unitary;
}
return *this;
}
Link Link::operator=(const Link&& U3) {
if (this != &U3) {
A = U3.A;
unitary = U3.unitary;
}
return *this;
}
Link Link::operator+=(const Link& U3) {
A += U3.A;
unitary = false;
return *this;
}
Link Link::operator+(const Link& U3) const{
return Link(A + U3.A);
}
Link Link::operator-=(const Link& U3) {
A -= U3.A;
unitary = false;
return *this;
}
Link Link::operator-(const Link& U3) const{
return Link(A - U3.A);
}
Link Link::operator*=(const Link& U3) {
A *= U3.A;
unitary &= U3.unitary;
return *this;
}
Link Link::operator*(const Link& U3) const{
return Link(A * U3.A, unitary && U3.unitary);
}
Link Link::operator*=(const double& c) {
A *= c;
unitary &= (c == 1.0);
return *this;
}
Link Link::operator*(const double& c) const{
return Link(A * c, unitary && (c == 1.0));
}
Link Link::operator*=(const complex<double>& c) {
A *= c;
unitary &= (abs(c) == 1.0);
return *this;
}
Link Link::operator*(const complex<double>& c) const{
return Link(A * c, unitary && (abs(c) == 1.0));
}