• R/O
  • SSH

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revision04dd78bb33cee72e8b260c65262ca2d42e46c73c (tree)
Zeit2006-12-11 00:25:45
Autoriselllo
Commiteriselllo

Log Message

(empty log message)

Ändern Zusammenfassung

Diff

diff -r 326dca2a8478 -r 04dd78bb33ce codes-for-fitting7/integration-and-plots-corrected-final.R
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/codes-for-fitting7/integration-and-plots-corrected-final.R Sun Dec 10 15:25:45 2006 +0000
@@ -0,0 +1,548 @@
1+rm(list=ls())
2+
3+
4+
5+
6+ # integral = 0.0D0
7+
8+
9+# do I=1,NN-4,4
10+#!C S1=h/3.0D0*(f(I)+4.0D0*f(I+2)+f(I+4))
11+#!C S2=h/6.0D0*(f(I)+4.0D0*f(I+1)+2.0D0*f(I+2)+4.0D0*f(I+3)+f(I+4))
12+
13+
14+#!C S1=h/3.0D0*(f(I)+4.0D0*f(I+1)+2.0D0*f(I+2)+4.0D0*f(I+3)+f(I+4))
15+ # S2=h/45.0D0*(14.0D0*f(I)+64.0D0*f(I+1) &
16+ # & +24.0D0*f(I+2)+64.0D0*f(I+3)+14.0D0*f(I+4))
17+
18+
19+ # integral = integral + S2
20+
21+
22+#!C eps = eps + dabs(S1-S2)/15.0D0
23+
24+
25+#!C eps = eps + dabs(S1-S2)
26+
27+
28+ # end do
29+
30+
31+#!CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
32+ # end subroutine integration
33+
34+skip<-1
35+
36+def_integral<-function(integrand,h)
37+{
38+n<-length(integrand)
39+myseq<-seq(1,n-4,4)
40+integral<-0
41+for (i in myseq)
42+{
43+integral<- integral + h/45.0*(14.0*integrand[i]+64.0*integrand[i+1] +24.0*integrand[i+2]+64.0*integrand[i+3]+14.0*integrand[i+4])
44+
45+}
46+return(integral)
47+}
48+
49+#Now a test of the integration routine
50+
51+test_seq<-seq(0,2*pi,len=200)
52+integ<-sin(test_seq)
53+h2<-test_seq[25]-test_seq[24]
54+sin_int<-def_integral(integ,h2)
55+
56+
57+
58+lendat<-23
59+for(i in 1:lendat)
60+{
61+ fn <- paste("r",i,".txt",sep="")
62+ dat <- read.table(fn,header=FALSE)
63+ # ... do your stuff on "dat" here ...
64+ dat_temp<-as.matrix(dat)
65+{
66+if (i ==1) {mymat<-dat_temp}
67+
68+else
69+mymat<-cbind(mymat,dat_temp)
70+}
71+}
72+
73+print("OK reading the first files")
74+
75+mymat_save<-mymat # It is handy to save these data into a separate object and work with mymat only in the following
76+
77+
78+h<-abs(mymat[200,1]-mymat[201,1])
79+#vecdim<-dim(mymat)
80+#n<-vecdim[2]
81+#myseq<-seq(1,n-4,4)
82+
83+#define below each contribution to the integral and then work out the total.
84+
85+
86+
87+
88+
89+vecdim<-dim(mymat)
90+n_int<-vecdim[2]/2
91+int_value<-seq(1:n_int)
92+int_value2<-seq(1:n_int)
93+int_value3<-seq(1:n_int)
94+int_value4<-seq(1:n_int)
95+int_value5<-seq(1:n_int)
96+int_value_save<-seq(1:n_int)
97+
98+
99+
100+
101+x_seq<-seq(1:n_int)
102+
103+for (i in 1:n_int) # I define the grid position I will be using
104+{
105+{
106+if (i<=11)
107+{
108+x_seq[i]<-0.01*(i-1)
109+}
110+
111+if (i > 11 & i<=20 )
112+{
113+x_seq[i]<-0.1*(i-10)
114+}
115+if (i>20 & i<= lendat)
116+{
117+x_seq[i]<-i-19
118+}
119+}
120+}
121+
122+
123+for(i in 1:n_int)
124+{
125+myseq2<-mymat[ ,2*i]
126+int_value[i]<-def_integral(myseq2,h)
127+}
128+
129+
130+
131+
132+
133+print("the density at wall is")
134+print(int_value[1])
135+
136+dens_v<-int_value[ ]/(0.193242)
137+
138+pdf("density-absorbing-1.pdf")
139+plot(x_seq,int_value/int_value[1],col="blue",xlab=expression("x"),ylab=expression(" average v "))
140+lines(x_seq,int_value/int_value[1],lwd=2,col="red")
141+dev.off()
142+
143+
144+
145+save_data<-matrix(ncol=2,nrow=n_int)
146+save_data[ ,2]<-int_value[ ]
147+save_data[ ,1]<-x_seq[ ]
148+
149+
150+
151+
152+
153+
154+write.table(save_data,"density-normalized.txt",quote=FALSE,row.names=FALSE)
155+
156+#Now I can plot and work out other quantities.
157+#mymat[ ,2]<-mymat[ ,1]*mymat[ ,2]
158+
159+for (i in 1:n_int)
160+{
161+myseq2<-mymat[ ,2*i]*mymat[ ,2*(i-1)+1]
162+int_value2[i]<-def_integral(myseq2,h)
163+}
164+
165+
166+
167+pdf("flux-wrong-absorbing-1.pdf")
168+plot(x_seq,int_value2,col="blue",xlab=expression("x"),ylab=expression("J= average (rho*v)"))
169+lines(x_seq,int_value2,lwd=2,col="red")
170+dev.off()
171+
172+flux_v<-int_value2
173+
174+
175+
176+int_value2[ ]<-int_value2[ ]/int_value[]
177+
178+pdf("velocity-absorbing-1.pdf")
179+plot(x_seq,int_value2,col="blue",xlab=expression("x"),ylab=expression(" average v"))
180+lines(x_seq,int_value2,lwd=2,col="red")
181+dev.off()
182+
183+
184+vel_v<-int_value2
185+
186+flux_v_correct<-vel_v*dens_v
187+
188+
189+
190+
191+
192+for (i in 1:n_int)
193+{
194+myseq2<-mymat[ ,2*i]*(mymat[ ,2*(i-1)+1])*(mymat[ ,2*(i-1)+1])
195+int_value3[i]<-def_integral(myseq2,h)
196+}
197+
198+
199+pdf("rho-velocity-squared-absorbing-1.pdf")
200+plot(x_seq,int_value3,col="blue",xlab=expression("x"),ylab=expression(" average [rho*(v squared)]"))
201+lines(x_seq,int_value3,lwd=2,col="red")
202+dev.off()
203+
204+
205+int_value3[ ]<-int_value3[ ]/int_value[ ] # now int_value3 contains <v>
206+
207+
208+
209+pdf("velocity-squared-absorbing-1.pdf")
210+plot(x_seq,int_value3,col="blue",xlab=expression("x"),ylab=expression(" average v squared"))
211+lines(x_seq,int_value3,lwd=2,col="red")
212+dev.off()
213+
214+velsq_v<-int_value3
215+
216+for (i in 1:n_int)
217+{
218+myseq2<-mymat[ ,2*i]*(mymat[ ,2*(i-1)+1])*(mymat[ ,2*(i-1)+1])
219+int_value4[i]<-def_integral(myseq2,h)
220+}
221+
222+pdf("rho-velocity-fluctuations-squared-absorbing-1.pdf")
223+plot(x_seq,int_value4,col="blue",xlab=expression("x"),ylab=expression(" average (rho*sig_vv squared)"))
224+lines(x_seq,int_value4,lwd=2,col="red")
225+dev.off()
226+
227+
228+int_value4[ ]<-int_value4[ ]/int_value[ ]-int_value2[ ]*int_value2[ ]
229+
230+
231+pdf("velocity-fluctuations-squared-absorbing-1.pdf")
232+plot(x_seq,int_value4,col="blue",xlab=expression("x"),ylab=expression(" average (sig_vv squared)"))
233+lines(x_seq,int_value4,lwd=2,col="red")
234+dev.off()
235+
236+sig_v<-int_value4
237+
238+# Now I compare these results to the ones predicted by Alichenkov
239+vel_ali1<-function(chi,sig)
240+{
241+(1-chi)/(1+chi)*sqrt(2*sig/pi)
242+}
243+
244+vel_ali2<-function(chi,vsq)
245+{
246+(1-chi)/(1+chi)*sqrt(2*vsq/pi)
247+}
248+
249+chi<-0 # perfect absorption
250+
251+vel_model1<-function()
252+{
253+vel_ali1(chi=chi,sig=int_value4)
254+}
255+
256+vel_model2<-function()
257+{
258+vel_ali2(chi=chi,vsq=int_value3)
259+}
260+
261+vel1<-vel_model1()
262+vel2<-vel_model2()
263+
264+#Now I add Nagvi's results for the density
265+nagvi_den<-function(b,D,x_ini,x)
266+{
267+b/((D+b*x_ini)*x_ini*(1-0.5*b*x_ini/(D+b*x_ini)))*(x-x_ini)+1/(x_ini*(1-0.5*b*x_ini/(D+b*x_ini)))
268+}
269+
270+nagvi<-function()
271+{
272+nagvi_den(b,D,x_ini,x)
273+}
274+
275+b<-1
276+D<-1/100
277+x_ini<-8
278+x<-x_seq
279+
280+ana_dens<-nagvi()
281+
282+
283+
284+# Now I'll create a plot with the 3 velocities together
285+
286+pdf("velocity-absorbing-comparison-Alichenko.pdf")
287+plot(x_seq,int_value2,col="blue",xlab=expression("x"),ylab=expression(" average v"),type="b",
288+ylim=range(c(min(int_value2,vel1,vel2),max(int_value2,vel1,vel2))))
289+#lines(x_seq,int_value2,lwd=2,col="blue")
290+#lines(x_seq,vel1,lwd=2,col="red")
291+lines(x_seq,vel1,lwd=2,col="red",type="b")
292+#lines(x_seq,vel2,lwd=2,col="black")
293+lines(x_seq,vel2,lwd=2,col="black",type="b")
294+legend(0.4, 1, c(expression("Numerics"), expression("Alipchenkov eq 6"), expression("Alipchenkov eq 15")),
295+lwd= c(2, 2,2),col=c("blue","red","black" ))
296+
297+dev.off()
298+
299+
300+###################################################
301+##################################################
302+
303+
304+
305+rm(mymat)
306+rm(dat_temp)
307+
308+
309+for(i in 1:lendat)
310+{
311+ fn <- paste("../../../no-convection/v0-0/final/rnc",i,".txt",sep="")
312+ dat <- read.table(fn,header=FALSE)
313+ # ... do your stuff on "dat" here ...
314+ dat_temp<-as.matrix(dat)
315+{
316+if (i ==1) {mymat<-dat_temp}
317+
318+else
319+mymat<-cbind(mymat,dat_temp)
320+}
321+}
322+
323+for(i in 1:n_int)
324+{
325+myseq2<-mymat[ ,2*i]
326+int_value[i]<-def_integral(myseq2,h)
327+}
328+
329+
330+
331+
332+
333+print("the density at wall is")
334+print(int_value[1])
335+
336+dens<-int_value/(0.706045)
337+
338+pdf("2density-absorbing-1.pdf")
339+plot(x_seq,int_value/int_value[1],col="blue",xlab=expression("x"),ylab=expression(" average v "))
340+lines(x_seq,int_value/int_value[1],lwd=2,col="red")
341+dev.off()
342+
343+
344+
345+save_data<-matrix(ncol=2,nrow=n_int)
346+save_data[ ,2]<-int_value[ ]
347+save_data[ ,1]<-x_seq[ ]
348+
349+
350+
351+
352+write.table(save_data,"density-normalized.txt",quote=FALSE,row.names=FALSE)
353+
354+#Now I can plot and work out other quantities.
355+#mymat[ ,2]<-mymat[ ,1]*mymat[ ,2]
356+
357+for (i in 1:n_int)
358+{
359+myseq2<-mymat[ ,2*i]*mymat[ ,2*(i-1)+1]
360+int_value2[i]<-def_integral(myseq2,h)
361+}
362+
363+
364+
365+pdf("2flux-absorbing-1.pdf")
366+plot(x_seq,int_value2,col="blue",xlab=expression("x"),ylab=expression("J= average (rho*v)"))
367+lines(x_seq,int_value2,lwd=2,col="red")
368+dev.off()
369+
370+flux<-int_value2
371+
372+int_value2[ ]<-int_value2[ ]/int_value[]
373+
374+pdf("2velocity-absorbing-1.pdf")
375+plot(x_seq,int_value2,col="blue",xlab=expression("x"),ylab=expression(" average v"))
376+lines(x_seq,int_value2,lwd=2,col="red")
377+dev.off()
378+
379+
380+vel<-int_value2
381+flux_correct<-vel*dens
382+
383+for (i in 1:n_int)
384+{
385+myseq2<-mymat[ ,2*i]*(mymat[ ,2*(i-1)+1])*(mymat[ ,2*(i-1)+1])
386+int_value3[i]<-def_integral(myseq2,h)
387+}
388+
389+
390+pdf("2rho-velocity-squared-absorbing-1.pdf")
391+plot(x_seq,int_value3,col="blue",xlab=expression("x"),ylab=expression(" average [rho*(v squared)]"))
392+lines(x_seq,int_value3,lwd=2,col="red")
393+dev.off()
394+
395+
396+int_value3[ ]<-int_value3[ ]/int_value[ ] # now int_value3 contains <v>
397+
398+
399+
400+pdf("2velocity-squared-absorbing-1.pdf")
401+plot(x_seq,int_value3,col="blue",xlab=expression("x"),ylab=expression(" average v squared"))
402+lines(x_seq,int_value3,lwd=2,col="red")
403+dev.off()
404+
405+velsq<-int_value3
406+
407+for (i in 1:n_int)
408+{
409+myseq2<-mymat[ ,2*i]*(mymat[ ,2*(i-1)+1])*(mymat[ ,2*(i-1)+1])
410+int_value4[i]<-def_integral(myseq2,h)
411+}
412+
413+pdf("2rho-velocity-fluctuations-squared-absorbing-1.pdf")
414+plot(x_seq,int_value4,col="blue",xlab=expression("x"),ylab=expression(" average (rho*sig_vv squared)"))
415+lines(x_seq,int_value4,lwd=2,col="red")
416+dev.off()
417+
418+
419+int_value4[ ]<-int_value4[ ]/int_value[ ]-int_value2[ ]*int_value2[ ]
420+
421+
422+pdf("2velocity-fluctuations-squared-absorbing-1.pdf")
423+plot(x_seq,int_value4,col="blue",xlab=expression("x"),ylab=expression(" average (sig_vv squared)"))
424+lines(x_seq,int_value4,lwd=2,col="red")
425+dev.off()
426+
427+sig<-int_value4
428+
429+# Now I compare these results to the ones predicted by Alichenkov
430+#vel_ali1<-function(chi,sig)
431+#{
432+#(1-chi)/(1+chi)*sqrt(2*sig/pi)
433+#}
434+
435+#vel_ali2<-function(chi,vsq)
436+#{
437+#(1-chi)/(1+chi)*sqrt(2*vsq/pi)
438+#}
439+
440+#chi<-0 # perfect absorption
441+
442+#vel_model1<-function()
443+#{
444+#vel_ali1(chi=chi,sig=int_value4)
445+#}
446+
447+#vel_model2<-function()
448+#{
449+#vel_ali2(chi=chi,vsq=int_value3)
450+#}
451+
452+vel1bis<-vel_model1()
453+vel2bis<-vel_model2()
454+
455+# Now I'll create a plot with the 3 velocities together
456+
457+pdf("2velocity-absorbing-comparison-Alichenko.pdf")
458+plot(x_seq,int_value2,col="blue",xlab=expression("x"),ylab=expression(" average v"),type="b",
459+ylim=range(c(min(int_value2,vel1bis,vel2bis),max(int_value2,vel1bis,vel2bis))))
460+#lines(x_seq,int_value2,lwd=2,col="blue")
461+#lines(x_seq,vel1,lwd=2,col="red")
462+lines(x_seq,vel1bis,lwd=2,col="red",type="b")
463+#lines(x_seq,vel2,lwd=2,col="black")
464+lines(x_seq,vel2bis,lwd=2,col="black",type="b")
465+legend(0.4, 1, c(expression("Numerics"), expression("Alipchenkov eq 6"), expression("Alipchenkov eq 15")),
466+lwd= c(2, 2,2),col=c("blue","red","black" ))
467+
468+dev.off()
469+######################################################################
470+######################################################################
471+
472+pdf("comparison-flux-wrong.pdf")
473+plot(x_seq,flux_v,col="blue",xlab=expression("x"),ylab=expression(" average flux"),
474+ylim=range(c(min(flux_v,flux),max(flux_v,flux))))
475+lines(x_seq,flux_v,col="blue", type="b")
476+lines(x_seq,flux,col="red")
477+lines(x_seq,flux,col="red",type="b")
478+dev.off()
479+
480+
481+pdf("comparison-flux-correct.pdf")
482+plot(x_seq,flux_v_correct,col="blue",xlab=expression("x"),ylab=expression(" average flux"),
483+ylim=range(c(min(flux_v_correct,flux_correct),max(flux_v_correct,flux_correct))),type="b")
484+#lines(x_seq,flux_v_correct,col="blue", type="b")
485+#lines(x_seq,flux_correct,col="red")
486+lines(x_seq,flux_correct,col="red",type="b")
487+dev.off()
488+
489+
490+
491+pdf("comparison-density.pdf")
492+plot(x_seq,dens_v,col="blue",xlab=expression("x"),ylab=expression(" density"),
493+ylim=range(c(min(dens_v,dens),max(dens_v,dens))),type="b")
494+lines(x_seq,ana_dens,lwd=2,col="black")
495+lines(x_seq,dens,col="red",type="b")
496+dev.off()
497+
498+
499+
500+pdf("comparison-sig.pdf")
501+plot(x_seq,sig_v,col="blue",xlab=expression("x"),ylab=expression(" average sig_vv squared"),
502+ylim=range(c(min(sig_v,sig),max(sig_v,sig))),type="b")
503+#lines(x_seq,sig_v,col="blue", type="b")
504+#lines(x_seq,sig,col="red")
505+lines(x_seq,sig,col="red",type="b")
506+dev.off()
507+
508+pdf("comparison-vel-squared.pdf")
509+plot(x_seq,velsq_v,col="blue",xlab=expression("x"),ylab=expression(" average v squared"),
510+ylim=range(c(min(velsq_v,velsq),max(velsq_v,velsq))),type="b")
511+#lines(x_seq,velsq_v,col="blue", type="b")
512+#lines(x_seq,velsq,col="red")
513+lines(x_seq,velsq,col="red",type="b")
514+dev.off()
515+
516+pdf("comparison-vel.pdf")
517+plot(x_seq,vel_v,col="blue",xlab=expression("x"),ylab=expression(" average v"),
518+ylim=range(c(min(vel_v,vel),max(vel_v,vel))),type="b")
519+#lines(x_seq,vel_v,col="blue", type="b")
520+#lines(x_seq,vel,col="red")
521+lines(x_seq,vel,col="red",type="b")
522+dev.off()
523+
524+
525+pdf("comparison-vel-bis.pdf")
526+plot(x_seq,vel_v,col="blue",xlab=expression("x"),ylab=expression(" average v"),
527+ylim=range(c(min(vel_v,vel),max(vel_v,vel))),type="b")
528+lines(x_seq,0.2*x_seq,col="green")
529+#lines(x_seq,vel,col="red")
530+lines(x_seq,vel,col="red",type="b")
531+dev.off()
532+
533+myseq2<-mymat_save[ ,2]
534+norm1<-def_integral(myseq2,h)
535+
536+myseq2<-mymat[ ,2]
537+norm2<-def_integral(myseq2,h)
538+
539+pdf("comparison-vel-profiles.pdf")
540+plot(mymat_save[ ,1],mymat_save[ ,2]/norm1
541+,col="blue","l",xlab=expression("v"),ylab=expression("f(x,v,t) at wall"))
542+lines(mymat[ ,1],mymat[ ,2]/norm2,col="red")
543+dev.off()
544+
545+
546+
547+
548+print("So far so good")
\ No newline at end of file