-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOO.m
More file actions
253 lines (205 loc) · 9.06 KB
/
BOO.m
File metadata and controls
253 lines (205 loc) · 9.06 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
function [out,outCOMP] = BOO(boo,X,L,ll,input,NNmode)
%X is a 3n long matrix
%L is period of box
%
%NNmode = 1,2
%1 - input is NN list from NNlist2
%2 - input is file name of Voronoi face data
switch boo
case 'q'
n = ms(X)/3;
out = zeros(n,1);
outCOMP = cell(n,1);
switch NNmode
%case 1 - neighbour list based on threshold, max set
case(1)
%Need a neighbour list from NNlist2
%Make sure it is in NN with the right struct.
NN = input;
%Calculate q_6 for each particle
for I = 1:n
qlm = zeros(ll+1,1);
for J = 1:NN.LISTN(I)
n1 = NN.LIST(I,J);
dx = X(3*n1-2:3*n1) - X(3*I-2:3*I);
dx = dx - L * round(dx/L);
[phi,theta,~] = cart2sph(dx(1),dx(2),dx(3));
theta = pi/2 - theta;
%phi = phi + pi;
qlm = qlm + Ylm(ll,phi,theta);
end
qlm = qlm / NN.LISTN(I);
%qlm is a vector, complex terms in different orders, 0 to m
%For Associated legendre, m range from 0 to m, not -m to m
outCOMP{I} = qlm;
%Sum over orders
qlm2 = 0;
%Start with terms 1 to l, double to account for -ve m values
for J = 2:ll+1
qlm2 = qlm2 + 2 * abs(qlm(J))^2;
end
%Add m = 0 contribution afterwards
qlm2 = qlm2 + abs(qlm(1))^2;
out(I) = sqrt(qlm2 * 4*pi/(2*ll+1));
end
%Voronoi tesselation
case(2)
stream = input{1};
P = 1;
VDATAn = 1;
while P <= n
%Skip particle index
VDATAn = VDATAn + 1;
nn = stream(VDATAn);
%Nlist contains indices of neighbours of particle P
Nlist = zeros(nn,1);
for I = 1:nn
VDATAn = VDATAn + 1;
Nlist(I) = stream(VDATAn);
end
%Flist contains
Flist = zeros(nn,1);
for I = 1:nn
VDATAn = VDATAn + 1;
Flist(I) = stream(VDATAn);
end
FA = sum(Flist);
qlm = zeros(ll+1,1);
for J = 1:nn
n1 = Nlist(J);
dx = X(3*n1-2:3*n1) - X(3*P-2:3*P);
dx = dx - L * round(dx/L);
[phi,theta,~] = cart2sph(dx(1),dx(2),dx(3));
theta = pi/2 - theta;
%phi = phi + pi;
qlm = qlm + Flist(J) / FA * Ylm(ll,phi,theta);
end
%qlm = qlm / nn;
%qlm is a vector, complex terms in different orders, 0 to m
%For Associated legendre, m range from 0 to m, not -m to m
outCOMP{P} = qlm;
%Sum over orders
qlm2 = 0;
%Start with terms 1 to l, double to account for -ve m values
for J = 2:ll+1
qlm2 = qlm2 + 2 * abs(qlm(J))^2;
end
%Add m = 0 contribution afterwards
qlm2 = qlm2 + abs(qlm(1))^2;
out(P) = sqrt(qlm2 * 4*pi/(2*ll+1));
%Next particle...
P = P + 1;
VDATAn = VDATAn + 1;
end
end
case 'Q'
n = ms(X)/3;
out = zeros(n,1);
outCOMP = cell(n,1);
switch NNmode
%case 1 - neighbour list based on threshold, max set
case(1)
%Need a neighbour list from NNlist2
%Make sure it is in NN with the right struct.
NN = input;
%Calculate q_6 for each particle
qlm = zeros(ll+1,n);
for I = 1:n
for J = 1:NN.LISTN(I)
n1 = NN.LIST(I,J);
dx = X(3*n1-2:3*n1) - X(3*I-2:3*I);
dx = dx - L * round(dx/L);
[phi,theta,~] = cart2sph(dx(1),dx(2),dx(3));
theta = pi/2 - theta;
%phi = phi + pi;
qlm(:,I) = qlm(:,I) + Ylm(ll,phi,theta);
end
qlm(:,I) = qlm(:,I) / NN.LISTN(I);
%qlm is a vector, complex terms in different orders, 0 to m
%For Associated legendre, m range from 0 to m, not -m to m
end
for I = 1:n
qlmav = zeros(ll+1,1);
for J = 1:NN.LISTN(I)
n1 = NN.LIST(I,J);
qlmav = qlmav + qlm(:,n1);
end
qlmav = qlmav + qlm(:,I);
qlmav = qlmav / (NN.LISTN(I)+1);
outCOMP{I} = qlmav;
%Sum over orders
qlm2 = 0;
%Start with terms 1 to l, double to account for -ve m values
for J = 2:ll+1
qlm2 = qlm2 + 2 * abs(qlmav(J))^2;
end
%Add m = 0 contribution afterwards
qlm2 = qlm2 + abs(qlmav(1))^2;
out(I) = sqrt(qlm2 * 4*pi/(2*ll+1));
end
%Voronoi tesselation
case(2)
stream = input{1};
P = 1;
VDATAn = 1;
qlm = zeros(ll+1,n);
nn = zeros(n,1);
NlistMEM = cell(n,1);
while P <= n
%Skip particle index
VDATAn = VDATAn + 1;
nn(P) = stream(VDATAn);
%Nlist contains indices of neighbours of particle P
Nlist = zeros(nn(P),1);
for I = 1:nn(P)
VDATAn = VDATAn + 1;
Nlist(I) = stream(VDATAn);
end
NlistMEM{P} = Nlist;
%Flist contains
Flist = zeros(nn(P),1);
for I = 1:nn(P)
VDATAn = VDATAn + 1;
Flist(I) = stream(VDATAn);
end
FA = sum(Flist);
for J = 1:nn(P)
n1 = Nlist(J);
dx = X(3*n1-2:3*n1) - X(3*P-2:3*P);
dx = dx - L * round(dx/L);
[phi,theta,~] = cart2sph(dx(1),dx(2),dx(3));
theta = pi/2 - theta;
%phi = phi + pi;
qlm(:,P) = qlm(:,P) + Flist(J) / FA * Ylm(ll,phi,theta);
end
%qlm = qlm / nn;
%qlm is a vector, complex terms in different orders, 0 to m
%For Associated legendre, m range from 0 to m, not -m to m
%Next particle...
P = P + 1;
VDATAn = VDATAn + 1;
end
%For Minkowski metric, sum over NN neighbours as judged by
%Voronoi (?)
for I = 1:n
qlmav = zeros(ll+1,1);
for J = 1:nn(I)
n1 = NlistMEM{I}(J);
qlmav = qlmav + qlm(:,n1);
end
qlmav = qlmav + qlm(:,I);
qlmav = qlmav / (nn(I)+1);
outCOMP{I} = qlmav;
%Sum over orders
qlm2 = 0;
%Start with terms 1 to l, double to account for -ve m values
for J = 2:ll+1
qlm2 = qlm2 + 2 * abs(qlmav(J))^2;
end
%Add m = 0 contribution afterwards
qlm2 = qlm2 + abs(qlmav(1))^2;
out(I) = sqrt(qlm2 * 4*pi/(2*ll+1));
end
end
end
end