Changeset 8353 for trunk/anuga_work/development/gareth/tests/runup
- Timestamp:
- Mar 7, 2012, 9:49:06 PM (13 years ago)
- Location:
- trunk/anuga_work/development/gareth/tests/runup
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_work/development/gareth/tests/runup/runup.py
r8308 r8353 4 4 #Import Modules 5 5 #-------- 6 from sys import path7 6 import anuga 8 7 9 8 import numpy 10 11 import struct12 #import scipy13 14 #from Numeric import *15 9 16 10 from math import sin, pi, exp … … 23 17 #from swb_domain import * 24 18 #path.append('/home/gareth/storage/anuga_clean/anuga_jan12/trunk/anuga_work/development/gareth/balanced_basic') 25 from balanced_basic import * 19 #from balanced_basic import * 20 from balanced_dev import * 26 21 #--------- 27 22 #Setup computational domain … … 33 28 domain.set_datadir('.') # Use current folder 34 29 domain.set_quantities_to_be_stored({'stage': 2, 'xmomentum': 2, 'ymomentum': 2, 'elevation': 1}) 35 domain.set_store_vertices_uniquely(True)30 #domain.set_store_vertices_uniquely(True) 36 31 #------------------ 37 32 # Define topography … … 66 61 # Associate boundary tags with boundary objects 67 62 #---------------------------------------------- 68 domain.set_boundary({'left': Br, 'right': B r, 'top': Br, 'bottom':Br})63 domain.set_boundary({'left': Br, 'right': Bw, 'top': Br, 'bottom':Br}) 69 64 70 65 #------------------------------ … … 80 75 print domain.timestepping_statistics() 81 76 82 # momx=domain.quantities['xmomentum'].centroid_values83 # momy=domain.quantities['ymomentum'].centroid_values84 # #mom2=domain.quantities['xmomentum'].vertex_values85 # dep1=(domain.quantities['stage'].centroid_values-domain.quantities['elevation'].centroid_values+1.0e-06)86 # #dep2=(domain.quantities['stage'].vertex_values-domain.quantities['elevation'].vertex_values+1.0e-06)87 # velx=momx/dep188 # vely=momy/dep189 # #vel2=mom2/dep290 # #print vel1.max(), vel2.max()91 # #print vel1.min(), vel2.min()92 # #xwrite.write(velx)93 # #print >> xwrite, str(velx)94 # #print >> ywrite, str(vely)95 # for i in velx:96 # data=struct.pack('f',i)97 # xwrite.write(data)98 #99 # for j in vely:100 # data2=struct.pack('f',j)101 # ywrite.write(data2)102 #103 # #print >> xwrite, \n104 # #numpy.savetxt("xvel.txt",velx)105 # #numpy.savetxt("yvel.txt",vely)106 # #velx.tofile(xwrite," ")107 # #vely.tofile(ywrite," ")108 #109 #xwrite.close()110 #ywrite.close()111 77 112 78 print 'Finished' -
trunk/anuga_work/development/gareth/tests/runup/runuplot.py
r8308 r8353 5 5 #--------------- 6 6 import anuga 7 import struct8 7 import numpy 9 8 import scipy 10 import pylab 9 from matplotlib import pyplot as pyplot 10 import util # Routines to read in and work with ANUGA output 11 11 12 from Scientific.IO.NetCDF import NetCDFFile 12 p2=util.get_output('runup_v2.sww', minimum_allowed_height=1.0e-03) 13 p=util.get_centroids(p2, velocity_extrapolation=True) 13 14 14 #-------------- 15 # Get variables 16 #-------------- 17 fid = NetCDFFile('runup_v2.sww') 18 x = fid.variables['x'] 19 x = x.getValue() 20 y = fid.variables['y'] 21 y = y.getValue() 22 elev = fid.variables['elevation'] 23 elev = elev.getValue() 24 stage = fid.variables['stage'] 25 stage = stage.getValue() 26 xmom = fid.variables['xmomentum'] 27 xmom = xmom.getValue() 28 ymom = fid.variables['ymomentum'] 29 ymom = ymom.getValue() 30 #xvel2 = fid.variables['centroid_xvelocity'] 31 #xvel2 = xvel2.getValue() 32 #yvel2 = fid.variables['centroid_yvelocity'] 33 #yvel2 = yvel2.getValue() 34 vols=fid.variables['volumes'] 35 vols=vols.getValue() 15 #p=util.get_output('runup_v2.sww', minimum_allowed_height=1.0e-03) 36 16 37 # Calculate centroids38 x_cent=vols[:,0]*0.039 y_cent=vols[:,0]*0.040 41 for i in range(0,len(x_cent)):42 x_cent[i]=(x[vols[i,0]]+x[vols[i,1]]+x[vols[i,2]])/3.043 y_cent[i]=(y[vols[i,0]]+y[vols[i,1]]+y[vols[i,2]])/3.044 45 # Read in centroid velocities46 #xvel_cent = numpy.arange(0.0,len(x_cent)*xmom.shape[0]*1.0).reshape(xmom.shape[0],len(x_cent))47 #yvel_cent = numpy.arange(0.0,len(x_cent)*xmom.shape[0]*1.0).reshape(xmom.shape[0],len(x_cent))48 #49 #xfile=open('xvel.out','rb')50 #floatsize=struct.calcsize('f')51 #for i in range(0,xmom.shape[0]):52 # for j in range(0,len(x_cent)):53 # data = xfile.read(floatsize)54 # num = struct.unpack('f', data)55 # #print num[0], i*len(x_cent)+j56 # xvel_cent[i,j] = num[0]57 #58 #xfile.close()59 #60 #yfile=open('yvel.out','rb')61 #floatsize2=struct.calcsize('f')62 #for i in range(0,xmom.shape[0]):63 # for j in range(0,len(x_cent)):64 # data2 = yfile.read(floatsize2)65 # num2 = struct.unpack('f', data2)66 # #print num[0], i*len(x_cent)+j67 # yvel_cent[i,j] = num2[0]68 #69 #yfile.close()70 71 #vel_cent=(xvel_cent**2+yvel_cent**2)**(0.5)72 ## Read in centroid velocities from file as a long string73 ##xvel2=[]74 ##for line in file('xvel.txt'):75 ## line = line.rstrip('\n')76 ## xvel2.append(line)77 ## Coerce values to array78 ##xvel_cent = numpy.arange(0.0,len(x_cent)*xmom.shape[0]*1.0).reshape(xmom.shape[0],len(x_cent))79 ##for i in range(0,xmom.shape[0]):80 ## for j in range(0,len(x_cent)):81 ## xvel_cent[i,j] = eval(xvel2[i*len(x_cent)+j])82 ## #print i, j, xvel_cent[i,j], xvel2[i*len(x_cent)+j], eval(xvel2[i*len(x_cent)+j])83 ##84 ##yvel2=[]85 ##for line in file('yvel.txt'):86 # line = line.rstrip('\n')87 # yvel2.append(line)88 #89 #yvel_cent = numpy.arange(0.0,len(x_cent)*xmom.shape[0]*1.0).reshape(xmom.shape[0],len(x_cent))90 #91 #for i in range(0,xmom.shape[0]):92 # for j in range(0,len(x_cent)):93 # yvel_cent[i,j] = eval(yvel2[i*len(x_cent)+j])94 #95 96 #for i in vols.97 98 #-------------------99 # Calculate Velocity100 #-------------------101 xvel=xmom*0102 yvel=ymom*0103 for i in range(xmom.shape[0]):104 xvel[i,:]=xmom[i,:]/(stage[i,:]-elev+1.0e-06)*(stage[i,:]-elev>1.0e-03)105 yvel[i,:]=ymom[i,:]/(stage[i,:]-elev+1.0e-06)*(stage[i,:]-elev>1.0e-03)106 107 vel=(xvel**2+yvel**2)**0.5108 17 #------------------ 109 18 # Select line 110 19 #------------------ 111 v=(y==0) 20 py_central=p.y[scipy.argmin(abs(p.y-0.5))] 21 v=(p.y==p.y[py_central]) 112 22 113 23 #-------------------- 114 24 # Make plot animation 115 25 #-------------------- 116 py lab.close() #If the plot is open, there will be problems117 py lab.ion()26 pyplot.close() #If the plot is open, there will be problems 27 pyplot.ion() 118 28 119 29 if True: 120 line, = py lab.plot( (x[v].min(),x[v].max()) ,(xvel[:,v].min(),xvel[:,v].max() ) )121 for i in range( xmom.shape[0]):122 line.set_xdata( x[v])123 line.set_ydata( xvel[i,v])124 py lab.draw()125 py lab.plot( (0,1),(0,0), 'r' )126 py lab.title(str(i)+'/200') # : velocity does not converge to zero' )127 py lab.xlabel('x')128 py lab.ylabel('Velocity (m/s)')30 line, = pyplot.plot( (p.x[v].min(),p.x[v].max()) ,(p.xvel[:,v].min(),p.xvel[:,v].max() ) ) 31 for i in range(p.xmom.shape[0]): 32 line.set_xdata(p.x[v]) 33 line.set_ydata(p.xvel[i,v]) 34 pyplot.draw() 35 pyplot.plot( (0,1),(0,0), 'r' ) 36 pyplot.title(str(i)+'/200') # : velocity does not converge to zero' ) 37 pyplot.xlabel('x') 38 pyplot.ylabel('Velocity (m/s)') 129 39 130 py lab.savefig('runup_x_velocities.png')40 pyplot.savefig('runup_x_velocities.png') 131 41 132 #py lab.clf()133 #py lab.close()42 #pyplot.clf() 43 #pyplot.close() 134 44 135 45 #------------------------------------------------ … … 139 49 #highx=yvel[3,:].argmax() 140 50 #v=(x==x[highx]) 141 #py lab.plot(yvel[3,v])142 #py lab.title('y-velocity is not always zero at the boundaries, e.g. x='+str(x[highx])+' , t=0.3s')143 #py lab.xlabel('y')144 #py lab.ylabel('Velocity (m/s)')145 #py lab.savefig('runup_y_velocities.png')51 #pyplot.plot(yvel[3,v]) 52 #pyplot.title('y-velocity is not always zero at the boundaries, e.g. x='+str(x[highx])+' , t=0.3s') 53 #pyplot.xlabel('y') 54 #pyplot.ylabel('Velocity (m/s)') 55 #pyplot.savefig('runup_y_velocities.png') 146 56 147 py lab.clf()148 py lab.plot(x[y==0.5],stage[5,y==0.5])149 py lab.plot(x[y==0.5],stage[5,y==0.5],'o')150 py lab.plot(x[y==0.5],elev[y==0.5])151 py lab.xlabel('x (m)')152 py lab.ylabel('z (m)')153 py lab.title('Free surface and bed at y==0.5, time = 1.0 second')154 py lab.savefig('elev_1s_v2.png')57 pyplot.clf() 58 pyplot.plot(p.x[v],p.stage[5,v]) 59 pyplot.plot(p.x[v],p.stage[5,v],'o') 60 pyplot.plot(p.x[v],p.elev[v]) 61 pyplot.xlabel('x (m)') 62 pyplot.ylabel('z (m)') 63 pyplot.title('Free surface and bed at y==0.5, time = 1.0 second') 64 pyplot.savefig('elev_1s_v2.png') 155 65 156 py lab.clf()157 py lab.plot(x[y==0.5],xvel[5,y==0.5])158 py lab.plot(x[y==0.5],xvel[5,y==0.5],'o')159 py lab.title('Velocity at y==0.500, time = 1.0 second')160 py lab.xlabel('x (m)')161 py lab.ylabel('Velocity (m/s)')162 py lab.savefig('vel1d_1s_v2.png')66 pyplot.clf() 67 pyplot.plot(p.x[v],p.xvel[5,v]) 68 pyplot.plot(p.x[v],p.xvel[5,v],'o') 69 pyplot.title('Velocity at y==0.500, time = 1.0 second') 70 pyplot.xlabel('x (m)') 71 pyplot.ylabel('Velocity (m/s)') 72 pyplot.savefig('vel1d_1s_v2.png') 163 73 164 #py lab.clf()165 #py lab.plot(x_cent[y_cent==y_cent[80]],xvel_cent[15,y_cent==y_cent[80]])166 #py lab.plot(x_cent[y_cent==y_cent[80]],xvel_cent[15,y_cent==y_cent[80]],'o')167 #py lab.title('Velocity at y==0.500, time = 3.0 second')168 #py lab.xlabel('x (m)')169 #py lab.ylabel('Velocity (m/s)')170 #py lab.savefig('vel1d_3s_v2.png')74 #pyplot.clf() 75 #pyplot.plot(x_cent[y_cent==y_cent[80]],xvel_cent[15,y_cent==y_cent[80]]) 76 #pyplot.plot(x_cent[y_cent==y_cent[80]],xvel_cent[15,y_cent==y_cent[80]],'o') 77 #pyplot.title('Velocity at y==0.500, time = 3.0 second') 78 #pyplot.xlabel('x (m)') 79 #pyplot.ylabel('Velocity (m/s)') 80 #pyplot.savefig('vel1d_3s_v2.png') 171 81 #------------------------------------- 172 82 # Final velocities plot 173 83 #------------------------------------- 174 #py lab.clf()175 #py lab.quiver(x,y,xvel[200,:],yvel[200,:])176 #py lab.xlabel('x')177 #py lab.ylabel('y')178 #py lab.title('The maximum speed is '+ str(vel[200,:].max()) + ' m/s')179 #py lab.savefig('final_vel_field.png')84 #pyplot.clf() 85 #pyplot.quiver(x,y,xvel[200,:],yvel[200,:]) 86 #pyplot.xlabel('x') 87 #pyplot.ylabel('y') 88 #pyplot.title('The maximum speed is '+ str(vel[200,:].max()) + ' m/s') 89 #pyplot.savefig('final_vel_field.png') 180 90 #print vel[200,:].max() 181 91 182 py lab.clf()183 py lab.scatter(x,y,c=elev,edgecolors='none', s=25)184 py lab.colorbar()185 #py lab.quiver(x_cent,y_cent,xvel_cent[15,:],yvel_cent[15,:])186 #py lab.title('The maximum speed is '+ str(vel_cent[15,:].max()) + ' m/s at time 3.0s')187 py lab.quiver(x,y,xvel[5,:],yvel[5,:])188 py lab.title('The maximum speed is '+ str(vel[5,:].max()) + ' m/s at time 1.0s')189 py lab.savefig('vel_1s_v2.png')92 pyplot.clf() 93 pyplot.scatter(p.x,p.y,c=p.elev,edgecolors='none', s=25) 94 pyplot.colorbar() 95 #pyplot.quiver(x_cent,y_cent,xvel_cent[15,:],yvel_cent[15,:]) 96 #pyplot.title('The maximum speed is '+ str(vel_cent[15,:].max()) + ' m/s at time 3.0s') 97 pyplot.quiver(p.x,p.y,p.xvel[5,:],p.yvel[5,:]) 98 pyplot.title('The maximum speed is '+ str(p.vel[5,:].max()) + ' m/s at time 1.0s') 99 pyplot.savefig('vel_1s_v2.png') 190 100 191 py lab.clf()192 py lab.scatter(x,y,c=elev,edgecolors='none', s=25)193 py lab.colorbar()194 #py lab.quiver(x_cent,y_cent,xvel_cent[150,:],yvel_cent[150,:])195 #py lab.title('The maximum speed is '+ str(vel_cent[150,:].max()) + ' m/s at time 30.0s')196 py lab.quiver(x,y,xvel[150,:],yvel[150,:])197 py lab.title('The maximum speed is '+ str(vel[150,:].max()) + ' m/s at time 30.0s')198 py lab.savefig('vel_30s_v2.png')101 pyplot.clf() 102 pyplot.scatter(p.x,p.y,c=p.elev,edgecolors='none', s=25) 103 pyplot.colorbar() 104 #pyplot.quiver(x_cent,y_cent,xvel_cent[150,:],yvel_cent[150,:]) 105 #pyplot.title('The maximum speed is '+ str(vel_cent[150,:].max()) + ' m/s at time 30.0s') 106 pyplot.quiver(p.x,p.y,p.xvel[150,:],p.yvel[150,:]) 107 pyplot.title('The maximum speed is '+ str(p.vel[150,:].max()) + ' m/s at time 30.0s') 108 pyplot.savefig('vel_30s_v2.png') 199 109 200 201 202 pylab.clf() 203 pylab.plot(x[y==0.5],stage[150,y==0.5]) 204 pylab.plot(x[y==0.5],stage[150,y==0.5],'o') 205 pylab.plot(x[y==0.5],elev[y==0.5]) 206 pylab.xlabel('x (m)') 207 pylab.ylabel('z (m)') 208 pylab.title('Free surface and bed at y==0.5, time = 30.0 second') 209 pylab.savefig('elev_30s_v2.png') 210 pylab.clf() 211 pylab.plot(x[y==0.5],xvel[150,y==0.5]) 212 pylab.plot(x[y==0.5],xvel[150,y==0.5],'o') 213 pylab.title('Velocity at y==0.500, time = 30.0 second') 214 pylab.xlabel('x (m)') 215 pylab.ylabel('Velocity (m/s)') 216 pylab.savefig('vel1d_30s_v2.png') 217 #pylab.clf() 218 #pylab.plot(x_cent[y_cent==y_cent[80]],xvel_cent[150,y_cent==y_cent[80]]) 219 #pylab.plot(x_cent[y_cent==y_cent[80]],xvel_cent[150,y_cent==y_cent[80]],'o') 220 #pylab.title('Velocity at y==0.500, time = 30.0 second') 221 #pylab.xlabel('x (m)') 222 #pylab.ylabel('Velocity (m/s)') 223 #pylab.savefig('vel1d_30s_v2.png') 110 pyplot.clf() 111 pyplot.plot(p.x[v],p.stage[150,v]) 112 pyplot.plot(p.x[v],p.stage[150,v],'o') 113 pyplot.plot(p.x[v],p.elev[v]) 114 pyplot.xlabel('x (m)') 115 pyplot.ylabel('z (m)') 116 pyplot.title('Free surface and bed at y==0.5, time = 30.0 second') 117 pyplot.savefig('elev_30s_v2.png') 118 pyplot.clf() 119 pyplot.plot(p.x[v],p.xvel[150,v]) 120 pyplot.plot(p.x[v],p.xvel[150,v],'o') 121 pyplot.title('Velocity at y==0.500, time = 30.0 second') 122 pyplot.xlabel('x (m)') 123 pyplot.ylabel('Velocity (m/s)') 124 pyplot.savefig('vel1d_30s_v2.png') 125 #pyplot.clf() 126 #pyplot.plot(x_cent[y_cent==y_cent[80]],xvel_cent[150,y_cent==y_cent[80]]) 127 #pyplot.plot(x_cent[y_cent==y_cent[80]],xvel_cent[150,y_cent==y_cent[80]],'o') 128 #pyplot.title('Velocity at y==0.500, time = 30.0 second') 129 #pyplot.xlabel('x (m)') 130 #pyplot.ylabel('Velocity (m/s)') 131 #pyplot.savefig('vel1d_30s_v2.png')
Note: See TracChangeset
for help on using the changeset viewer.