Changeset 8353 for trunk/anuga_work/development/gareth/tests
- Timestamp:
- Mar 7, 2012, 9:49:06 PM (13 years ago)
- Location:
- trunk/anuga_work/development/gareth/tests
- Files:
-
- 5 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_work/development/gareth/tests/channel_floodplain/channel_floodplain1.py
r8309 r8353 10 10 import numpy 11 11 from anuga.structures.inlet_operator import Inlet_operator 12 12 from anuga import * 13 #from swb_domain import domain 13 14 #from anuga import * 14 15 #from balanced_basic import * … … 23 24 floodplain_width = 14.0 # Model domain width 24 25 floodplain_slope = 1./300. 25 chan_initial_depth = 0. 8# Initial depth of water in the channel26 chan_initial_depth = 0.65 # Initial depth of water in the channel 26 27 chan_bankfull_depth = 1.0 # Bankfull depth of the channel 27 28 chan_width = 10.0 # Bankfull width of the channel 28 29 bankwidth = 2. # Width of the bank regions -- note that these protrude into the channel 29 30 man_n=0.03 # Manning's n 30 l0 = 2.009# Length scale associated with triangle side length in channel (min_triangle area = 0.5*l0^2)31 l0 = 1.000 # Length scale associated with triangle side length in channel (min_triangle area = 0.5*l0^2) 31 32 32 33 assert chan_width < floodplain_width, \ … … 81 82 82 83 83 domain.set_name('channel_floodplain1_test') # Output name 84 domain.extrapolate_velocity_second_order=True 84 domain.set_name('channel_floodplain1_bal_dev_lowvisc') # Output name 85 #domain.set_store_vertices_uniquely(True) 86 #domain.use_edge_limiter=False 87 #domain.extrapolate_velocity_second_order=False 85 88 #------------------------------------------------------------------------------ 86 89 # … … 139 142 140 143 # Define inlet operator 144 flow_in_yval=100.0 141 145 if True: 142 line1 = [ [floodplain_width/2. - chan_width/2., 0.],\143 [floodplain_width/2. + chan_width/2., 0.] \146 line1 = [ [floodplain_width/2. - chan_width/2., flow_in_yval],\ 147 [floodplain_width/2. + chan_width/2., flow_in_yval] \ 144 148 ] 145 149 Qin = 0.5*(floodplain_slope*(chan_width*chan_initial_depth)**2.*man_n**(-2.)\ … … 191 195 Br = anuga.Reflective_boundary(domain) # Solid reflective wall 192 196 Bt = anuga.Transmissive_boundary(domain) # Transmissive boundary 193 #Bout_sub = anuga.Dirichlet_boundary( \ 194 # [-floodplain_length*floodplain_slope - chan_bankfull_depth + \ 195 # chan_initial_depth, 0., 0.]) #An outflow boundary for subcritical steady flow 197 198 199 Bout_sub = anuga.Dirichlet_boundary( \ 200 [-floodplain_length*floodplain_slope - chan_bankfull_depth + \ 201 chan_initial_depth, 0., 0.]) #An outflow boundary for subcritical steady flow 196 202 197 203 def outflow_stage_boundary(t): … … 226 232 #------------------------------------------------------------------------------ 227 233 228 for t in domain.evolve(yieldstep= 1.0, finaltime=800.0):234 for t in domain.evolve(yieldstep=2.0, finaltime=3200.0): 229 235 print domain.timestepping_statistics() 236 xx=domain.quantities['ymomentum'].centroid_values 237 dd=(domain.quantities['stage'].centroid_values - domain.quantities['elevation'].centroid_values) 238 dd=dd*(dd>0.) 239 240 tmp = xx/(dd+1.0e-06)*(dd>0.0) 241 print tmp.max(), tmp.argmax(), tmp.min(), tmp.argmin() 242 243 # Compute flow through cross-section -- check that the inflow boundary condition is doing its job 244 # This also provides another useful steady-state check 245 if( numpy.floor(t/100.) == t/100. ): 246 print '#### COMPUTING FLOW THROUGH CROSS-SECTIONS########' 247 s1 = domain.get_flow_through_cross_section([[0., floodplain_length-300.0], [floodplain_width, floodplain_length-300.0]]) 248 s2 = domain.get_flow_through_cross_section([[0., floodplain_length-1.0], [floodplain_width, floodplain_length-1.0]]) 249 250 print 'Cross sectional flows: ', s1, s2 251 print '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$' 252 253 #vv = domain.get_flow_through_cross_section 230 254 #print domain.quantities['ymomentum'].get_integral() 231 255 #print 'Qin = ', Qin -
trunk/anuga_work/development/gareth/tests/channel_floodplain/plotme.py
r8308 r8353 1 1 import util 2 import pylab 2 from matplotlib import pyplot as pyplot 3 #import pylab 3 4 4 5 # Time-index to plot outputs from 5 6 index=800 6 7 7 p = util.get_output('channel_floodplain1_test.sww') 8 v = (p.x>5.0)*(p.x<7.0) 8 #p2 = util.get_output('channel_floodplain1_bal_dev.sww', minimum_allowed_height=0.01) 9 #p=p2 10 #p=util.get_centroids(p2, velocity_extrapolation=True) 11 12 p2 = util.get_output('channel_floodplain1_bal_dev.sww', 0.01) 13 p=util.get_centroids(p2, velocity_extrapolation=True) 14 15 16 #p2 = util.get_output('channel_floodplain1_test_edge_lim.sww', minimum_allowed_height=0.01) 17 #p2 = util.get_output('channel_floodplain1_test.sww', minimum_allowed_height=0.01) 18 #p=util.get_centroids(p2, velocity_extrapolation=False) 19 20 #p2 = util.get_output('channel_floodplain1_standard.sww', minimum_allowed_height=0.01) 21 #p2 = util.get_output('channel_floodplain1_balanced_basic.sww', minimum_allowed_height=0.01) 22 #p2 = util.get_output('channel_floodplain1_dev.sww') 23 #p=util.get_centroids(p2, velocity_extrapolation=True) 24 #p=p2 25 v = (p.x>6.0)*(p.x<8.0) 9 26 #util.animate_1D(p.time, p.stage[:, v], p.y[v]) 10 27 … … 18 35 ########################################################################## 19 36 20 Qin=6.6339 # Inflow discharge 37 #Qin=6.6339 # Inflow discharge 38 #Qin=5.2 39 Qin=4.6932 40 #Qin=4.693286 # Inflow discharge 21 41 slp=1./300. # Floodplain slope (= water slope for steady uniform flow) 22 42 man_n=0.03 # Manning's n … … 53 73 # Analytical solution has U*abs(U)*n^2 / D^(4./3.) = Sf = bed slope 54 74 # Hence, the following two variables should be equal -- I have checked that x velocities are fairly small 55 py lab.clf()56 py lab.figure(figsize=(12.,8.))57 py lab.plot(p.y[v], (V2**2)**0.5,'o', label='computed velocity')58 py lab.plot(p.y[v], V2*0+k*dc_analytical**(2./3.), 'o', label='Analytical velocity')59 py lab.plot(p.y[v], V1, 'o',label='computed depth')60 py lab.plot(p.y[v], V1*0. + dc_analytical, 'o', label='analytical depth')61 #py lab.plot( ( (1./300.)*V1**(4./3.)*(1./0.03)**2.)**0.5,'o', label='Analytical velocity based on computed depth')62 py lab.title('Mid channel velocities and depths, vs analytical velocities and depths')75 pyplot.clf() 76 pyplot.figure(figsize=(12.,8.)) 77 pyplot.plot(p.y[v], (V2**2)**0.5,'o', label='computed velocity') 78 pyplot.plot(p.y[v], V2*0+k*dc_analytical**(2./3.), 'o', label='Analytical velocity') 79 pyplot.plot(p.y[v], V1, 'o',label='computed depth') 80 pyplot.plot(p.y[v], V1*0. + dc_analytical, 'o', label='analytical depth') 81 #pyplot.plot( ( (1./300.)*V1**(4./3.)*(1./0.03)**2.)**0.5,'o', label='Analytical velocity based on computed depth') 82 pyplot.title('Mid channel velocities and depths, vs analytical velocities and depths') 63 83 # But in my tests, they are not equal 64 #pylab.legend( ('computed velocity', 'Analytical velocity', 'computed depth', 'analytical depth'))65 py lab.savefig('trapz_velocity_downstream_l0_eq_2t.png')84 pyplot.legend( ('computed velocity', 'Analytical velocity', 'computed depth', 'analytical depth'), loc=4) 85 pyplot.savefig('trapz_velocity_downstream_l0_eq_1_EL.png') 66 86 67 87 # Plot velocity over the cross-section 68 v1 = (p.y<500.0)&(p.y>4 70.0)88 v1 = (p.y<500.0)&(p.y>490.0) 69 89 70 py lab.clf()90 pyplot.clf() 71 91 analytical_stage = min(p.elev[v1]) + dc_analytical 72 92 analytic_vel = ( (1./300.)*(analytical_stage-p.elev[v1])**(4./3.)*(1./0.03)**2.)**0.5 73 93 analytic_vel = analytic_vel*(analytical_stage>p.elev[v1]) 74 py lab.figure(figsize=(12.,8.))75 py lab.plot(p.x[v1], p.yvel[index,v1],'o', label='computed velocity (m/s)')76 py lab.plot(p.x[v1], analytic_vel,'o', label='analytical velocity (m/s)')77 py lab.plot(p.x[v1],p.elev[v1],'o', label='bed elevation (m)')78 py lab.plot(p.x[v1],p.stage[index,v1],'o', label='computed stage (m)')79 py lab.plot(p.x[v1],p.stage[index,v1]*0. + analytical_stage,'o', label='analytical stage (m)')94 pyplot.figure(figsize=(12.,8.)) 95 pyplot.plot(p.x[v1], p.yvel[index,v1],'o', label='computed velocity (m/s)') 96 pyplot.plot(p.x[v1], analytic_vel,'o', label='analytical velocity (m/s)') 97 pyplot.plot(p.x[v1],p.elev[v1],'o', label='bed elevation (m)') 98 pyplot.plot(p.x[v1],p.stage[index,v1],'o', label='computed stage (m)') 99 pyplot.plot(p.x[v1],p.stage[index,v1]*0. + analytical_stage,'o', label='analytical stage (m)') 80 100 81 #pylab.legend( ('computed velocity (m/s)', 'analytical velocity (m/s)', 'bed elevation (m)', 'computed stage (m)', 'analytical_stage (m)') ) 82 pylab.title('Velocity (analytical and numerical) and Stage:' + '\n' +'Central channel regions (470 to 500m)' +'\n') 83 pylab.savefig('trapz_velocity_cross_channel_l0_eq_2t.png') 84 101 pyplot.legend( ('computed velocity (m/s)', 'analytical velocity (m/s)', 'bed elevation (m)', 'computed stage (m)', 'analytical_stage (m)') ,loc=10) 102 pyplot.title('Velocity (analytical and numerical) and Stage:' + '\n' +'Central channel regions (470 to 500m)' +'\n') 103 pyplot.savefig('trapz_velocity_cross_channel_l0_eq_1_EL.png') 85 104 86 105 87 106 # Plot velocity over the cross-section 88 v1 = (p.y<800.0)&(p.y>7 70.0)107 v1 = (p.y<800.0)&(p.y>790.0) 89 108 90 py lab.clf()109 pyplot.clf() 91 110 analytical_stage = min(p.elev[v1]) + dc_analytical 92 111 analytic_vel = ( (1./300.)*(analytical_stage-p.elev[v1])**(4./3.)*(1./0.03)**2.)**0.5 93 112 analytic_vel = analytic_vel*(analytical_stage>p.elev[v1]) 94 py lab.figure(figsize=(12.,8.))95 py lab.plot(p.x[v1], p.yvel[index,v1],'o', label='computed velocity (m/s)')96 py lab.plot(p.x[v1], analytic_vel,'o', label='analytical velocity (m/s)')97 py lab.plot(p.x[v1],p.elev[v1],'o', label='bed elevation (m)')98 py lab.plot(p.x[v1],p.stage[index,v1],'o', label='computed stage (m)')99 py lab.plot(p.x[v1],p.stage[index,v1]*0. + analytical_stage,'o', label='analytical stage (m)')113 pyplot.figure(figsize=(12.,8.)) 114 pyplot.plot(p.x[v1], p.yvel[index,v1],'o', label='computed velocity (m/s)') 115 pyplot.plot(p.x[v1], analytic_vel,'o', label='analytical velocity (m/s)') 116 pyplot.plot(p.x[v1],p.elev[v1],'o', label='bed elevation (m)') 117 pyplot.plot(p.x[v1],p.stage[index,v1],'o', label='computed stage (m)') 118 pyplot.plot(p.x[v1],p.stage[index,v1]*0. + analytical_stage,'o', label='analytical stage (m)') 100 119 101 #pylab.legend( ('computed velocity (m/s)', 'analytical velocity (m/s)', 'bed elevation (m)', 'computed stage (m)', 'analytical_stage (m)') ) 102 pylab.title('Velocity (analytical and numerical) and Stage:' + '\n' +'Central channel regions (770 to 800m)' +'\n') 103 pylab.savefig('trapz_velocity_cross_channel_l0_eq_2tb.png') 104 105 120 pyplot.legend( ('computed velocity (m/s)', 'analytical velocity (m/s)', 'bed elevation (m)', 'computed stage (m)', 'analytical_stage (m)') ,loc=10) 121 pyplot.title('Velocity (analytical and numerical) and Stage:' + '\n' +'Central channel regions (470 to 500m)' +'\n') 122 pyplot.savefig('trapz_velocity_cross_channel_l0_eq_1b_EL.png') 106 123 107 124 # Plot velocity over the cross-section 108 v1 = (p.y<900.0)&(p.y>8 70.0)125 v1 = (p.y<900.0)&(p.y>890.0) 109 126 110 py lab.clf()127 pyplot.clf() 111 128 analytical_stage = min(p.elev[v1]) + dc_analytical 112 129 analytic_vel = ( (1./300.)*(analytical_stage-p.elev[v1])**(4./3.)*(1./0.03)**2.)**0.5 113 130 analytic_vel = analytic_vel*(analytical_stage>p.elev[v1]) 114 py lab.figure(figsize=(12.,8.))115 py lab.plot(p.x[v1], p.yvel[index,v1],'o', label='computed velocity (m/s)')116 py lab.plot(p.x[v1], analytic_vel,'o', label='analytical velocity (m/s)')117 py lab.plot(p.x[v1],p.elev[v1],'o', label='bed elevation (m)')118 py lab.plot(p.x[v1],p.stage[index,v1],'o', label='computed stage (m)')119 py lab.plot(p.x[v1],p.stage[index,v1]*0. + analytical_stage,'o', label='analytical stage (m)')131 pyplot.figure(figsize=(12.,8.)) 132 pyplot.plot(p.x[v1], p.yvel[index,v1],'o', label='computed velocity (m/s)') 133 pyplot.plot(p.x[v1], analytic_vel,'o', label='analytical velocity (m/s)') 134 pyplot.plot(p.x[v1],p.elev[v1],'o', label='bed elevation (m)') 135 pyplot.plot(p.x[v1],p.stage[index,v1],'o', label='computed stage (m)') 136 pyplot.plot(p.x[v1],p.stage[index,v1]*0. + analytical_stage,'o', label='analytical stage (m)') 120 137 121 #pylab.legend( ('computed velocity (m/s)', 'analytical velocity (m/s)', 'bed elevation (m)', 'computed stage (m)', 'analytical_stage (m)'))122 py lab.title('Velocity (analytical and numerical) and Stage:' + '\n' +'Central channel regions (870 to 900m)' +'\n')123 py lab.savefig('trapz_velocity_cross_channel_l0_eq_2tc.png')138 pyplot.legend( ('computed velocity (m/s)', 'analytical velocity (m/s)', 'bed elevation (m)', 'computed stage (m)', 'analytical_stage (m)') , loc=10) 139 pyplot.title('Velocity (analytical and numerical) and Stage:' + '\n' +'Central channel regions (870 to 900m)' +'\n') 140 pyplot.savefig('trapz_velocity_cross_channel_l0_eq_1c_EL.png') -
trunk/anuga_work/development/gareth/tests/parabolic/parabolaplot.py
r8308 r8353 5 5 #--------------- 6 6 import anuga 7 import struct7 #import struct 8 8 import numpy 9 import scipy 10 import pylab 9 #import scipy 10 from matplotlib import pyplot as pyplot 11 import util 11 12 12 from Scientific.IO.NetCDF import NetCDFFile 13 p=util.get_output('parabola_v2.sww', 0.01) 14 p2=util.get_centroids(p, velocity_extrapolation=True) 13 15 14 #-------------- 15 # Get variables 16 #-------------- 17 fid = NetCDFFile('parabola_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 time = fid.variables['time'] 31 time = time.getValue() 32 33 #xvel2 = fid.variables['centroid_xvelocity'] 34 #xvel2 = xvel2.getValue() 35 #yvel2 = fid.variables['centroid_yvelocity'] 36 #yvel2 = yvel2.getValue() 37 vols=fid.variables['volumes'] 38 vols=vols.getValue() 39 40 # Calculate centroids 41 x_cent=vols[:,0]*0.0 42 y_cent=vols[:,0]*0.0 43 44 for 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 49 xvel_cent = numpy.arange(0.0,len(x_cent)*xmom.shape[0]*1.0).reshape(xmom.shape[0],len(x_cent)) 50 yvel_cent = numpy.arange(0.0,len(x_cent)*xmom.shape[0]*1.0).reshape(xmom.shape[0],len(x_cent)) 51 52 xfile=open('xvel.out','rb') 53 floatsize=struct.calcsize('f') 54 for 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 61 xfile.close() 62 63 yfile=open('yvel.out','rb') 64 floatsize2=struct.calcsize('f') 65 for 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 72 yfile.close() 73 74 vel_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 #------------------- 104 xvel=xmom*0 105 yvel=ymom*0 106 for 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 110 vel=(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 #------------------ 119 v=(y==0.0) 120 v2=(y_cent==y_cent[40]) 16 # Define some 'lines' along which to plot 17 v=(p2.y==p2.y[0]) 121 18 122 19 #-------------------- 123 20 # Make plot animation 124 21 #-------------------- 125 py lab.close() #If the plot is open, there will be problems126 py lab.ion()22 pyplot.close() #If the plot is open, there will be problems 23 pyplot.ion() 127 24 128 if True:129 line, = py lab.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 py lab.draw()134 #py lab.plot( (0,1),(0,0), 'r' )135 py lab.plot(x[v],elev[v])136 py lab.title(str(i)+'/200') # : velocity does not converge to zero' )137 py lab.xlabel('x')138 py lab.ylabel('stage (m/s)')25 if False: 26 line, = pyplot.plot( (p2.x[v].min(),p2.x[v].max()) ,(p2.stage[:,v].min(),p2.stage[:,v].max() ) ) 27 for i in range(700,p2.xmom.shape[0]): 28 line.set_xdata(p2.x[v]) 29 line.set_ydata(p2.stage[i,v]) 30 pyplot.draw() 31 #pyplot.plot( (0,1),(0,0), 'r' ) 32 pyplot.plot(p2.x[v],p2.elev[v]) 33 pyplot.title(str(i)+'/200') # : velocity does not converge to zero' ) 34 pyplot.xlabel('x') 35 pyplot.ylabel('stage (m/s)') 139 36 140 if True:141 py lab.clf()37 if False: 38 pyplot.clf() 142 39 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 40 line, = pyplot.plot( (p2.x[v].min(),p2.x[v].max()) ,(p2.xvel[:,v].min(),p2.xvel[:,v].max() ), 'ro' ) 41 for i in range(700,p2.xmom.shape[0]): 42 line.set_xdata(p2.x[v]) 43 line.set_ydata(p2.xvel[i,v]) 44 pyplot.draw() 45 pyplot.plot( (p2.x[v].min(),p2.x[v].max()),(0,0), 'ro' ) 46 #pyplot.plot(x[v],elev[v]) 47 pyplot.title(str(i)+'/200') # : velocity does not converge to zero' ) 48 pyplot.xlabel('x') 49 pyplot.ylabel('xvel (m/s)') 165 50 166 51 D0=4.0 … … 172 57 omega=numpy.sqrt(2*D0*g)/L 173 58 T= 2*numpy.pi/omega 174 ppp= (abs( x-4.*L/2.)).argmin()175 ppp2= (abs( x-4.*L/4.)).argmin()59 ppp= (abs(p2.x-4.*L/2.)).argmin() 60 ppp2= (abs(p2.x-4.*L/4.)).argmin() 176 61 177 w = D0 + 2*A*D0/(L**2)*numpy.cos(omega* time)*( (x[ppp]-4.*L/2.) -A/2.*numpy.cos(omega*time))178 w2 = D0 + 2*A*D0/(L**2)*numpy.cos(omega* time)*( (x[ppp2]-4.*L/2.) -A/2.*numpy.cos(omega*time))179 w2 = w2*(w2> elev[ppp2])+elev[ppp2]*(w2<=elev[ppp2])62 w = D0 + 2*A*D0/(L**2)*numpy.cos(omega*p2.time)*( (p2.x[ppp]-4.*L/2.) -A/2.*numpy.cos(omega*p2.time)) 63 w2 = D0 + 2*A*D0/(L**2)*numpy.cos(omega*p2.time)*( (p2.x[ppp2]-4.*L/2.) -A/2.*numpy.cos(omega*p2.time)) 64 w2 = w2*(w2>p2.elev[ppp2])+p2.elev[ppp2]*(w2<=p2.elev[ppp2]) 180 65 181 py lab.clf()182 py lab.plot(time,w)183 py lab.plot(time,stage[:,ppp])184 py lab.savefig('Stage_centre_v2.png')185 # py lab.savefig('runup_x_velocities.png')186 py lab.clf()187 py lab.plot(time,w2)188 py lab.plot(time,stage[:,ppp2])189 py lab.savefig('Stage_centre_v3.png')66 pyplot.clf() 67 pyplot.plot(p2.time,w, color='blue') 68 pyplot.plot(p2.time,p2.stage[:,ppp], color='green') 69 pyplot.savefig('Stage_centre_v2.png') 70 # pyplot.savefig('runup_x_velocities.png') 71 pyplot.clf() 72 pyplot.plot(p2.time,w2, color='blue') 73 pyplot.plot(p2.time,p2.stage[:,ppp2], color='green') 74 pyplot.savefig('Stage_centre_v3.png') 190 75 191 76 192 pltind=numpy.argmin(abs( time-T*3))77 pltind=numpy.argmin(abs(p2.time-T*3)) 193 78 194 py lab.clf()195 py lab.plot(x[v],xvel[pltind,v])196 py lab.title('Velocity near to time=3T')197 py lab.savefig('Vel_3T_v2.png')79 pyplot.clf() 80 pyplot.plot(p2.x[v],p2.xvel[pltind,v]) 81 pyplot.title('Velocity near to time=3T') 82 pyplot.savefig('Vel_3T_v2.png') 198 83 199 pltind=numpy.argmin(abs( time-T*3.25))84 pltind=numpy.argmin(abs(p2.time-T*3.25)) 200 85 201 pylab.clf() 202 pylab.plot(x[v],xvel[pltind,v]) 203 pylab.title('Velocity near to time=3.25T') 204 pylab.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') 86 pyplot.clf() 87 pyplot.plot(p2.x[v],p2.xvel[pltind,v]) 88 pyplot.title('Velocity near to time=3.25T') 89 pyplot.savefig('Vel_3_5T_v2.png') 90 #pyplot.clf() 91 #pyplot.close() -
trunk/anuga_work/development/gareth/tests/parabolic/parabolic.py
r8308 r8353 5 5 #-------- 6 6 import anuga 7 7 #from anuga.shallow_water.shallow_water_domain import Domain as Domain 8 8 import numpy 9 9 10 import struct 11 #import scipy 12 13 #from Numeric import * 14 15 from math import sin, pi, exp 10 from balanced_dev import * 11 #from balanced_basic import * 16 12 #from anuga.shallow_water_balanced2.swb2_domain import Domain as Domain 17 from anuga.shallow_water.shallow_water_domain import Domain as Domain13 #from anuga.shallow_water.shallow_water_domain import Domain as Domain 18 14 #--------- 19 15 #Setup computational domain … … 25 21 domain.set_datadir('.') # Use current folder 26 22 domain.set_quantities_to_be_stored({'stage': 2, 'xmomentum': 2, 'ymomentum': 2, 'elevation': 1}) 27 #domain.set_minimum_allowed_height(0.01)23 domain.set_minimum_allowed_height(0.01) 28 24 # Time stepping 29 25 #domain.set_timestepping_method('euler') # Default … … 81 77 #Evolve the system through time 82 78 #------------------------------ 83 84 xwrite=open("xvel.out","wb")85 ywrite=open("yvel.out","wb")86 # Set print options to be compatible with file writing via the 'print' statement87 numpy.set_printoptions(threshold=numpy.nan, linewidth=numpy.nan)88 89 79 for t in domain.evolve(yieldstep=0.1,finaltime=90.0): 90 80 print domain.timestepping_statistics() 91 # Calculate velocity at centroids, and record92 momx=domain.quantities['xmomentum'].centroid_values93 momy=domain.quantities['ymomentum'].centroid_values94 dep1=(domain.quantities['stage'].centroid_values-domain.quantities['elevation'].centroid_values+1.0e-06)95 velx=momx/dep196 vely=momy/dep197 98 for i in velx:99 data=struct.pack('f',i)100 xwrite.write(data)101 81 102 for j in vely:103 data2=struct.pack('f',j)104 ywrite.write(data2)105 106 107 xwrite.close()108 ywrite.close()109 82 print 'Finished' -
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') -
trunk/anuga_work/development/gareth/tests/runup_sinusoid/runup_sinusoid.py
r8308 r8353 8 8 import numpy 9 9 10 import struct11 #import scipy12 from sys import path13 #from Numeric import *14 15 10 from math import sin, pi, exp 16 11 #from anuga.shallow_water.shallow_water_domain import Domain as Domain … … 18 13 #path.append('/home/gareth/storage/anuga_clean/anuga_jan12/trunk/anuga_work/development/gareth/balanced_basic') 19 14 #from swb2_domain import * 20 from balanced_basic import * 15 #from balanced_basic import * 16 from balanced_dev import * 21 17 #--------- 22 18 #Setup computational domain … … 28 24 domain.set_datadir('.') # Use current folder 29 25 domain.set_quantities_to_be_stored({'stage': 2, 'xmomentum': 2, 'ymomentum': 2, 'elevation': 1}) 30 domain.set_store_vertices_uniquely(True) 31 # Time stepping 32 #domain.set_timestepping_method('euler') # Default 33 #domain.set_timestepping_method('rk2') # 34 #domain.beta_w= 1. #0.2 35 #domain.beta_uh= 1. #0.2 36 #domain.beta_vh= 1. #0.2 37 #domain.beta_w_dry= 0.2 #0. 38 #domain.beta_uh_dry= 0.2 #0. 39 #domain.beta_vh_dry= 0.2 #0. 40 #domain.alpha=100. 26 #domain.set_store_vertices_uniquely(True) 41 27 42 28 #------------------ … … 45 31 46 32 def topography(x,y): 47 return -x/2.0 +0.05*numpy.sin((x+y)*50.0) #+0.1*(numpy.random.rand(len(x)) -0.5) # Linear bed slope + small random perturbation 48 # Note that without smoothing, this will cause the elevation to be discontinuous, which at present the model cannot manage. 33 return -x/2.0 +0.05*numpy.sin((x+y)*50.0) 49 34 50 35 def stagefun(x,y): … … 88 73 #------------------------------ 89 74 90 xwrite=open("xvel.out","wb")91 ywrite=open("yvel.out","wb")92 # Set print options to be compatible with file writing via the 'print' statement93 numpy.set_printoptions(threshold=numpy.nan, linewidth=numpy.nan)94 95 75 for t in domain.evolve(yieldstep=0.1,finaltime=20.0): 96 76 print domain.timestepping_statistics() 97 momx=domain.quantities['xmomentum'].centroid_values98 momy=domain.quantities['ymomentum'].centroid_values99 #mom2=domain.quantities['xmomentum'].vertex_values100 dep1=domain.quantities['stage'].centroid_values-domain.quantities['elevation'].centroid_values101 dep1=dep1*(dep1>1.0e-03) +1.0e-06102 #dep2=(domain.quantities['stage'].vertex_values-domain.quantities['elevation'].vertex_values+1.0e-06)103 velx=momx/dep1104 vely=momy/dep1105 #vel2=mom2/dep2106 #print vel1.max(), vel2.max()107 #print vel1.min(), vel2.min()108 #xwrite.write(velx)109 #print >> xwrite, str(velx)110 #print >> ywrite, str(vely)111 for i in velx:112 data=struct.pack('f',i)113 xwrite.write(data)114 115 for j in vely:116 data2=struct.pack('f',j)117 ywrite.write(data2)118 119 #print >> xwrite, \n120 #numpy.savetxt("xvel.txt",velx)121 #numpy.savetxt("yvel.txt",vely)122 #velx.tofile(xwrite," ")123 #vely.tofile(ywrite," ")124 125 xwrite.close()126 ywrite.close()127 77 128 78 print 'Finished' -
trunk/anuga_work/development/gareth/tests/runup_sinusoid/runup_sinusoidplot.py
r8308 r8353 8 8 import numpy 9 9 10 p1=util.get_output('runup_sinusoid_v2.sww' )11 p2=util.get_centroids(p1 )10 p1=util.get_output('runup_sinusoid_v2.sww', 0.001) 11 p2=util.get_centroids(p1, velocity_extrapolation=True) 12 12 13 13 #------------------ -
trunk/anuga_work/development/gareth/tests/util.py
r8308 r8353 4 4 class get_output: 5 5 """Read in data from an .sww file in a convenient form 6 e.g. p = util.get_output('channel3.sww') 6 e.g. 7 p = util.get_output('channel3.sww', minimum_allowed_height=0.01) 8 9 p then contains most relevant information as e.g., p.stage, p.elev, p.xmom, etc 7 10 """ 8 def __init__(self, filename ):11 def __init__(self, filename, minimum_allowed_height=1.0e-03): 9 12 self.x, self.y, self.time, self.vols, self.stage, \ 10 13 self.elev, self.xmom, self.ymom, \ 11 self.xvel, self.yvel, self.vel = \12 read_output(filename )14 self.xvel, self.yvel, self.vel, self.minimum_allowed_height = \ 15 read_output(filename, minimum_allowed_height) 13 16 14 17 15 def read_output(filename ):18 def read_output(filename, minimum_allowed_height): 16 19 # Input: The name of an .sww file to read data from, 17 20 # e.g. read_sww('channel3.sww') … … 61 64 62 65 for i in range(xmom.shape[0]): 63 xvel[i,:]=xmom[i,:]/(stage[i,:]-elev+1.0e-06)*(stage[i,:]> elev+ 2.0e-02)64 yvel[i,:]=ymom[i,:]/(stage[i,:]-elev+1.0e-06)*(stage[i,:]> elev+ 2.0e-02)66 xvel[i,:]=xmom[i,:]/(stage[i,:]-elev+1.0e-06)*(stage[i,:]> elev+minimum_allowed_height) 67 yvel[i,:]=ymom[i,:]/(stage[i,:]-elev+1.0e-06)*(stage[i,:]> elev+minimum_allowed_height) 65 68 66 69 vel = (xvel**2+yvel**2)**0.5 67 70 68 return x, y, time, vols, stage, elev, xmom, ymom, xvel, yvel, vel 71 return x, y, time, vols, stage, elev, xmom, ymom, xvel, yvel, vel, minimum_allowed_height 69 72 70 73 ############## … … 102 105 class get_centroids: 103 106 """ 104 Extract centroid values from p=util.get_output('my_sww.sww') 107 Extract centroid values from the output of get_output. 108 e.g. 109 p = util.get_output('my_sww.sww', minimum_allowed_height=0.01) # vertex values 110 pc=util.get_centroids(p, velocity_extrapolation=True) # centroid values 105 111 """ 106 def __init__(self,p ):107 self. x, self.y, self.stage, self.xmom,\112 def __init__(self,p, velocity_extrapolation=False): 113 self.time, self.x, self.y, self.stage, self.xmom,\ 108 114 self.ymom, self.elev, self.xvel, \ 109 self.yvel, self.vel= get_centroid_values(p) 115 self.yvel, self.vel= \ 116 get_centroid_values(p, velocity_extrapolation) 117 110 118 111 def get_centroid_values(p ):119 def get_centroid_values(p, velocity_extrapolation): 112 120 # Input: p is the result of e.g. p=util.get_output('mysww.sww'). See the get_output class defined above 113 121 # Output: Values of x, y, Stage, xmom, ymom, elev, xvel, yvel, vel at centroids … … 120 128 vols2=numpy.zeros(l, dtype='int') 121 129 130 # FIXME: 22/2/12/ - I think this loop is slow, should be able to do this 131 # another way 122 132 for i in range(l): 123 133 vols0[i]=p.vols[i][0] … … 130 140 131 141 stage_cent=(p.stage[:,vols0]+p.stage[:,vols1]+p.stage[:,vols2])/3.0 132 xmom_cent=(p.xmom[:,vols0]+p.xmom[:,vols1]+p.xmom[:,vols2])/3.0133 ymom_cent=(p.ymom[:,vols0]+p.ymom[:,vols1]+p.ymom[:,vols2])/3.0134 142 elev_cent=(p.elev[vols0]+p.elev[vols1]+p.elev[vols2])/3.0 135 143 136 # Now compute velocities 137 xvel_cent=stage_cent*0.0 138 yvel_cent=stage_cent*0.0 139 vel_cent=stage_cent*0.0 144 # Here, we need to treat differently the case of momentum extrapolation or 145 # velocity extrapolation 146 if velocity_extrapolation: 147 xvel_cent=(p.xvel[:,vols0]+p.xvel[:,vols1]+p.xvel[:,vols2])/3.0 148 yvel_cent=(p.yvel[:,vols0]+p.yvel[:,vols1]+p.yvel[:,vols2])/3.0 149 150 # Now compute momenta 151 xmom_cent=stage_cent*0.0 152 ymom_cent=stage_cent*0.0 140 153 141 t=len(p.time)154 t=len(p.time) 142 155 143 for i in range(t): 144 xvel_cent[i,:]=xmom_cent[i,:]/(stage_cent[i,:]-elev_cent+1.0e-06)*(stage_cent[i,:]>elev_cent+1.0e-03) 145 yvel_cent[i,:]=ymom_cent[i,:]/(stage_cent[i,:]-elev_cent+1.0e-06)*(stage_cent[i,:]>elev_cent+1.0e-03) 146 156 for i in range(t): 157 xmom_cent[i,:]=xvel_cent[i,:]*(stage_cent[i,:]-elev_cent+1.0e-06)*\ 158 (stage_cent[i,:]>elev_cent+p.minimum_allowed_height) 159 ymom_cent[i,:]=yvel_cent[i,:]*(stage_cent[i,:]-elev_cent+1.0e-06)*\ 160 (stage_cent[i,:]>elev_cent+p.minimum_allowed_height) 161 162 else: 163 xmom_cent=(p.xmom[:,vols0]+p.xmom[:,vols1]+p.xmom[:,vols2])/3.0 164 ymom_cent=(p.ymom[:,vols0]+p.ymom[:,vols1]+p.ymom[:,vols2])/3.0 165 166 # Now compute velocities 167 xvel_cent=stage_cent*0.0 168 yvel_cent=stage_cent*0.0 169 170 t=len(p.time) 171 172 for i in range(t): 173 xvel_cent[i,:]=xmom_cent[i,:]/(stage_cent[i,:]-elev_cent+1.0e-06)*(stage_cent[i,:]>elev_cent+p.minimum_allowed_height) 174 yvel_cent[i,:]=ymom_cent[i,:]/(stage_cent[i,:]-elev_cent+1.0e-06)*(stage_cent[i,:]>elev_cent+p.minimum_allowed_height) 175 176 177 # Compute velocity 147 178 vel_cent=(xvel_cent**2 + yvel_cent**2)**0.5 148 179 149 return x_cent, y_cent, stage_cent, xmom_cent,\180 return p.time, x_cent, y_cent, stage_cent, xmom_cent,\ 150 181 ymom_cent, elev_cent, xvel_cent, yvel_cent, vel_cent 151 182
Note: See TracChangeset
for help on using the changeset viewer.