Revision | 1769ee7ee4c3892a55582399c129c4f9aa815e2f (tree) |
---|---|
Zeit | 2007-05-22 01:22:46 |
Autor | iselllo |
Commiter | iselllo |
I modified the code Python-codes/postprocess2.py. It now goes reading
the output files to postprocess in an upper directory.
Furthermore, I cleaned up its structures so that it does not do the same
job twice when calculating the mean and saving up the results. I
fundamentally added some if-conditions and slightly changed the way in
which the results are saved into text files. I checked against the
previous versions of the code that it returns the same results as in the
past.
@@ -13,12 +13,13 @@ | ||
13 | 13 | |
14 | 14 | def readq(n1,n2,n3,n_snap_ini,n_snap_fin,name,z_pos,theta_pos,readmean): |
15 | 15 | #q3arr=zeros((n1,n2,n3)) |
16 | - q3arr=zeros(n1*n2*n3) | |
17 | - qmean=zeros(n1*n2*n3) | |
18 | - v_rms=zeros(n1*n2*n3) | |
19 | - if (readmean==1): | |
20 | - name_bis='means_v_z_3D%03d'%n_snap_fin | |
21 | - qmean=pylab.load(name_bis) | |
16 | + if (readmean !=1): # I calculate the mean velocity | |
17 | + q3arr=zeros(n1*n2*n3) | |
18 | + elif (readmean ==1): # I read the mean the velocity & calculate the rms | |
19 | + qmean=zeros(n1*n2*n3) | |
20 | + v_rms=zeros(n1*n2*n3) | |
21 | + name_bis='means_v_z_3D%03d'%n_snap_fin | |
22 | + qmean=pylab.load(name_bis) | |
22 | 23 | #fluctuations=zeros((n2,(n_snap_fin-n_snap_ini+1))) |
23 | 24 | #flu_av=zeros(n2) |
24 | 25 | jcount=0 |
@@ -26,54 +27,60 @@ | ||
26 | 27 | print 'l is', l |
27 | 28 | fname = name%l # %03d pads the integers with zeros |
28 | 29 | temp_arr=pylab.load(fname) # loading |
29 | - q3arr[:]=temp_arr[:]+q3arr[:] | |
30 | - if (readmean==1): | |
30 | + if (readmean != 1): # I define the array I need for the mean velocity | |
31 | + q3arr[:]=temp_arr[:]+q3arr[:] | |
32 | + elif (readmean==1): # I define the array for the rms & I simply read the\ | |
33 | + #mean velocity I had already calculated | |
31 | 34 | v_rms[:]=(temp_arr[:]-qmean[:])*(temp_arr[:]-qmean[:])+v_rms[:] |
32 | - | |
33 | 35 | jcount=jcount+1 |
34 | 36 | #print 'the dimension of q3arr is', shape(q3arr) |
35 | 37 | #now I divide by the number of snapshots in order to have a mean field |
36 | - q3arr=q3arr/float(n_snap_fin-n_snap_ini+1.) #I first take a temporal mean | |
37 | - name_bis='means_v_z_3D%03d'%n_snap_fin | |
38 | - pylab.save(name_bis,q3arr) | |
39 | - v_rms=v_rms/float(n_snap_fin-n_snap_ini+1.) # temporal mean of v_rms | |
40 | - q3arr=reshape(q3arr,[n1,n2,n3]) | |
41 | - v_rms=reshape(v_rms,[n1,n2,n3]) | |
42 | - my_mean=zeros(n2) | |
43 | - my_v_rms=zeros(n2) | |
44 | - | |
45 | - | |
46 | -#The following lines are a much faster and cleaner way to deal with the means along theta | |
47 | -# and r | |
48 | - my_mean=q3arr.mean(axis=0).mean(axis=1) | |
49 | - my_v_rms=v_rms.mean(axis=0).mean(axis=1) | |
50 | - my_v_rms=sqrt(my_v_rms) | |
51 | - #now I work out the average v_z(r) for a specific z (average on a tube cross | |
52 | - #section) | |
53 | - mean_cross=zeros(n2) | |
54 | - #for i in range(0,n1): | |
55 | - #mean_cross[:]= q3arr[i,:,z_pos]+mean_cross[:] | |
56 | - #mean_cross=mean_cross/n1 | |
57 | - mean_cross=q3arr[:,:,z_pos].mean(axis=0) | |
58 | - #finally I work out the temporal mean for a specific theta and x | |
59 | - mean_theta=q3arr[theta_pos,:,z_pos] | |
60 | - | |
61 | - #now I glue together the results | |
62 | - my_means=zeros((n2,4)) | |
63 | - my_means[:,0]=my_mean | |
64 | - my_means[:,1]=mean_cross | |
65 | - my_means[:,2]=mean_theta | |
66 | - my_means[:,3]=my_v_rms | |
67 | - name_bis='means_v_z%03d'%n_snap_fin | |
68 | - pylab.save(name_bis,my_means) | |
69 | - | |
38 | + if (readmean != 1): | |
39 | + #I simply take the temporal mean and save the array along | |
40 | + # the whole tube. It will be used afterwards to | |
41 | + #evaluate the rms | |
42 | + q3arr=q3arr/float(n_snap_fin-n_snap_ini+1.) #I first take a temporal mean | |
43 | + name_bis='means_v_z_3D%03d'%n_snap_fin | |
44 | + pylab.save(name_bis,q3arr) | |
45 | + # Now I conveniently change the shape of the array | |
46 | + q3arr=reshape(q3arr,[n1,n2,n3]) | |
47 | + #my_mean=zeros(n2) | |
48 | + #Now I take the mean along theta and z to get v_z(r) | |
49 | + my_mean=q3arr.mean(axis=0).mean(axis=1) | |
50 | + #now I work out the average v_z(r) for a specific | |
51 | + #z (average on a tube cross section) | |
52 | + #mean_cross=zeros(n2) | |
53 | + #similar procedure as before, but along only an axis only | |
54 | + mean_cross=q3arr[:,:,z_pos].mean(axis=0) | |
55 | + #finally I work out the temporal mean for a specific theta and x | |
56 | + mean_theta=q3arr[theta_pos,:,z_pos] | |
57 | + #now I glue together the results | |
58 | + my_means=zeros((n2,3)) | |
59 | + my_means[:,0]=my_mean | |
60 | + my_means[:,1]=mean_cross | |
61 | + my_means[:,2]=mean_theta | |
62 | + #my_means[:,3]=my_v_rms | |
63 | + name_bis='means_v_z%03d'%n_snap_fin | |
64 | + pylab.save(name_bis,my_means) | |
65 | + elif (readmean ==1): | |
66 | + v_rms=v_rms/float(n_snap_fin-n_snap_ini+1.) # temporal mean of v_rms | |
67 | + v_rms=reshape(v_rms,[n1,n2,n3]) | |
68 | + #my_v_rms=zeros(n2) | |
69 | + #The following lines are a much faster and cleaner way to deal | |
70 | + # with the means along theta and r | |
71 | + my_v_rms=v_rms.mean(axis=0).mean(axis=1) | |
72 | + my_v_rms=sqrt(my_v_rms) | |
73 | + name_bis='v_z_rms%03d'%n_snap_fin | |
74 | + #my_means=zeros(n2) | |
75 | + pylab.save(name_bis,my_v_rms) | |
76 | + my_means=my_v_rms | |
70 | 77 | return my_means |
71 | 78 | |
72 | 79 | |
73 | 80 | |
74 | -n1=65 # theta grid | |
75 | -n2=65 # r grid | |
76 | -n3=65 # z grid | |
81 | +n1=129 # theta grid | |
82 | +n2=88 # r grid | |
83 | +n3=129 # z grid | |
77 | 84 | |
78 | 85 | z_pos=25 # I fix a certain position along z |
79 | 86 | # I am not really using this now, but it could come handy later on. |
@@ -83,7 +90,8 @@ | ||
83 | 90 | n_snap_fin = int(raw_input("Enter the value of the final snapshot to read ")) |
84 | 91 | #n_snap_ini=15 |
85 | 92 | #n_snap_fin=20 # number of snapshots |
86 | -name='vz%05d' | |
93 | +name='../vz%05d' | |
94 | +#print 'name is ', name | |
87 | 95 | readmean = int(raw_input("Do you want to read (1) qmean for the v_rms? ")) |
88 | 96 | |
89 | 97 |
@@ -97,7 +105,7 @@ | ||
97 | 105 | elif (icalc == 0): |
98 | 106 | print 'here I am' |
99 | 107 | #l=n_snap_fin |
100 | - fname='means_v_z%03d'%n_snap_fin | |
108 | + fname='../means_v_z%03d'%n_snap_fin | |
101 | 109 | print 'fname is', fname |
102 | 110 | my_arr=pylab.load(fname) |
103 | 111 |
@@ -109,7 +117,7 @@ | ||
109 | 117 | |
110 | 118 | |
111 | 119 | |
112 | -data=pylab.load("rg2.out") | |
120 | +data=pylab.load("../rg2.out") | |
113 | 121 | #data=pylab.load("radstr.out") |
114 | 122 | |
115 | 123 | print 'data[:,0] is', data[:,0] |
@@ -126,19 +134,21 @@ | ||
126 | 134 | vel_prof=(1-my_arr)**(1./6.) |
127 | 135 | return vel_prof |
128 | 136 | |
129 | - | |
130 | -name_bis='Average_v_z(r)_on_snapshot%03d'%n_snap_fin | |
137 | +if (readmean != 1): # in this case I plot some statistics about the average velocity I | |
138 | + # have just worked out | |
131 | 139 | |
132 | -vel_emp=one_sixth(data[:,0]) | |
133 | -pylab.plot(data[:,0],my_arr[:,0],data[:,0],my_arr[:,1],data[:,0],my_arr[:,2]\ | |
134 | -,data[:,0],vel_emp*max(my_arr[:,0])) | |
135 | -pylab.legend(('average on the whole tube','average on cross section','specific position'\ | |
136 | -,'empirical correlation')) | |
137 | -pylab.xlabel('Radial Coordinate') | |
138 | -pylab.ylabel('Physical Coordinate') | |
139 | -pylab.title('Radial Grid') | |
140 | -pylab.grid(True) | |
141 | -pylab.savefig(name_bis) | |
140 | + name_bis='Average_v_z(r)_on_snapshot%03d'%n_snap_fin | |
141 | + | |
142 | + vel_emp=one_sixth(data[:,0]) | |
143 | + pylab.plot(data[:,0],my_arr[:,0],data[:,0],my_arr[:,1],data[:,0],my_arr[:,2]\ | |
144 | + ,data[:,0],vel_emp*max(my_arr[:,0])) | |
145 | + pylab.legend(('average on the whole tube','average on cross section',\ | |
146 | + 'specific position','empirical correlation')) | |
147 | + pylab.xlabel('Radial Coordinate') | |
148 | + pylab.ylabel('Physical Coordinate') | |
149 | + pylab.title('Radial Grid') | |
150 | + pylab.grid(True) | |
151 | + pylab.savefig(name_bis) | |
142 | 152 | |
143 | 153 | # now I compare everything with the result I got with Comsol |
144 | 154 |
@@ -147,36 +157,38 @@ | ||
147 | 157 | #comsol[:,0]=comsol[:,0]/max(comsol[:,0]) |
148 | 158 | #comsol[:,1]=comsol[:,1]/max(comsol[:,1])*max(my_arr[:,0]) |
149 | 159 | |
150 | -name_bis='Average_v_z(r)_on_snapshot%03d_bis'%n_snap_fin | |
160 | + name_bis='Average_v_z(r)_on_snapshot%03d_bis'%n_snap_fin | |
151 | 161 | |
152 | -pylab.plot(data[:,0],my_arr[:,0],\ | |
153 | -data[:,0],vel_emp*max(my_arr[:,0])) | |
154 | -pylab.legend(('average on the whole tube',\ | |
155 | -'empirical correlation')) | |
156 | -pylab.xlabel('Radial Coordinate') | |
157 | -pylab.ylabel('Physical Coordinate') | |
158 | -pylab.title('Radial Grid') | |
159 | -pylab.grid(True) | |
160 | -pylab.savefig(name_bis) | |
161 | - | |
162 | + pylab.plot(data[:,0],my_arr[:,0],\ | |
163 | + data[:,0],vel_emp*max(my_arr[:,0])) | |
164 | + pylab.legend(('average on the whole tube',\ | |
165 | + 'empirical correlation')) | |
166 | + pylab.xlabel('Radial Coordinate') | |
167 | + pylab.ylabel('Physical Coordinate') | |
168 | + pylab.title('Radial Grid') | |
169 | + pylab.grid(True) | |
170 | + pylab.savefig(name_bis) | |
162 | 171 | |
163 | 172 | |
164 | -name_bis='v_z(r)_rms%03d'%n_snap_fin | |
173 | +if (readmean ==1): # in this case I am ready with the rms plots | |
174 | + | |
165 | 175 | |
166 | -pylab.plot(data[:,0],my_arr[:,3]) | |
167 | -#pylab.legend(('average on the whole tube')) | |
168 | -pylab.xlabel('Radial Coordinate') | |
169 | -pylab.ylabel('Physical Coordinate') | |
170 | -pylab.title('Radial Grid') | |
171 | -pylab.grid(True) | |
172 | -pylab.savefig(name_bis) | |
176 | + name_bis='v_z(r)_rms%03d'%n_snap_fin | |
173 | 177 | |
174 | -name_bis='U_z_rms%03d'%n_snap_fin | |
178 | + pylab.plot(data[:,0],my_arr) | |
179 | + #pylab.legend(('average on the whole tube')) | |
180 | + pylab.xlabel('Radial Coordinate') | |
181 | + pylab.ylabel('Physical Coordinate') | |
182 | + pylab.title('Radial Grid') | |
183 | + pylab.grid(True) | |
184 | + pylab.savefig(name_bis) | |
175 | 185 | |
176 | -results=zeros((n2,2)) | |
177 | -results[:,0]=data[:,0] | |
178 | -results[:,1]=my_arr[:,3] | |
179 | -pylab.save(name_bis,results) | |
186 | + name_bis='U_z_rms%03d'%n_snap_fin | |
187 | + | |
188 | + results=zeros((n2,2)) | |
189 | + results[:,0]=data[:,0] | |
190 | + results[:,1]=my_arr | |
191 | + pylab.save(name_bis,results) | |
180 | 192 | |
181 | 193 | #name_bis='Radial_velocity_fluctuations%03d'%n_snap_fin |
182 | 194 |
@@ -191,24 +203,23 @@ | ||
191 | 203 | |
192 | 204 | |
193 | 205 | #Now it is time to calculate the physical axial velocity in the tube |
194 | - | |
195 | -U_phys=my_arr[:,0]*U_b*2. | |
206 | +if (readmean != 1): | |
207 | + U_phys=my_arr[:,0]*U_b*2. | |
196 | 208 | |
197 | 209 | |
198 | -#print 'U_phys is',U_phys | |
199 | - | |
200 | -#r_coord=r_ini | |
201 | -r_phys=r_ini*D/2. | |
210 | + #print 'U_phys is',U_phys | |
202 | 211 | |
203 | -name_bis='physical_axial_velocity%03d'%n_snap_fin | |
204 | -pylab.plot(r_phys,U_phys) | |
205 | -#pylab.legend(('average on the whole tube','comsol',\ | |
206 | -#'empirical correlation')) | |
207 | -pylab.xlabel('Radial Coordinate') | |
208 | -pylab.ylabel('Physical Coordinate') | |
209 | -pylab.title('Axial Velocity vs r') | |
210 | -pylab.grid(True) | |
211 | -pylab.savefig(name_bis) | |
212 | + #r_coord=r_ini | |
213 | + r_phys=r_ini*D/2. | |
214 | + name_bis='physical_axial_velocity%03d'%n_snap_fin | |
215 | + pylab.plot(r_phys,U_phys) | |
216 | + #pylab.legend(('average on the whole tube','comsol',\ | |
217 | + #'empirical correlation')) | |
218 | + pylab.xlabel('Radial Coordinate') | |
219 | + pylab.ylabel('Physical Coordinate') | |
220 | + pylab.title('Axial Velocity vs r') | |
221 | + pylab.grid(True) | |
222 | + pylab.savefig(name_bis) | |
212 | 223 | |
213 | 224 | |
214 | 225 | # Now I work out different units |
@@ -234,50 +245,54 @@ | ||
234 | 245 | print 'delta_nu is', delta_nu |
235 | 246 | |
236 | 247 | #Now the same plot as before in wall units (for r and v_z) |
237 | -r_plus=r_phys/delta_nu | |
238 | -U_plus=U_phys/u_tau | |
239 | - | |
240 | -name_bis='axial_velocity_wall_units%03d'%n_snap_fin | |
241 | -pylab.plot(r_plus,U_plus) | |
242 | -#pylab.legend(('average on the whole tube','comsol',\ | |
243 | -#'empirical correlation')) | |
244 | -pylab.xlabel('r+') | |
245 | -pylab.ylabel('u+') | |
246 | -pylab.title('Axial Velocity y+ vs r+') | |
247 | -pylab.grid(True) | |
248 | -pylab.savefig(name_bis) | |
249 | - | |
250 | -r_red=r_plus[2:(len(r_ini)-1)] | |
248 | +if (readmean != 1): | |
249 | + | |
250 | + r_plus=r_phys/delta_nu | |
251 | + U_plus=U_phys/u_tau | |
251 | 252 | |
252 | -name_bis='axial_velocity_wall_units_distance_from_wall%03d'%n_snap_fin | |
253 | -pylab.plot(max(r_plus)-r_plus,U_plus/max(U_plus),max(r_plus)-r_plus,max(r_plus)-r_plus,\ | |
254 | -max(r_plus)-r_red,\ | |
255 | -(5.2+(1./0.41)*log(max(r_plus)-r_red))/max((5.2+(1./0.41)*log(max(r_plus)-r_red)))) | |
256 | -pylab.axis([0.,max(r_plus),0.,1.]) | |
257 | -pylab.legend(('numerics','linear behavior','log-law')) | |
258 | -pylab.xlabel('r+') | |
259 | -pylab.ylabel('u+') | |
260 | -pylab.title('Axial Velocity y+ vs r+') | |
261 | -pylab.grid(True) | |
262 | -pylab.savefig(name_bis) | |
253 | + name_bis='axial_velocity_wall_units%03d'%n_snap_fin | |
254 | + pylab.plot(r_plus,U_plus) | |
255 | + #pylab.legend(('average on the whole tube','comsol',\ | |
256 | + #'empirical correlation')) | |
257 | + pylab.xlabel('r+') | |
258 | + pylab.ylabel('u+') | |
259 | + pylab.title('Axial Velocity y+ vs r+') | |
260 | + pylab.grid(True) | |
261 | + pylab.savefig(name_bis) | |
263 | 262 | |
264 | -name_bis='axial_velocity_wall_units_distance_from_wall_unscaled%03d'%n_snap_fin | |
265 | -pylab.plot(max(r_plus)-r_plus,U_plus,max(r_plus)-r_plus,max(r_plus)-r_plus,\ | |
266 | -max(r_plus)-r_red,\ | |
267 | -(5.2+(1./0.41)*log(max(r_plus)-r_red))) | |
268 | -pylab.axis([0.,max(r_plus),0.,max(max(U_plus),\ | |
269 | -max((5.2+(1./0.41)*log(max(r_plus)-r_red))))]) | |
270 | -pylab.legend(('numerics','linear behavior','log-law')) | |
271 | -pylab.xlabel('r+') | |
272 | -pylab.ylabel('u+') | |
273 | -pylab.title('Axial Velocity y+ vs r+') | |
274 | -pylab.grid(True) | |
275 | -pylab.savefig(name_bis) | |
263 | + r_red=r_plus[2:(len(r_ini)-1)] | |
276 | 264 | |
277 | -name_bis='r_and_Uz%03d'%n_snap_fin | |
278 | -#results=zeros((len(U_plus),2)) | |
279 | -results[:,0]=data[:,0] | |
280 | -results[:,1]=my_arr[:,0] | |
281 | -pylab.save(name_bis,results) | |
265 | + name_bis='axial_velocity_wall_units_distance_from_wall%03d'%n_snap_fin | |
266 | + pylab.plot(max(r_plus)-r_plus,U_plus/max(U_plus),\ | |
267 | + max(r_plus)-r_plus,max(r_plus)-r_plus,\ | |
268 | + max(r_plus)-r_red,\ | |
269 | + (5.2+(1./0.41)*log(max(r_plus)-r_red))/max((5.2+(1./0.41)*\ | |
270 | + log(max(r_plus)-r_red)))) | |
271 | + pylab.axis([0.,max(r_plus),0.,1.]) | |
272 | + pylab.legend(('numerics','linear behavior','log-law')) | |
273 | + pylab.xlabel('r+') | |
274 | + pylab.ylabel('u+') | |
275 | + pylab.title('Axial Velocity y+ vs r+') | |
276 | + pylab.grid(True) | |
277 | + pylab.savefig(name_bis) | |
278 | + | |
279 | + name_bis='axial_velocity_wall_units_distance_from_wall_unscaled%03d'%n_snap_fin | |
280 | + pylab.plot(max(r_plus)-r_plus,U_plus,max(r_plus)-r_plus,max(r_plus)-r_plus,\ | |
281 | + max(r_plus)-r_red,\ | |
282 | + (5.2+(1./0.41)*log(max(r_plus)-r_red))) | |
283 | + pylab.axis([0.,max(r_plus),0.,max(max(U_plus),\ | |
284 | + max((5.2+(1./0.41)*log(max(r_plus)-r_red))))]) | |
285 | + pylab.legend(('numerics','linear behavior','log-law')) | |
286 | + pylab.xlabel('r+') | |
287 | + pylab.ylabel('u+') | |
288 | + pylab.title('Axial Velocity y+ vs r+') | |
289 | + pylab.grid(True) | |
290 | + pylab.savefig(name_bis) | |
291 | + | |
292 | + name_bis='r_and_Uz%03d'%n_snap_fin | |
293 | + results=zeros((len(U_plus),2)) | |
294 | + results[:,0]=data[:,0] | |
295 | + results[:,1]=my_arr[:,0] | |
296 | + pylab.save(name_bis,results) | |
282 | 297 | |
283 | 298 | print 'So far so good' |
\ No newline at end of file |