• 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

Revision8f80def58fb25e3c117d63fa251bac5fe5fa4db8 (tree)
Zeit2009-01-20 03:05:19
Autoriselllo
Commiteriselllo

Log Message

Now the code reads most of the parameters from an input data file (apart from the monomers radia).
The code is now able to save also some intermediate results during the evolution of the system.
Still being developed, check everything!

Ändern Zusammenfassung

Diff

diff -r dd33bff1ad74 -r 8f80def58fb2 Python-codes/wiener.py
--- a/Python-codes/wiener.py Mon Jan 19 14:55:24 2009 +0000
+++ b/Python-codes/wiener.py Mon Jan 19 18:05:19 2009 +0000
@@ -3,11 +3,56 @@
33 import numpy as n
44 import pylab as p
55
6+import csv
7+
8+
69
710 #import absorbe as abso #compiled fortran code for detecting molecule-to-gas collisions
811 import absorbe_snap as absnap #compiled fortran code for detecting molecule-to-gas collisions
912
1013
14+#! /usr/bin/env python
15+import scipy as s
16+import csv
17+
18+
19+def read_input(filename):
20+
21+
22+ param_name_list=[]
23+ param_value_list=[]
24+
25+
26+
27+ reader = csv.reader(open(filename, 'r'), delimiter = ',')
28+ line = 0
29+ # I changed the two following lines into comments since I do not have a header I should skip
30+
31+ #IndexHeader = reader.next()
32+ #line = line+1
33+ for line in reader:
34+ #print line
35+ param_name, param_value = line[0], line[1]
36+
37+ param_name_list.append(param_name)
38+ param_value_list.append(float(param_value))
39+
40+
41+
42+ #print "param_name_list is, ", param_name_list
43+ #print "param_name_list is, ", param_value_list
44+
45+ param_arr=s.asarray(param_value_list)
46+
47+ #print "param_arr is, ", param_arr
48+
49+ #print "param_name_list[2] is, ", param_name_list[2]
50+
51+ return param_arr
52+
53+
54+
55+
1156
1257 def evolve_by_time_step(amplitude,t_step,N_part,L,pos_at_t):
1358
@@ -39,7 +84,9 @@
3984
4085 n_iter=int(round(t_fin/t_step))
4186
42- my_mod=int(round(t_fin/t_step))/10
87+ #my_mod=int(round(t_fin/t_step))/10
88+
89+ save_every=n_iter/number_save
4390
4491 #print "N_iter is, ", n_iter
4592
@@ -48,7 +95,7 @@
4895
4996 for i in xrange(n_iter):
5097
51- if (s.remainder(i,my_mod) == 0 ):
98+ if ((s.remainder(i,save_every) == 0) & (i>0) ):
5299
53100 print "i is, ", i
54101 #print "monomer_pos are, ", monomer_pos[:,0]
@@ -111,6 +158,149 @@
111158
112159 return results
113160
161+def evolution_and_absorption_intermediate_save(monomer_pos,number_monomers,amplitude,t_step,\
162+ N_part,L, pos_at_t,r1_arr,ini_coll_mat, number_save):
163+
164+
165+ n_iter=int(round(t_fin/t_step))
166+
167+
168+
169+ save_every=n_iter/number_save
170+
171+ snap_num=0
172+
173+
174+ for i in xrange(n_iter):
175+
176+
177+ if (i==0):
178+
179+ results=absnap.absorption_snap_calc(pos_at_t, monomer_pos[:,0], \
180+ monomer_pos[:,1], \
181+ monomer_pos[:,2], r1_arr, i, ini_coll_mat)
182+
183+ results_temp=s.copy(results)
184+
185+
186+
187+
188+ elif (i !=0):
189+
190+
191+
192+ temp=1 #which means I am now saving temporary files during the evolution
193+
194+
195+
196+ results=absnap.absorption_snap_calc(pos_at_t, monomer_pos[:,0], \
197+ monomer_pos[:,1], \
198+ monomer_pos[:,2], r1_arr, i, results_temp)
199+
200+ results_temp=s.copy(results)
201+
202+ if ((s.remainder(i,save_every) == 0) & (i>0) ):
203+
204+ snap_num=snap_num + 1
205+
206+ print "saving snapshot number , ", snap_num
207+
208+ #Now save the intermediate results
209+
210+ abso_temp=absorption_individual_monomers(number_mon,results,time, temp, snap_num )
211+
212+
213+ stat_coll=stat_collisions(results, time, 0)
214+
215+ prefix="temp_%01d"%snap_num
216+
217+ filename="_collision_statistics.dat"
218+
219+ filename=prefix+filename
220+
221+ p.save(filename,stat_coll )
222+
223+
224+
225+
226+
227+ #Now we perform some statistical analysis of the data
228+
229+ number_molecules_vs_time=count_molecules(results,N_part,stat_coll, t_step)
230+
231+ filename="_number_molecules_vs_time.dat"
232+
233+ filename=prefix+filename
234+
235+ p.save(filename,number_molecules_vs_time)
236+
237+ p.save("intermediate_mol_position.dat",pos_at_t )
238+ p.save("intermediate_time.dat",(t_step*i*s.ones(1)) )
239+
240+
241+
242+ pos_at_t=evolve_by_time_step(amplitude,t_step,N_part,L,pos_at_t)
243+
244+
245+
246+
247+ return results
248+
249+
250+
251+
252+
253+def absorption_individual_monomers(number_mon,new_abso,time, temp, snap_num):
254+
255+ for m in xrange(number_mon):
256+
257+ abso_mon=select_absorption(new_abso,(m+1)) #careful about the m+1 appearing in several places:
258+ #it comes from
259+ # the fortran routine way of labelling the molecules
260+
261+ if (temp ==1):
262+
263+ prefix="temp_%01d"%snap_num
264+
265+ filename="_abso_%01d"%(m+1)
266+
267+ filename=prefix+filename
268+
269+ elif (temp != 1):
270+
271+ filename="abso_%01d"%(m+1)
272+
273+ filename=filename+".dat"
274+
275+ p.save(filename,abso_mon )
276+
277+
278+
279+
280+
281+ stat_coll=stat_collisions(abso_mon, time, 0)
282+
283+ if (temp == 1):
284+
285+ prefix="temp_%01d"%snap_num
286+
287+ filename="_collision_statistics_%01d"%(m+1)
288+
289+ filename=prefix+filename
290+
291+
292+ elif (temp !=1):
293+
294+ filename="collision_statistics_%01d"%(m+1)
295+
296+
297+ filename=filename+".dat"
298+
299+ p.save(filename,stat_coll )
300+
301+ return 0
302+
303+
114304
115305
116306
@@ -481,24 +671,59 @@
481671 #######################################################################
482672 #######################################################################
483673
484-L=3.
485-
486-t_fin=20.
674+# L=3.
487675
488-t_step=0.001
676+# t_fin=20.
489677
490-amplitude=2.
678+# t_step=0.001
491679
492-N_part=30000
680+# amplitude=2.
681+
682+# N_part=30000
493683
494684
495-number_mon=2 #indicate the number of monomers
685+# number_mon=2 #indicate the number of monomers
496686
497-mon_rad=s.ones(number_mon)*0.5
687+# mon_rad=s.ones(number_mon)*0.5
498688
499689
500690
501-fold=1 #whether I should fold the trajectories inside the box or they have already been saved that way
691+input_arr=read_input("input.csv")
692+
693+#print "input_arr is, ", input_arr
694+
695+
696+L=input_arr[0]
697+
698+#print "L is, ", L
699+
700+t_ini=input_arr[1]
701+
702+t_fin=input_arr[2]
703+
704+t_step=input_arr[3]
705+
706+
707+
708+N_part=int(round(input_arr[4]))
709+number_mon=int(round(input_arr[5]))
710+number_save=int(round(input_arr[6])) #how many intermediate results I am supposed to save
711+
712+read_ini_pos=int(round(input_arr[7])) #whether I should read the initial position of the molecules \
713+# from another simulation or not
714+
715+read_radia=int(round(input_arr[8])) #whether I should read the list of the radia of the monomers from a file
716+
717+if (read_radia == 1):
718+ mon_rad=p.load("radia.csv", delimiter=",")
719+
720+
721+amplitude=input_arr[9]
722+
723+
724+#I do not need that any longer since I am now using the code in a different way
725+
726+#fold=1 #whether I should fold the trajectories inside the box or they have already been saved that way
502727
503728
504729
@@ -510,9 +735,9 @@
510735 time=s.linspace(0.,t_fin,(int(t_fin/t_step)+1) )
511736 p.save("time.dat", time)
512737
738+#I am no longe using the "read" parameter: the code no longer reads the trajectories to start with
513739
514-
515-read=1 #it means that the code will read some already-generated trajectories
740+#read=1 #it means that the code will read some already-generated trajectories
516741 # rather than calculate them on the fly
517742
518743
@@ -590,8 +815,12 @@
590815
591816
592817
593-new_abso=evolution_and_absorption(monomer_pos,number_mon,amplitude,t_step,\
594- N_part,L, initial_pos,mon_rad ,coll_matrix_ini)
818+#new_abso=evolution_and_absorption(monomer_pos,number_mon,amplitude,t_step,\
819+# N_part,L, initial_pos,mon_rad ,coll_matrix_ini)
820+
821+
822+new_abso=evolution_and_absorption_intermediate_save(monomer_pos,number_mon,amplitude,t_step,\
823+ N_part,L, initial_pos,mon_rad,coll_matrix_ini, number_save)
595824
596825
597826 print "OK after test2"