-
Notifications
You must be signed in to change notification settings - Fork 0
/
mathfluxdecomp2.m
384 lines (375 loc) · 8.78 KB
/
mathfluxdecomp2.m
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
clear all;
clc;
A1 = importdata('flux1nved.data');
A2 = importdata('flux2nved.data');
Ak=importdata('keallnved.data');
heat=importdata('heatfluxnved.log',' ',30);
lo=[-8.63958 6.05151 6.98018];%change y axis
hi=[89.0396 74.3485 73.4198];%change z axis for volume match
S=(hi(1,2)-lo(1,2))*(hi(1,3)-lo(1,3))*2;%calculate area of two sides
bz=[-2.64E+00 34.2];%value used in the box x-axis
v=(hi(1,1)-lo(1,1))/(bz(1,2)-bz(1,1));%the vol fact in the 600K.in
%%
B1 = A1.data;
B2 = A2.data;
Bk=Ak.data;
hl=heat.data;
ke=mean(Bk(:,2));
pe=mean(Bk(:,3));
n=size(B1,1); %maybe steps in B1 is different in B2
for i=1:n
for j=2:9
hf0(i,j-1)=-B1(i,j)+B2(i,j); %trans data to hf by adding flux1 and flux2
end
TB(i,1)=i/1000*0.25; %in ns
end
%transfer data to hf
for i=1:n
hf(i,1)=hf0(i,1)*v/2;%multiply the vol scale for the out put dif
hf(i,2)=hf0(i,2)*v/2;
%hf(i,1)=((hf0(i,1))^2)^0.5;%make the data positive
%hf(i,2)=((hf0(i,2))^2)^0.5;%make the data positive
for j=3:8
hf(i,j)=hf0(i,j)*v/2;
%hf(i,j)=((hf0(i,j))^2)^0.5+((hf0(i,2)^2)^0.5);%make the data positive
end
end
% integrate the flux in J/m^2
for k=1:8
fi(1,k)=hf(1,k)*0.25*1000/2/(1e-20)*4186.6/6.022140857e23;
for i=2:n
fi(i,k)=(hf(i,k)+hf(i-1,k))*0.25*1000/2/(1e-20)*4186.6/6.022140857e23+fi(i-1,k);%trapzoidal rule
end
end
%% remove the convection from the pair, bond, angle, dihedral
fix(:,1)=fi(:,1)-fi(:,2);
fix(:,2)=fi(:,2);
fix(:,3)=fi(:,3)-fi(:,2);
fix(:,4)=fi(:,4)-fi(:,2);
fix(:,5)=fi(:,5)-fi(:,2);
fix(:,6)=fi(:,6)-fi(:,2);
fix(:,7)=fi(:,7)-fi(:,2);
fix(:,8)=fi(:,8)-fi(:,2);
%% calculate heat flux with 5 time interval 1ns each time dt
nx=floor(size(TB,1)/5);
for k=1:8
for i=1:5
i1=(i-1)*nx+1;
i2=i*nx;
tt=TB(i1:i2,1);
qq=fix(i1:i2,k);
kfit=fit(tt,qq,'poly1');
dqq(i,k)=kfit.p1/(1e-9);% heat flux in W/m^2
dt=TB(i2,1)-TB(i1,1);%time difference ns
dQ(i,k)=(fix(i2,k)-fix(i1,k))/dt/(1e-9);% heat flux in W/m^2
end
end
for i=1:8
ans(i,1)=mean(dQ(:,i));%mean heat flux W/M^2
ans(i,2)=std(dQ(:,i));%std of heat flux
ans2(i,1)=mean(dqq(:,i));
ans2(i,2)=std(dqq(:,i));
end
%put pe ke in dQ
ans(1,3)=ke;
ans(2,3)=pe;
ans2(1,3)=ke;
ans2(2,3)=pe;
%%
%auto corelation 1000fs
for k=1:8
for j=1:n/2
fa(j,k)=0; ta(j,1)=TB(j,1);
end
for i=1:n/2
for j=1:n/2
fa(j,k)=hf(j+i-1,k)*hf(i,k)/(hf(i,k).^2)+fa(j,k);
end
end
end
for k=1:8
for i=1:n/2
fa(i,k)=fa(i,k)/(n/2); %average to 1
end
end
%compare the lammps heat rate J vs ns:
nhl=size(hl,1);
for i=2:nhl
TB1(i-1,1)=i/1000; %in ns
qo(i-1,1)=(hl(i,7)+hl(i,8))*4186.6/6.022140857e23/S*10^20;
qi(i-1,1)=-hl(i,6)*4186.6/6.022140857e23/S*10^20;
end
qc(:,1)=fi(:,1)-fi(:,2);
figure;%plot compare heat rate
plot(TB1,qi,TB1,qo,TB,qc);
title('Heat compare')
xlabel('Time in ns');
ylabel('Energy in J/m^2');
legend('heat source','heat sink','work in z-axis');
%% plot raw data
figure;
subplot(4,2,1);
plot(TB,hf(:,1)-hf(:,2));
title('z total raw in lammps units');
hold on;
subplot(4,2,2);
plot(TB,hf(:,2));
title('kinetic');
hold on;
subplot(4,2,3);
plot(TB,hf(:,3)-hf(:,2));
title('pair');
hold on;
subplot(4,2,4);
plot(TB,hf(:,4)-hf(:,2));
title('bond');
hold on;
subplot(4,2,5);
plot(TB,hf(:,5)-hf(:,2));
title('angle');
hold on;
subplot(4,2,6);
plot(TB,hf(:,6)-hf(:,2));
title('torsion');
hold on;
subplot(4,2,7);
plot(TB,hf(:,7)-hf(:,2));
title('improper');
hold on;
subplot(4,2,8);
plot(TB,hf(:,8)-hf(:,2));
title('KSpace');
%% plot integrated data
figure;
subplot(4,2,1);
plot(TB,fi(:,1)-fi(:,2),'LineWidth',2);
title('z total integrated');ylabel('Energy (J/m^2)');xlabel('Time (ns)');xlim([0,1.2]);ylim([0,5]);
hold on;
subplot(4,2,2);
plot(TB,abs(fi(:,2)),'LineWidth',2);
title('ke heat');ylabel('Energy (J/m^2)');xlabel('Time (ns)');xlim([0,1.2]);ylim([0,5]);
hold on;
subplot(4,2,3);
plot(TB,fi(:,3)-fi(:,2),'LineWidth',2);
title('pair heat');ylabel('Energy (J/m^2)');xlabel('Time (ns)');xlim([0,1.2]);ylim([0,5]);
hold on;
subplot(4,2,4);
plot(TB,fi(:,4)-fi(:,2),'LineWidth',2);
title('bond heat');ylabel('Energy (J/m^2)');xlabel('Time (ns)');xlim([0,1.2]);ylim([0,5]);
hold on;
subplot(4,2,5);
plot(TB,fi(:,5)-fi(:,2),'LineWidth',2);
title('angle heat');ylabel('Energy (J/m^2)');xlabel('Time (ns)');xlim([0,1.2]);ylim([0,5]);
hold on;
subplot(4,2,6);
plot(TB,fi(:,6)-fi(:,2),'LineWidth',2);
title('torsion heat');ylabel('Energy (J/m^2)');xlabel('Time (ns)');xlim([0,1.2]);ylim([0,5]);
hold on;
subplot(4,2,7);
plot(TB,fi(:,7)-fi(:,2),'LineWidth',2);
title('improper heat');ylabel('Energy (J/m^2)');xlabel('Time (ns)');xlim([0,1.2]);ylim([0,5]);
hold on;
subplot(4,2,8);
plot(TB,fi(:,8)-fi(:,2),'LineWidth',2);
title('KSpace heat');ylabel('Energy (J/m^2)');xlabel('Time (ns)');xlim([0,1.2]);ylim([0,5]);
%%
%transform to frequency domain for the flux in W/m^2
%flux unit convert W/m2
for i=1:n
for j=1:8
ff(i,j)=hf(i,j)/(1e-20)*4186.6/6.022140857e23/(1e-15);%unit convert
end
end
Fs=1e12;%frequency per sample
L=length(ff);
nf=2^nextpow2(L);
Y=fft(ff,nf,1);
for i=1:nf/2+1 F(i,1)=Fs*(i-1)/nf/1e12; end %to THz
for k=1:8
P(:,k)=abs(Y(1:(nf/2+1),k)/nf); %transformed flux
end
figure; %plot flux vs THz
subplot(4,2,1);
plot(F,P(:,1));
title('FFT z-total heat');
xlabel('frequency in THz');
ylabel('heat flux in W/m^2');ylim([0,0.15e9]);
hold on;
subplot(4,2,2);
plot(F,P(:,2));
title('kinetic');ylim([0,0.15e9]);
hold on;
subplot(4,2,3);
plot(F,P(:,3));
title('pair');ylim([0,0.15e9]);
hold on;
subplot(4,2,4);
plot(F,P(:,4));
title('bond');ylim([0,0.15e9]);
hold on;
subplot(4,2,5);
plot(F,P(:,5));
title('angle');ylim([0,0.15e9]);
hold on;
subplot(4,2,6);
plot(F,P(:,6));
title('torsion');ylim([0,0.15e9]);
hold on;
subplot(4,2,7);
plot(F,P(:,7));
title('improper');ylim([0,0.15e9]);
hold on;
subplot(4,2,8);
plot(F,P(:,8));
title('KSpace');ylim([0,0.15e9]);
%inverse fourier tranform
%separate the Y to 0-0.2THZ, 0.2-0.4THZ, 0.4-0.5THZ
lF=size(F,1);
for i=1:lF
if F(i,1)<0.02 %low limit
lcut=i;
end
if F(i,1)<0.05 %high limit
hcut=i;
end
end
for k=1:8
for i=1:L
lY(i,k)=0;
mY(i,k)=0;
hY(i,k)=0;
if i<lcut
lY(i,k)=Y(i,k);
else
mY(i,k)=Y(i,k);
if i>hcut
mY(i,k)=0;
hY(i,k)=Y(i,k);
end
end
end
end
%inverse fft
lff=real(ifft(lY,nf,1));
mff=real(ifft(mY,nf,1));
hff=real(ifft(hY,nf,1));
% integrate the flux low <0.2THz
for k=1:8
fil(1,k)=lff(1,k)*(1e-12)/2;
for i=2:n
fil(i,k)=(lff(i,k)+lff(i-1,k))*(1e-12)/2+fil(i-1,k);%trapzoidal rule
end
end
%plot integrated data <2.4THz
figure;
subplot(4,2,1);
plot(TB,fil(:,1)-fil(:,2));
title('z integrated flux f<0.02THz');ylabel('heat J/m^2');xlabel('time ns');
hold on;
subplot(4,2,2);
plot(TB,fil(:,2));
title('ke heat');
hold on;
subplot(4,2,3);
plot(TB,fil(:,3)-fil(:,2));
title('pair heat');
hold on;
subplot(4,2,4);
plot(TB,fil(:,4)-fil(:,2));
title('bond heat');
hold on;
subplot(4,2,5);
plot(TB,fil(:,5)-fil(:,2));
title('angle heat');
hold on;
subplot(4,2,6);
plot(TB,fil(:,6)-fil(:,2));
title('torsion heat');
hold on;
subplot(4,2,7);
plot(TB,fil(:,7)-fil(:,2));
title('improper heat');
hold on;
subplot(4,2,8);
plot(TB,fil(:,8)-fil(:,2));
title('KSpace heat');
% integrate the flux medium 0.2-0.4THz
for k=1:8
fim(1,k)=mff(1,k)*(1e-12)/2;
for i=2:n
fim(i,k)=(mff(i,k)+mff(i-1,k))*(1e-12)/2+fim(i-1,k);%trapzoidal rule
end
end
%plot integrated data 2.4<f<17THz
figure;
subplot(4,2,1);
plot(TB,fim(:,1)-fim(:,2));
title('z integrated flux 0.02<f<0.05THz');ylabel('heat J/m^2');xlabel('time ns');
hold on;
subplot(4,2,2);
plot(TB,fim(:,2));
title('ke heat');
hold on;
subplot(4,2,3);
plot(TB,fim(:,3)-fim(:,2));
title('pair heat');
hold on;
subplot(4,2,4);
plot(TB,fim(:,4)-fim(:,2));
title('bond heat');
hold on;
subplot(4,2,5);
plot(TB,fim(:,5)-fim(:,2));
title('angle heat');
hold on;
subplot(4,2,6);
plot(TB,fim(:,6)-fim(:,2));
title('torsion heat');
hold on;
subplot(4,2,7);
plot(TB,fim(:,7)-fim(:,2));
title('improper heat');
hold on;
subplot(4,2,8);
plot(TB,fim(:,8)-fim(:,2));
title('KSpace heat');
% integrate the flux medium 0.2-0.4THz
for k=1:8
fih(1,k)=hff(1,k)*(1e-12)/2;
for i=2:n
fih(i,k)=(hff(i,k)+hff(i-1,k))*(1e-12)/2+fih(i-1,k);%trapzoidal rule
end
end
%plot integrated data f>0.4THz
figure;
subplot(4,2,1);
plot(TB,fih(:,1)-fih(:,2));
title('z integrated flux f>0.05THz');ylabel('heat J/m^2');xlabel('time ns');
hold on;
subplot(4,2,2);
plot(TB,fih(:,2));
title('ke heat');
hold on;
subplot(4,2,3);
plot(TB,fih(:,3)-fih(:,2));
title('pair heat');
hold on;
subplot(4,2,4);
plot(TB,fih(:,4)-fih(:,2));
title('bond heat');
hold on;
subplot(4,2,5);
plot(TB,fih(:,5)-fih(:,2));
title('angle heat');
hold on;
subplot(4,2,6);
plot(TB,fih(:,6)-fih(:,2));
title('torsion heat');
hold on;
subplot(4,2,7);
plot(TB,fih(:,7)-fih(:,2));
title('improper heat');
hold on;
subplot(4,2,8);
plot(TB,fih(:,8)-fih(:,2));
title('KSpace heat');