source: trunk/anuga_work/development/gareth/tests/parabolic/parabolaplot.py @ 8308

Last change on this file since 8308 was 8308, checked in by davies, 12 years ago

Added extrapolate_velocity_second_order option in config.py
and getting various tests working in gareth/tests

File size: 8.3 KB
Line 
1"""View results of runup.py
2"""
3#---------------
4# Import Modules
5#---------------
6import anuga
7import struct
8import numpy
9import scipy
10import pylab
11
12from Scientific.IO.NetCDF import NetCDFFile
13
14#--------------
15# Get variables
16#--------------
17fid = NetCDFFile('parabola_v2.sww')
18x = fid.variables['x']
19x = x.getValue()
20y = fid.variables['y']
21y = y.getValue()
22elev = fid.variables['elevation']
23elev = elev.getValue()
24stage = fid.variables['stage']
25stage = stage.getValue()
26xmom = fid.variables['xmomentum']
27xmom = xmom.getValue()
28ymom = fid.variables['ymomentum']
29ymom = ymom.getValue()
30time = fid.variables['time']
31time = time.getValue()
32
33#xvel2 = fid.variables['centroid_xvelocity']
34#xvel2 = xvel2.getValue()
35#yvel2 = fid.variables['centroid_yvelocity']
36#yvel2 = yvel2.getValue()
37vols=fid.variables['volumes']
38vols=vols.getValue()
39
40# Calculate centroids
41x_cent=vols[:,0]*0.0
42y_cent=vols[:,0]*0.0
43
44for i in range(0,len(x_cent)):
45    x_cent[i]=(x[vols[i,0]]+x[vols[i,1]]+x[vols[i,2]])/3.0
46    y_cent[i]=(y[vols[i,0]]+y[vols[i,1]]+y[vols[i,2]])/3.0
47
48# Read in centroid velocities
49xvel_cent = numpy.arange(0.0,len(x_cent)*xmom.shape[0]*1.0).reshape(xmom.shape[0],len(x_cent))
50yvel_cent = numpy.arange(0.0,len(x_cent)*xmom.shape[0]*1.0).reshape(xmom.shape[0],len(x_cent))
51
52xfile=open('xvel.out','rb')
53floatsize=struct.calcsize('f')
54for i in range(0,xmom.shape[0]):
55    for j in range(0,len(x_cent)):
56        data = xfile.read(floatsize)
57        num = struct.unpack('f', data)
58        #print num[0], i*len(x_cent)+j
59        xvel_cent[i,j] = num[0] 
60
61xfile.close()
62
63yfile=open('yvel.out','rb')
64floatsize2=struct.calcsize('f')
65for i in range(0,xmom.shape[0]):
66    for j in range(0,len(x_cent)):
67        data2 = yfile.read(floatsize2)
68        num2 = struct.unpack('f', data2)
69        #print num[0], i*len(x_cent)+j
70        yvel_cent[i,j] = num2[0] 
71
72yfile.close()
73
74vel_cent=(xvel_cent**2+yvel_cent**2)**(0.5)
75# Read in centroid velocities from file as a long string
76#xvel2=[]
77#for line in file('xvel.txt'):
78#    line = line.rstrip('\n')
79#    xvel2.append(line)
80# Coerce values to array
81#xvel_cent = numpy.arange(0.0,len(x_cent)*xmom.shape[0]*1.0).reshape(xmom.shape[0],len(x_cent))
82#for i in range(0,xmom.shape[0]):
83#    for j in range(0,len(x_cent)):
84#        xvel_cent[i,j] = eval(xvel2[i*len(x_cent)+j])
85#        #print i, j, xvel_cent[i,j], xvel2[i*len(x_cent)+j], eval(xvel2[i*len(x_cent)+j])
86#
87#yvel2=[]
88#for line in file('yvel.txt'):
89#    line = line.rstrip('\n')
90#    yvel2.append(line)
91#
92#yvel_cent = numpy.arange(0.0,len(x_cent)*xmom.shape[0]*1.0).reshape(xmom.shape[0],len(x_cent))
93#
94#for i in range(0,xmom.shape[0]):
95#    for j in range(0,len(x_cent)):
96#        yvel_cent[i,j] = eval(yvel2[i*len(x_cent)+j])
97#
98
99#for i in vols.
100
101#-------------------
102# Calculate Velocity
103#-------------------
104xvel=xmom*0
105yvel=ymom*0
106for i in range(xmom.shape[0]):
107    xvel[i,:]=xmom[i,:]/(stage[i,:]-elev+1.0e-06)*(stage[i,:]-elev>1.0e-03)
108    yvel[i,:]=ymom[i,:]/(stage[i,:]-elev+1.0e-06)*(stage[i,:]-elev>1.0e-03)
109
110vel=(xvel**2+yvel**2)**0.5
111
112
113#for i in range(xmim.shape[0]):
114#    xvel[i,:]=xvel[i,:]*(stage[i,:]>elev+0.01)
115
116#------------------
117# Select line
118#------------------
119v=(y==0.0)
120v2=(y_cent==y_cent[40])
121
122#--------------------
123# Make plot animation
124#--------------------
125pylab.close() #If the plot is open, there will be problems
126pylab.ion()
127
128if True:
129    line, = pylab.plot( (x[v].min(),x[v].max()) ,(stage[:,v].min(),stage[:,v].max() ) )
130    for i in range(700,xmom.shape[0]):
131        line.set_xdata(x[v])
132        line.set_ydata(stage[i,v])
133        pylab.draw()
134        #pylab.plot( (0,1),(0,0), 'r' )
135        pylab.plot(x[v],elev[v]) 
136        pylab.title(str(i)+'/200') # : velocity does not converge to zero' )
137        pylab.xlabel('x')
138        pylab.ylabel('stage (m/s)')
139
140if True:
141    pylab.clf()
142 
143    line, = pylab.plot( (x[v].min(),x[v].max()) ,(xvel[:,v].min(),xvel[:,v].max() ), 'ro' )
144    for i in range(700,xmom.shape[0]):
145        line.set_xdata(x[v])
146        line.set_ydata(xvel[i,v])
147        pylab.draw()
148        pylab.plot( (x[v].min(),x[v].max()),(0,0), 'ro' )
149        #pylab.plot(x[v],elev[v])
150        pylab.title(str(i)+'/200') # : velocity does not converge to zero' )
151        pylab.xlabel('x')
152        pylab.ylabel('xvel (m/s)')
153
154    #line, = pylab.plot( (x_cent[v2].min(),x_cent[v2].max()) ,(xvel_cent[:,v2].min(),xvel_cent[:,v2].max() ) )
155    #for i in range(xmom.shape[0]):
156    #    line.set_xdata(x_cent[v2])
157    #    line.set_ydata(xvel_cent[i,v2])
158    #    pylab.draw()
159    #    pylab.plot( (x_cent[v2].min(),x_cent[v2].max()),(0,0), 'r' )
160    #    #pylab.plot(x[v],elev[v])
161    #    pylab.title(str(i)+'/200') # : velocity does not converge to zero' )
162    #    pylab.xlabel('x')
163    #    pylab.ylabel('xvel (m/s)')
164
165
166D0=4.0
167L=10.0
168A=2.0
169g=9.8
170#t=time[30]
171
172omega=numpy.sqrt(2*D0*g)/L
173T= 2*numpy.pi/omega
174ppp= (abs(x-4.*L/2.)).argmin()
175ppp2= (abs(x-4.*L/4.)).argmin()
176
177w = D0 + 2*A*D0/(L**2)*numpy.cos(omega*time)*( (x[ppp]-4.*L/2.) -A/2.*numpy.cos(omega*time))
178w2 = D0 + 2*A*D0/(L**2)*numpy.cos(omega*time)*( (x[ppp2]-4.*L/2.) -A/2.*numpy.cos(omega*time))
179w2 = w2*(w2>elev[ppp2])+elev[ppp2]*(w2<=elev[ppp2])
180
181pylab.clf()
182pylab.plot(time,w)
183pylab.plot(time,stage[:,ppp])
184pylab.savefig('Stage_centre_v2.png')
185#       pylab.savefig('runup_x_velocities.png')
186pylab.clf()
187pylab.plot(time,w2)
188pylab.plot(time,stage[:,ppp2])
189pylab.savefig('Stage_centre_v3.png')
190
191
192pltind=numpy.argmin(abs(time-T*3))
193
194pylab.clf()
195pylab.plot(x[v],xvel[pltind,v])
196pylab.title('Velocity near to time=3T')
197pylab.savefig('Vel_3T_v2.png')
198
199pltind=numpy.argmin(abs(time-T*3.25))
200
201pylab.clf()
202pylab.plot(x[v],xvel[pltind,v])
203pylab.title('Velocity near to time=3.25T')
204pylab.savefig('Vel_3_5T_v2.png')
205#pylab.clf()
206#pylab.close()
207
208#------------------------------------------------
209# Maximum y velocities -- occurs in output step 3
210#------------------------------------------------
211#print yvel[3,:].max(), yvel[3,:].min()
212#highx=yvel[3,:].argmax()
213#v=(x==x[highx])
214#pylab.plot(yvel[3,v])
215#pylab.title('y-velocity is not always zero at the boundaries, e.g. x='+str(x[highx])+' , t=0.3s')
216#pylab.xlabel('y')
217#pylab.ylabel('Velocity (m/s)')
218#pylab.savefig('runup_y_velocities.png')
219
220#pylab.clf()
221#pylab.plot(x[y==0.5],stage[15,y==0.5])
222#pylab.plot(x[y==0.5],stage[15,y==0.5],'o')
223#pylab.plot(x[y==0.5],elev[y==0.5])
224#pylab.xlabel('x (m)')
225#pylab.ylabel('z (m)')
226#pylab.title('Free surface and bed at y==0.5, time = 3.0 second')
227#pylab.savefig('elev_3s_vdense.png')
228#pylab.clf()
229#pylab.plot(x_cent[y_cent==0.500],xvel_cent[15,y_cent==0.500])
230#pylab.plot(x_cent[y_cent==0.500],xvel_cent[15,y_cent==0.500],'o')
231#pylab.title('Velocity at y==0.500, time = 3.0 second')
232#pylab.xlabel('x (m)')
233#pylab.ylabel('Velocity (m/s)')
234#pylab.savefig('vel1d_3s_vdense.png')
235#-------------------------------------
236# Final velocities plot
237#-------------------------------------
238#pylab.clf()
239#pylab.quiver(x,y,xvel[200,:],yvel[200,:])
240#pylab.xlabel('x')
241#pylab.ylabel('y')
242#pylab.title('The maximum speed is '+ str(vel[200,:].max()) + ' m/s')
243#pylab.savefig('final_vel_field.png')
244#print vel[200,:].max()
245
246#pylab.clf()
247#pylab.scatter(x,y,c=elev,edgecolors='none', s=25)
248#pylab.colorbar()
249#pylab.quiver(x_cent,y_cent,xvel_cent[15,:],yvel_cent[15,:])
250#pylab.title('The maximum speed is '+ str(vel_cent[15,:].max()) + ' m/s at time 3.0s')
251#pylab.quiver(x,y,xvel[15,:],yvel[15,:])
252#pylab.title('The maximum speed is '+ str(vel[15,:].max()) + ' m/s at time 3.0s')
253#pylab.savefig('vel_3s_vdense.png')
254
255#pylab.clf()
256#pylab.scatter(x,y,c=elev,edgecolors='none', s=25)
257#pylab.colorbar()
258#pylab.quiver(x_cent,y_cent,xvel_cent[150,:],yvel_cent[150,:])
259#pylab.title('The maximum speed is '+ str(vel_cent[150,:].max()) + ' m/s at time 30.0s')
260#pylab.quiver(x,y,xvel[150,:],yvel[150,:])
261#pylab.title('The maximum speed is '+ str(vel[150,:].max()) + ' m/s at time 30.0s')
262#pylab.savefig('vel_30s_vdense.png')
263
264
265
266#pylab.clf()
267#pylab.plot(x[y==0.5],stage[150,y==0.5])
268#pylab.plot(x[y==0.5],stage[150,y==0.5],'o')
269#pylab.plot(x[y==0.5],elev[y==0.5])
270#pylab.xlabel('x (m)')
271#pylab.ylabel('z (m)')
272#pylab.title('Free surface and bed at y==0.5, time = 30.0 second')
273#pylab.savefig('elev_30s_vdense.png')
274#pylab.clf()
275#pylab.plot(x_cent[y_cent==0.500],xvel_cent[150,y_cent==0.500])
276#pylab.plot(x_cent[y_cent==0.500],xvel_cent[150,y_cent==0.500],'o')
277#pylab.title('Velocity at y==0.500, time = 30.0 second')
278#pylab.xlabel('x (m)')
279#pylab.ylabel('Velocity (m/s)')
280##pylab.savefig('vel1d_30s_vdense.png')
Note: See TracBrowser for help on using the repository browser.