Revision | 8f80def58fb25e3c117d63fa251bac5fe5fa4db8 (tree) |
---|---|
Zeit | 2009-01-20 03:05:19 |
Autor | iselllo |
Commiter | iselllo |
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!
@@ -3,11 +3,56 @@ | ||
3 | 3 | import numpy as n |
4 | 4 | import pylab as p |
5 | 5 | |
6 | +import csv | |
7 | + | |
8 | + | |
6 | 9 | |
7 | 10 | #import absorbe as abso #compiled fortran code for detecting molecule-to-gas collisions |
8 | 11 | import absorbe_snap as absnap #compiled fortran code for detecting molecule-to-gas collisions |
9 | 12 | |
10 | 13 | |
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 | + | |
11 | 56 | |
12 | 57 | def evolve_by_time_step(amplitude,t_step,N_part,L,pos_at_t): |
13 | 58 |
@@ -39,7 +84,9 @@ | ||
39 | 84 | |
40 | 85 | n_iter=int(round(t_fin/t_step)) |
41 | 86 | |
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 | |
43 | 90 | |
44 | 91 | #print "N_iter is, ", n_iter |
45 | 92 |
@@ -48,7 +95,7 @@ | ||
48 | 95 | |
49 | 96 | for i in xrange(n_iter): |
50 | 97 | |
51 | - if (s.remainder(i,my_mod) == 0 ): | |
98 | + if ((s.remainder(i,save_every) == 0) & (i>0) ): | |
52 | 99 | |
53 | 100 | print "i is, ", i |
54 | 101 | #print "monomer_pos are, ", monomer_pos[:,0] |
@@ -111,6 +158,149 @@ | ||
111 | 158 | |
112 | 159 | return results |
113 | 160 | |
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 | + | |
114 | 304 | |
115 | 305 | |
116 | 306 |
@@ -481,24 +671,59 @@ | ||
481 | 671 | ####################################################################### |
482 | 672 | ####################################################################### |
483 | 673 | |
484 | -L=3. | |
485 | - | |
486 | -t_fin=20. | |
674 | +# L=3. | |
487 | 675 | |
488 | -t_step=0.001 | |
676 | +# t_fin=20. | |
489 | 677 | |
490 | -amplitude=2. | |
678 | +# t_step=0.001 | |
491 | 679 | |
492 | -N_part=30000 | |
680 | +# amplitude=2. | |
681 | + | |
682 | +# N_part=30000 | |
493 | 683 | |
494 | 684 | |
495 | -number_mon=2 #indicate the number of monomers | |
685 | +# number_mon=2 #indicate the number of monomers | |
496 | 686 | |
497 | -mon_rad=s.ones(number_mon)*0.5 | |
687 | +# mon_rad=s.ones(number_mon)*0.5 | |
498 | 688 | |
499 | 689 | |
500 | 690 | |
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 | |
502 | 727 | |
503 | 728 | |
504 | 729 |
@@ -510,9 +735,9 @@ | ||
510 | 735 | time=s.linspace(0.,t_fin,(int(t_fin/t_step)+1) ) |
511 | 736 | p.save("time.dat", time) |
512 | 737 | |
738 | +#I am no longe using the "read" parameter: the code no longer reads the trajectories to start with | |
513 | 739 | |
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 | |
516 | 741 | # rather than calculate them on the fly |
517 | 742 | |
518 | 743 |
@@ -590,8 +815,12 @@ | ||
590 | 815 | |
591 | 816 | |
592 | 817 | |
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) | |
595 | 824 | |
596 | 825 | |
597 | 826 | print "OK after test2" |