-
Notifications
You must be signed in to change notification settings - Fork 1
/
Analysis.R
369 lines (320 loc) · 10.5 KB
/
Analysis.R
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
load(tseq)
load(bfallobj)
#Evolutionary droplet size distribution
size_dis_t=list()
for (i in 1:length(bfallobj))
{
k=1
for (j in 1:length(tseq))
{
if ((bfallobj[[i]]$deat.t<0 & bfallobj[[i]]$jump.t<0)|
(bfallobj[[i]]$deat.t>tseq[j]) | ( bfallobj[[i]]$jump.t>tseq[j]))
{
while (k<nrow(bfallobj[[i]]$log.tr))
{
if (bfallobj[[i]]$log.tr[k+1,1]<=tseq[j])
{
k=k+1
}
else
{
break
}
}
if (bfallobj[[i]]$log.tr[k,1]==tseq[j])
{
if (j>length(size_dis_t))
{
size_dis_t[[j]]<-matrix(c(bfallobj[[i]]$ind,bfallobj[[i]]$log.tr[k,4]),ncol=2)
}
else
{
size_dis_t[[j]]<-rbind(size_dis_t[[j]],c(bfallobj[[i]]$ind,bfallobj[[i]]$log.tr[k,4]))
}
k=k+1
}
}
if (k>nrow(bfallobj[[i]]$log.tr)) break
}
#print(i)
}
#Find maximum r for range of density plot
rmax=0
for(i in 1:length(bfallobj))
{
if(rmax<bfallobj[[i]]$r)
{
rmax=bfallobj[[i]]$r
}
}
#plot(density(size_dis_t[[1500]][,2]))
plot(density(size_dis_t[[1]][,2],from=0,to=2*rmax),xlim=c(0,rmax))
lines(density(size_dis_t[[1500]][,2]))
#0
pdf("size_dis-0.pdf")
plot(density(size_dis_t[[1]][,2],from=0),main="Drop size distribution at t=0",xlab="Radius",ylab="Density")
dev.off()
#10
pdf("size_dis-0.064.pdf")
plot(density(size_dis_t[[11]][,2],from=0),main="Drop size distribution at t=0.064",xlab="Radius",ylab="Density")
dev.off()
#100
pdf("size_dis-0.135.pdf")
plot(density(size_dis_t[[101]][,2],from=0),main="Drop size distribution at t=0.135",xlab="Radius",ylab="Density")
dev.off()
#200
pdf("size_dis-0.173.pdf")
plot(density(size_dis_t[[201]][,2],from=0),main="Drop size distribution at t=0.173",xlab="Radius",ylab="Density")
dev.off()
#400
pdf("size_dis-0.261.pdf")
plot(density(size_dis_t[[401]][,2],from=0),main="Drop size distribution at t=0.261",xlab="Radius",ylab="Density")
dev.off()
#600
pdf("size_dis-0.390.pdf")
plot(density(size_dis_t[[101]][,2],from=0),main="Drop size distribution at t=0.390",xlab="Radius",ylab="Density")
dev.off()
#800
pdf("size_dis-0.504.pdf")
plot(density(size_dis_t[[801]][,2],from=0),main="Drop size distribution at t=0.504",xlab="Radius",ylab="Density")
dev.off()
plotc=c(10,100,500,300,seq(200,2000,200))
# plotc=c(500)
for (i in 1:length(plotc))
{
pdf(paste0("size_dis-",tseq[plotc[i]+1]-((tseq[plotc[i]+1]*1000)%%1)/1000,"-",plotc[i],".pdf"))
plot(density(size_dis_t[[plotc[i]+1]][,2],from=0),ylim=c(0,50),main=paste0("Drop size distribution at t=",tseq[plotc[i]+1]-((tseq[plotc[i]+1]*1000)%%1)/1000),xlab="Radius",ylab="Density")
dev.off()
}
plot_drop_distr_t<-function(plotc,size_dis_t,tseq,y_lim,rmax)
{
lwd<-seq(0.5,2.5,length=length(plotc))
plot(density(size_dis_t[[plotc[1]+1]][,2],from=0),xlim=c(0,rmax),ylim=y_lim,
main=paste0("Drop size distribution at Different time"),
xlab="Radius",ylab="Density",lty=1,lwd=lwd[1])
legend_name<-c(paste0("t=",tseq[plotc[1]+1]-((tseq[plotc[1]+1]*1000)%%1)/1000))
if (length(plotc)==1) return()
for (i in 2:length(plotc))
{
legend_name<-c(legend_name,paste0("t=",tseq[plotc[i]+1]-((tseq[plotc[i]+1]*1000)%%1)/1000))
lines(density(size_dis_t[[plotc[i]+1]][,2],from=0),col=i,lty=i,lwd=lwd[i])
}
legend(x = "topright",legend = legend_name,
bty="n",
text.col=1:length(plotc),
lty=1:length(plotc),pch=NA,
lwd=lwd,
col=1:length(plotc))
par("yaxs"="r")
}
plotc<-c(10,50,100,300,400,seq(500,4000,500))
pdf("Asymptotic Distribution.pdf")
plot_drop_distr_t(plotc,size_dis_t,tseq,c(0,80),rmax)
dev.off()
#Jumping size, time, and number of coalescence
jump_info=NULL
for (i in 1:length(depart.list))
{
const=length(bfallobj[[depart.list[[i]]]]$coal)
nofcoal=0
while (bfallobj[[depart.list[[i]]]]$coal[[const-nofcoal]]$t==bfallobj[[depart.list[[i]]]]$jump.t)
{
nofcoal=nofcoal+1
if(nofcoal>=const) break
}
jump_info=rbind(jump_info,c(bfallobj[[depart.list[[i]]]]$jump.t,bfallobj[[depart.list[[i]]]]$r,as.character(nofcoal)))
}
hist(as.numeric(jump_info[,2]))
plot(density(as.numeric(jump_info[,2]),from=0))
plot(density(as.numeric(jump_info[,2]),from=0))
plot(as.numeric(jump_info[,1]),as.numeric(jump_info[,2]))
pdf("jump_times-t.pdf")
plot(as.numeric(jump_info[,1]),(1:nrow(jump_info)),pch=1,cex=0.1,main="Times of disappearance before t",xlab="t",ylab="Accumulated times of disappearance")
dev.off()
plot(as.integer(jump_info[,3]))
#Coalescence times v.s. time
coal_times_t=rep(0,length(tseq))
accu_coal_times_t=rep(0,length(tseq))
k=1
for(i in 1:length(coalall))
{
while (coalall[[i]]$t>tseq[k])
{
k=k+1
}
if (coalall[[i]]$t==tseq[k])
{
coal_times_t[k]=coal_times_t[k]+1
}
accu_coal_times_t[k]=sum(coal_times_t[1:k])
}
pdf("coal_times-t.pdf")
plot(tseq,accu_coal_times_t,pch=1,cex=0.1,main="Times of coalescence before t",xlab="t",ylab="Accumulated times of coalescence")
dev.off()
#Sort information in bfallobj
bfallobj_sort<-bfallobj
for(i in 1:length(bfallobj_sort))
{
delete.row=NULL
if(nrow(bfallobj_sort[[i]]$log.tr)>1)
{
for(j in 1:(nrow(bfallobj_sort[[i]]$log.tr)-1))
{
if(bfallobj_sort[[i]]$log.tr[j,1]==bfallobj_sort[[i]]$log.tr[j+1,1])
{
delete.row=c(delete.row,j)
}
}
if (!is.null(delete.row))
{
bfallobj_sort[[i]]$log.tr<-bfallobj_sort[[i]]$log.tr[-delete.row,]
}
}
}
# #Coalsecence times v.s. size
# coal_drop_t=matrix(rep(NA,length(bfallobj_sort)*length(tseq)),ncol=length(tseq))
# for(i in 1:length(bfallobj_all))
# {
# k=1
# for(j in 1:length(tseq))
# {
# if(bfallobj[[i]]$coal[[k]]$t==tseq[j])
# {
# coal_drop_t[i,j]=bfallobj[[i]]$log.tr[]
# k=k+1
# if (k>nrow(bfall))
# }
# }
# }
#Coalsecence times v.s. size
coal_drop<-function(bfallobj_t,tseq)
{
coal_drop_t=list()
for(i in 1:length(bfallobj_t))
{
k=1
for(j in 1:length(tseq))
{
if (length(bfallobj_t[[i]]$coal)==0) break
if(bfallobj_t[[i]]$coal[[k]]$t==tseq[j])
{
r<-max(bfallobj_t[[i]]$log.tr[bfallobj_t[[i]]$log.tr[,1]==bfallobj_t[[i]]$coal[[k]]$t,4])
if (k>length(coal_drop_t))
{
coal_drop_t<-c(coal_drop_t, list(matrix(c(bfallobj_t[[i]]$coal[[k]]$t,r),nrow=1)))
}
else
{
coal_drop_t[[k]]<-rbind(coal_drop_t[[k]],c(bfallobj_t[[i]]$coal[[k]]$t,r))
}
k=k+1
if (k>length(bfallobj_t[[i]]$coal)) break
}
}
}
return(coal_drop_t)
}
coal_drop_t<-coal_drop(bfallobj_sort,tseq)
#Find the maximum time of coalescence and return the index of the droplets in bfallobj_sort or bfallobj
maxncoal=0
maxncoal_ind=0
for (i in 1:length(bfallobj_sort))
{
if (length(bfallobj_sort[[i]]$coal)>maxncoal)
{
maxncoal=length(bfallobj_sort[[i]]$coal)
maxncoal_ind=bfallobj_sort[[i]]$ind
}
}
maxncoal_drop<-bfallobj_sort[[maxncoal_ind]]
coal_t<-unlist(lapply(maxncoal_drop$coal,function(x) x$t))
plot(1:length(maxncoal_drop$coal),maxncoal_drop$log.tr[maxncoal_drop$log.tr[,1] %in% coal_t,4],
pch=1,cex=0.3,
main="Times of coalescence v.s. size",xlab="# of coalescence",
ylab="Size of droplets with /n the most coalescence times")
CEX=0.7
pdf("coal_times-size.pdf")
plot(1:length(coal_drop_t),unlist(lapply(coal_drop_t,function(x) mean(x[,2]))),
pch=1,cex=CEX,main="Times of coalescence v.s. size",xlab="# of coalescence",ylab="Size of droplets")
points(1:length(coal_drop_t),unlist(lapply(coal_drop_t,function(x) mean(x[,2]))) +sqrt(unlist(lapply(coal_drop_t,function(x) var(x[,2])))),
pch=1,cex=CEX,col="red")
points(1:length(coal_drop_t),unlist(lapply(coal_drop_t,function(x) mean(x[,2]))) -sqrt(unlist(lapply(coal_drop_t,function(x) var(x[,2])))),
pch=1,cex=CEX,col="red")
points(1:length(maxncoal_drop$coal),maxncoal_drop$log.tr[maxncoal_drop$log.tr[,1] %in% coal_t,4],
pch=3,cex=CEX,col="blue")
legend(x = "bottomright",legend = c("Mean radius","1 STD upper","1 STD lower", "The case with largest coalescence time"),
bty="n",
text.col=c("black","red","red","blue"),
lty=NA,pch=c(1,1,1,3),
lwd=1,
col=c("black","red","red","blue"))
par("yaxs"="r")
dev.off()
#At every moment, the size distribution of existing droplets with different times of coalescence
drop_gener_t<-function(bfallobj_t,tseq,t,y_lim,nsample)
{
for (i in 1:length(tseq))
{
if (t<tseq[i])
{
nt<-i-1
break
}
}
drop_list<-NULL
for (i in 1:length(bfallobj_t))
{
if (bfallobj_t[[i]]$deat.t>=t | bfallobj_t[[i]]$jump.t>=t)
{
drop_list<-c(drop_list,i)
}
}
plot_drop_gener_t<-function(drop_gener_t,t)
{
plot(density(drop_gener_t1[[1]][,2],from=0,to=2*rmax),xlim=c(0,rmax),ylim=y_lim,
main=paste("Distribution of different \n generation (coalescence) at t=",t),
xlab="Drop size",
ylab="Density")
legend_name<-c(paste0("g1","-",length(drop_gener_t[[1]])))
plotted_one<-c(1)
for (i in 2:length(drop_gener_t))
{
if (length(drop_gener_t[[i]])>nsample)
{
lines(density(drop_gener_t1[[i]][,2]),col=i)
legend_name<-c(legend_name,paste0("g",i,"-",length(drop_gener_t[[i]])))
plotted_one<-c(plotted_one,i)
}
}
legend(x = "topright",legend = legend_name,
bty="n",
text.col=1:length(drop_gener_t)[plotted_one],
lty=1,pch=NA,
lwd=1,
col=1:length(drop_gener_t)[plotted_one])
par("yaxs"="r")
}
drop_gener_t1<-coal_drop(bfallobj_t[drop_list],tseq[1:nt])
plot_drop_gener_t(drop_gener_t1,t)
return(drop_gener_t1)
}
for (i in 1:23)
{
pdf(paste0("Distr-gener-",i/10,".pdf"))
drop_gener_t1<-drop_gener_t(bfallobj_sort,tseq,i/10,c(0,100),10)
dev.off()
}
drop_gener_t1<-drop_gener_t(bfallobj_sort,tseq,0.5,c(0,100),10)
drop_gener_t1<-drop_gener_t(bfallobj_sort,tseq,0.8,c(0,100),10)
drop_gener_t1<-drop_gener_t(bfallobj_sort,tseq,0.9,c(0,100),10)
drop_gener_t1<-drop_gener_t(bfallobj_sort,tseq,1.0,c(0,100),10)
drop_gener_t1<-drop_gener_t(bfallobj_sort,tseq,1.1,c(0,100),10)
drop_gener_t1<-drop_gener_t(bfallobj_sort,tseq,1.2,c(0,100),10)
drop_gener_t1<-drop_gener_t(bfallobj_sort,tseq,1.3,c(0,100),10)
drop_gener_t1<-drop_gener_t(bfallobj_sort,tseq,1.4,c(0,100),10)
drop_gener_t1<-drop_gener_t(bfallobj_sort,tseq,1.5,c(0,100),10)
drop_gener_t1<-drop_gener_t(bfallobj_sort,tseq,1.6,c(0,100),10)
drop_gener_t1<-drop_gener_t(bfallobj_sort,tseq,1.7,c(0,100),10)
drop_gener_t1<-drop_gener_t(bfallobj_sort,tseq,1.8,c(0,100),10)
drop_gener_t1<-drop_gener_t(bfallobj_sort,tseq,1.9,c(0,100),10)
drop_gener_t1<-drop_gener_t(bfallobj_sort,tseq,2.0,c(0,100),10)