• R/O
  • SSH

提交

標籤
無標籤

Frequently used words (click to add to your profile)

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

Commit MetaInfo

修訂89465b6a444b6333459f9faa9faba64546caaf9e (tree)
時間2008-07-30 00:56:48
作者iselllo
Commiteriselllo

Log Message

I added a code which evaluates the kernel elements from a system
snapshot and compares those with the results from the analytical kernel
in the agglomeration equation.

Change Summary

差異

diff -r 92e573888427 -r 89465b6a444b Python-codes/kernel_from_collisions.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Python-codes/kernel_from_collisions.py Tue Jul 29 15:56:48 2008 +0000
@@ -0,0 +1,316 @@
1+#! /usr/bin/env python
2+
3+import scipy as s
4+import numpy as n
5+import pylab as p
6+
7+
8+
9+A=p.load("k_vec_binary00004.dat")
10+
11+
12+d = {}
13+for r in A:
14+ t = tuple(r)
15+ d[t] = d.get(t,0) + 1
16+
17+# The dict d now has the counts of the unique rows of A.
18+
19+B = n.array(d.keys()) # The unique rows of A
20+C = n.array(d.values()) # The counts of the unique rows
21+
22+
23+def kernel_calc(A):
24+
25+
26+
27+ d = {}
28+ for r in A:
29+ t = tuple(r)
30+ d[t] = d.get(t,0) + 1
31+
32+ # The dict d now has the counts of the unique rows of A.
33+
34+ B = n.array(d.keys()) # The unique rows of A
35+ C = n.array(d.values()) # The counts of the unique rows
36+
37+ return B,C
38+
39+
40+
41+
42+
43+print "A is, ", A
44+
45+print "B is, ", B
46+
47+print "C is, ", C
48+
49+
50+mycalc=kernel_calc(A)
51+
52+print "mycalc is, ", mycalc
53+
54+
55+print "mycalc[0] is, ", mycalc[0]
56+
57+
58+print "mycalc[1] is, ", mycalc[1]
59+
60+B2=mycalc[0]
61+C2=mycalc[1]
62+
63+
64+print "B is, ", B2
65+
66+print "C is, ", C2
67+
68+print "B-B2 is, ", B-B2
69+
70+print "C-C2 is, ", C-C2
71+
72+
73+
74+#Now proper evaluation of the kernel!
75+
76+dist=p.load("cluster_dist00003")
77+
78+print "dist is,", dist
79+
80+delta_t=2. #in the complete code, make this automatic from the reading of the file time.dat
81+
82+#I need to create an n_in_j matrix from the ij matrix (B2!!!!)
83+
84+
85+
86+dim=s.shape(B2)
87+
88+
89+
90+n_i=s.zeros(dim[0])
91+
92+
93+n_j=s.zeros(dim[0])
94+
95+
96+print "n_i is, ", n_i
97+
98+for i in xrange(len(B2[:,0])):
99+ print "B2[i,0] is, ", B2[i,0]
100+ n_i[i]=len(s.where(dist==B2[i,0])[0])
101+ n_j[i]=len(s.where(dist==B2[i,1])[0])
102+
103+
104+print "n_i, nj now are, ", n_i, n_j
105+
106+
107+
108+
109+
110+kernel_list=C2/(n_i*n_j)
111+
112+
113+print "kernel_list is, ", kernel_list
114+
115+
116+
117+
118+#Now I define a function to do the same as above
119+
120+
121+def kernel_entries(B2, dist, C2):
122+ dim=s.shape(B2)
123+ print "dim is, ", dim
124+
125+ n_i=s.zeros(dim[0])
126+ n_j=s.zeros(dim[0])
127+
128+
129+
130+ for i in xrange(len(B2[:,0])):
131+
132+ n_i[i]=len(s.where(dist==B2[i,0])[0])
133+ n_j[i]=len(s.where(dist==B2[i,1])[0])
134+
135+ kernel_list=C2/(n_i*n_j) #I do not get the whole kernel matrix,
136+ #but only the matrix elements for the collisions which actually took place
137+
138+ return kernel_list
139+
140+
141+
142+
143+kernel_list2=kernel_entries(B2, dist, C2)
144+
145+print "kernel_list2 is, ", kernel_list2
146+
147+print "kernel_list-kernel_list2 is, ", kernel_list-kernel_list2
148+
149+
150+
151+
152+#Now the "correct" function to evaluate the kernel where n_i and n_j are expressed as concentrations
153+#i.e. number of clusters with i and j monomers divided by the box volume
154+
155+
156+def kernel_entries_normalized(B2, dist, C2, box_vol, delta_t):
157+ dim=s.shape(B2)
158+ print "dim is, ", dim
159+
160+ n_i=s.zeros(dim[0])
161+ n_j=s.zeros(dim[0])
162+
163+
164+
165+ for i in xrange(len(B2[:,0])):
166+
167+ n_i[i]=len(s.where(dist==B2[i,0])[0])
168+ n_j[i]=len(s.where(dist==B2[i,1])[0])
169+
170+ n_i=n_i/box_vol
171+ n_j=n_j/box_vol
172+
173+
174+
175+ kernel_list=C2/(n_i*n_j*delta_t*box_vol) #I do not get the whole kernel matrix,
176+ #but only the matrix elements for the collisions which actually took place
177+
178+ return kernel_list
179+
180+
181+box_vol=5000./0.01
182+
183+kernel_corr=kernel_entries_normalized(B2, dist, C2, box_vol,delta_t)
184+
185+
186+
187+
188+
189+print "the kernel elements are, ", kernel_corr
190+
191+
192+
193+
194+
195+
196+
197+
198+
199+
200+
201+
202+#Now a calculation from the continuum kernel, two fractal dimensions and beta
203+
204+a_small=0.36
205+df_small=2.20
206+
207+a_large=0.24
208+df_large=1.62
209+
210+T_0=0.5
211+
212+
213+
214+r_mon=0.5
215+
216+v_mono=4./3.*s.pi*r_mon**3.
217+
218+print "the monodisperse volume is, ", v_mono
219+
220+x=s.linspace(v_mono, v_mono*5.,5) # volume grid
221+
222+n_mon=x/v_mono #volume of solids expressed in terms of number of monomers
223+
224+print "n_mon is, ", n_mon
225+
226+beta=1. #cluster/monomer 1/tau
227+k_B=1. #in these units
228+T_0=0.5 #temperature of the system
229+m_mon=1. #monomer mass in these units
230+sigma=1. #monomer diameter
231+mu=(m_mon*beta)/(3.*s.pi*sigma) # fluid viscosity
232+
233+
234+threshold=15. # I define the threshold between small and large clusters, to be used where it matters.
235+
236+
237+small=s.where(n_mon<=threshold)
238+large=s.where(n_mon>threshold)
239+
240+
241+
242+def Brow_ker_cont_optim_diffusion_adjusted_and_monomer_beta_fuchs(Vlist):
243+ #monomer volume
244+ #r_mon=0.5 #monomer radius
245+ #v_mon=4./3.*s.pi*r_mon**3.
246+ #v_mono already defined as a global variable
247+ #n_mon=Vlist/v_mono #number of monomers in each aggregate
248+
249+ #print "n_mon is, ", n_mon
250+
251+ Diff=k_B*T_0/(n_mon*m_mon*beta) #vector with the cluster diffusion coefficients
252+ #which just depends on the cluster size.
253+
254+ R_list=s.zeros(len(Vlist)) #I initialize the array which will contain the
255+ #radia of gyration
256+
257+ #threshold=15.
258+
259+# small=s.where(n_mon<=threshold)
260+# large=s.where(n_mon>threshold)
261+
262+# a_small=0.36
263+# df_small=2.19
264+
265+# a_large=0.241
266+# df_large=1.62
267+
268+
269+ R_list[small]=a_small*n_mon[small]**(1./df_small)
270+
271+ R_list[large]=a_large*n_mon[large]**(1./df_large)
272+
273+# R_list[0]=0.5 #special case for the monomer radius
274+
275+# m=rho_p*Vlist # this holds in general (i.e. for Vlist !=3.)
276+ ## as long as Vlist is the volume of solid
277+ ##and not the space occupied by the agglomerate structure
278+
279+ m=Vlist #since rho = 1.
280+
281+ c=(8.*k_B*T_0/(s.pi*m))**0.5
282+ #print 'c is', c
283+ l=8.*Diff/(s.pi*c)
284+ #print 'l is', l
285+ diam_seq=2.*R_list
286+
287+ g=1./(3.*diam_seq*l)*((diam_seq+l)**3.-(diam_seq**2.+l**2.)**1.5)-diam_seq
288+
289+ beta_fuchs=(\
290+ (diam_seq[:,s.newaxis]+diam_seq[s.newaxis,:]) \
291+ /(diam_seq[:,s.newaxis]+diam_seq[s.newaxis,:]\
292+ +2.*(g[:,s.newaxis]**2.+g[s.newaxis,:]**2.)**0.5)\
293+ + 8.*(Diff[:,s.newaxis]+Diff[s.newaxis,:])/\
294+ ((c[:,s.newaxis]**2.+c[s.newaxis,:]**2.)**0.5*\
295+ (diam_seq[:,s.newaxis]+diam_seq[s.newaxis,:]))\
296+ )**(-1.)
297+
298+
299+ ## now I have all the bits for the kernel matrix
300+# kern_mat=Brow_ker_cont_optim(Vlist)*beta
301+
302+
303+ kern_mat=4.*s.pi*(Diff[:,s.newaxis]+Diff[s.newaxis,:])* \
304+ (R_list[:,s.newaxis]+R_list[s.newaxis,:])*beta_fuchs
305+
306+
307+ return kern_mat
308+
309+
310+
311+kernel_smolu=Brow_ker_cont_optim_diffusion_adjusted_and_monomer_beta_fuchs(x)
312+
313+print "smoluchowski kernel is, ", kernel_smolu
314+
315+
316+print "So far so good"