• R/O
  • SSH

提交

标签
No Tags

Frequently used words (click to add to your profile)

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

Commit MetaInfo

修订版8b4222acf1f0c5903aa23a88c6e32bf4f834ced2 (tree)
时间2007-12-06 23:41:32
作者iselllo
Commiteriselllo

Log Message

I updated plot_statistics.py; now the code is also able to calculate the
velocity autocorrelation function.

更改概述

差异

diff -r cd60708cc67b -r 8b4222acf1f0 Python-codes/plot_statistics.py
--- a/Python-codes/plot_statistics.py Tue Dec 04 12:34:22 2007 +0000
+++ b/Python-codes/plot_statistics.py Thu Dec 06 14:41:32 2007 +0000
@@ -5,11 +5,31 @@
55 import pylab as p
66
77 n_part=3000
8-n_config=100
8+n_config=100 # total number of configurations, which are numbered from 0 to n_config-1
99 t_step=1.
1010
1111 config_ini=50
1212
13+time=s.linspace(0.,((n_config-1)*t_step),n_config) #I define the time along the simulation
14+
15+
16+
17+
18+#some physical parameters of the system
19+T=0.1 #temperature
20+beta=0.1 #damping coefficient
21+v_0=0. #initial particle mean velocity
22+
23+
24+n_s_ini=40 #element in the time-sequence corresponding
25+ # to the chosen reference time for calculating the velocity autocorrelation
26+ #function
27+
28+s_ini=(n_s_ini)*t_step #I define a specific time I will need for the calculation
29+# of the autocorrelation function
30+
31+print 'the time chosen for the velocity correlation function is, ', s_ini
32+print 'and the corresponding time on the array is, ', time[n_s_ini]
1333
1434
1535
@@ -60,14 +80,17 @@
6080 mean_x_arr=s.zeros(n_config)
6181 var_x_arr=s.zeros(n_config)
6282
63- for i in xrange(0, n_config):
64- mean_x_arr[i]=s.mean(x_arr[i,:])
65- var_x_arr[i]=s.var(x_arr[i,:])
83+ #for i in xrange(0, n_config):
84+ #mean_x_arr[i]=s.mean(x_arr[i,:])
85+ #var_x_arr[i]=s.var(x_arr[i,:])
86+
87+ mean_x_arr[:]=s.mean(x_arr,axis=1)
88+ var_x_arr[:]=s.var(x_arr,axis=1)
89+
6690
6791 print "mean_x_arr is, ", mean_x_arr
6892 print "var_x_arr is, ", var_x_arr
6993
70- time=s.linspace(0.,(n_config*t_step),n_config)
7194
7295 p.plot(time, var_x_arr ,linewidth=2.)
7396 p.xlabel('time')
@@ -79,24 +102,105 @@
79102 p.hold(False)
80103
81104 p.save("mean_square_disp.dat", var_x_arr)
105+# Now I do pretty much the same thing with the velocity
82106
107+ tot_config_vel=p.load("total_configuration_vel.dat")
108+
109+
110+
111+
112+
113+ print "the length of tot_config is, ", len(tot_config)
114+ tot_config_vel=s.reshape(tot_config_vel,(n_config,3*n_part))
115+
116+ #print "tot_config at line 10 is, ", tot_config[10,:]
117+
118+
119+ v_0=tot_config_vel[0,0] #initial x position of all my particles
120+ v_arr=s.zeros((n_config,n_part))
121+ print 'OK creating v_arr'
122+ v_col=s.arange(n_part)*3
123+
124+ #print "x_col is, ", x_col
125+
126+ for i in xrange(0,n_part):
127+ v_arr[:,i]=tot_config_vel[:,3*i]
128+
129+ mean_v_arr=s.zeros(n_config)
130+ var_v_arr=s.zeros(n_config)
131+
132+# for i in xrange(0, n_config):
133+ # mean_v_arr[i]=s.mean(v_arr[i,:])
134+ #var_v_arr[i]=s.var(v_arr[i,:])
135+
136+ mean_v_arr[:]=s.mean(v_arr,axis=1)
137+ var_v_arr[:]=s.var(v_arr,axis=1)
138+
139+
140+
141+
142+ #print "mean_v_arr is, ", mean_v_arr
143+ #print "var_v_arr is, ", var_v_arr
144+
145+ #time=s.linspace(0.,(n_config*t_step),n_config)
146+
147+ p.plot(time, var_v_arr ,linewidth=2.)
148+ p.xlabel('time')
149+ p.ylabel('velocity variance')
150+ #p.legend(('beta=1e-2,100 part','beta=1e-1, 100 part', 'beta=1e-1, 200 part'))
151+ p.title('VAR(v) vs time')
152+ p.grid(True)
153+ p.savefig('velocity_variance.pdf')
154+ p.hold(False)
155+
156+ p.save("velocity_variance.dat", var_v_arr)
157+
158+ #Now I want to calculate the autocorrelation function.
159+ #First, I need to fix an intial time. I choose something which is well past the
160+ #ballistic regime
161+
162+
163+
164+ #Now I start calculating the velocity autocorrelation function
165+
166+ vel_autocor=s.zeros(n_config)
167+
168+
169+
170+ for i in xrange(0, n_config):
171+ vel_autocor[i]=s.mean(v_arr[i]*v_arr[n_s_ini])
172+
173+
174+ p.plot(time, vel_autocor ,linewidth=2.)
175+ p.xlabel('time')
176+ p.ylabel('<v(s)v(t)> ')
177+ #p.legend(('beta=1e-2,100 part','beta=1e-1, 100 part', 'beta=1e-1, 200 part'))
178+ p.title('Velocity correlation')
179+ p.grid(True)
180+ p.savefig('velocity_correlation_numerics.pdf')
181+ p.hold(False)
182+
183+
184+ p.save("velocity_autocorrelation.dat", vel_autocor)
185+
186+
187+
188+
189+
83190 elif (calculate ==0):
84191
85192 var_x_arr=p.load("mean_square_disp.dat")
86193
87194 #now some analytics of the mean-square displacement
88- def x_sq(T,Gamma,v_0 ,t):
89- z=2.*T/(Gamma)*t+v_0**2./Gamma**2.*(1.-s.exp(-Gamma*t))\
90- -T/Gamma**2.*(3.-4.*s.exp(-Gamma*t)+s.exp(-2.*Gamma*t))
195+ def x_sq(T,beta,v_0 ,t):
196+ z=2.*T/(beta)*t+v_0**2./beta**2.*(1.-s.exp(-beta*t))\
197+ -T/beta**2.*(3.-4.*s.exp(-beta*t)+s.exp(-2.*beta*t))
91198 return z
92199
93- time=s.linspace(0.,(n_config*t_step),n_config)
200+# time=s.linspace(0.,(n_config*t_step),n_config)
94201
95- T=0.1
96- Gamma=0.1
97- v_0=0.
98202
99- x_sq_book=x_sq(T,Gamma,v_0,time)
203+ x_sq_book=x_sq(T,beta,v_0,time)
100204
101205 p.plot(time, var_x_arr,time, x_sq_book ,linewidth=2.)
102206 p.xlabel('time')
@@ -106,8 +210,84 @@
106210 p.grid(True)
107211 p.savefig('mean_square_disp_comparison_analytics.pdf')
108212 p.hold(False)
213+
214+ #now a similar thing for the velocity
215+
216+ def v_sq(T,beta,v_0,Gamma,t):
217+ z=Gamma**2./(2.*beta)+(v_0**2.-Gamma**2./(2.*beta))*s.exp(-2.*beta*t)
218+ return z
219+
220+ Gamma=s.sqrt(2.*beta*T)
221+
222+ #NB: Gamma (NOT the damping parameter which I call beta here!!!) is related to the nosie strength i.e.
223+ # Gamma**2./(2*beta)=k_BT/m i.e. Gamma=sqrt(2*beta*k_b*T/m), but I work in units where
224+ #Gamma=sqrt(2*beta*T)
225+
226+
227+ v_sq_book=v_sq(T,beta,v_0,Gamma,time)
228+
229+ var_v_arr=p.load("velocity_variance.dat")
230+
231+
232+ p.plot(time, var_v_arr,time, v_sq_book ,linewidth=2.)
233+ p.xlabel('time')
234+ p.ylabel('velocity variance ')
235+ #p.legend(('beta=1e-2,100 part','beta=1e-1, 100 part', 'beta=1e-1, 200 part'))
236+ p.title('VAR(x) vs time')
237+ p.grid(True)
238+ p.savefig('velocity_variance_comparison_analytics.pdf')
239+ p.hold(False)
240+
241+ def vel_corr(t,s_ini,v_0,beta,T):
242+ z=(v_0**2.-T)*s.exp(-beta*(t+s_ini))+T*s.exp(-beta*abs(t-s_ini))
243+# z=(v_0**2.-T)*s.exp(-t/10.)
244+ return z
245+
246+# def vel_corr_asym(t,s,beta,T):
247+ # z=T*s.exp(-beta*abs(t-s))
248+ #return z
249+
250+
251+
252+
253+ print 'the initial time for the velocity correlation is',s_ini
254+
255+ print 'T is,', T
256+ print 'beta is, ', beta
257+ print 'time is, ', time
258+ print 'v_0 is, ', v_0
259+ my_vel_corr= vel_corr(time,s_ini,v_0,beta,T)
260+ print 'my_vel_corr is, ', my_vel_corr
261+
109262
110263
111264
112265
113-print "So far so good"
\ No newline at end of file
266+ print 'OK before plot'
267+
268+ p.plot(time, my_vel_corr ,linewidth=2.)
269+ p.xlabel('time')
270+ p.ylabel('<v(s)v(t)> ')
271+ #p.legend(('beta=1e-2,100 part','beta=1e-1, 100 part', 'beta=1e-1, 200 part'))
272+ p.title('Velocity correlation')
273+ p.grid(True)
274+ p.savefig('velocity_correlation_analytics.pdf')
275+ p.hold(False)
276+
277+ #Now I read the velocity autocorrelation function I calculated numerically
278+ # and try seeing how it compares with the analytics
279+
280+ vel_autocor_numerics=p.load("velocity_autocorrelation.dat")
281+
282+
283+ p.plot(time, vel_autocor_numerics,time, my_vel_corr ,linewidth=2.)
284+ p.xlabel('time')
285+ p.ylabel('velocity autocorrelation ')
286+ p.legend(('Numerical Result','Analytical Result'))
287+ p.title('Velocity Autocorrelation')
288+ p.grid(True)
289+ p.savefig('velocity_autocorrelation_comparison_numerics_analytics.pdf')
290+ p.hold(False)
291+
292+
293+print "So far so good"