Ignore:
Timestamp:
Mar 7, 2012, 9:49:06 PM (13 years ago)
Author:
davies
Message:

Updates to balanced_dev and associated tests

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  
    44#Import Modules
    55#--------
    6 from sys import path
    76import anuga
    87
    98import numpy
    10 
    11 import struct
    12 #import scipy
    13 
    14 #from Numeric import *
    159
    1610from math import sin, pi, exp
     
    2317#from swb_domain import *
    2418#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 *
     20from balanced_dev import *
    2621#---------
    2722#Setup computational domain
     
    3328domain.set_datadir('.')                          # Use current folder
    3429domain.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)
    3631#------------------
    3732# Define topography
     
    6661# Associate boundary tags with boundary objects
    6762#----------------------------------------------
    68 domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom':Br})
     63domain.set_boundary({'left': Br, 'right': Bw, 'top': Br, 'bottom':Br})
    6964
    7065#------------------------------
     
    8075    print domain.timestepping_statistics()
    8176
    82 #    momx=domain.quantities['xmomentum'].centroid_values
    83 #    momy=domain.quantities['ymomentum'].centroid_values
    84 #    #mom2=domain.quantities['xmomentum'].vertex_values
    85 #    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/dep1
    88 #    vely=momy/dep1
    89 #    #vel2=mom2/dep2
    90 #    #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, \n
    104 #    #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()
    11177
    11278print 'Finished'
  • trunk/anuga_work/development/gareth/tests/runup/runuplot.py

    r8308 r8353  
    55#---------------
    66import anuga
    7 import struct
    87import numpy
    98import scipy
    10 import pylab
     9from matplotlib import pyplot as pyplot
     10import util # Routines to read in and work with ANUGA output
    1111
    12 from Scientific.IO.NetCDF import NetCDFFile
     12p2=util.get_output('runup_v2.sww', minimum_allowed_height=1.0e-03)
     13p=util.get_centroids(p2, velocity_extrapolation=True)
    1314
    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)
    3616
    37 # Calculate centroids
    38 x_cent=vols[:,0]*0.0
    39 y_cent=vols[:,0]*0.0
    40 
    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.0
    43     y_cent[i]=(y[vols[i,0]]+y[vols[i,1]]+y[vols[i,2]])/3.0
    44 
    45 # Read in centroid velocities
    46 #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)+j
    56 #        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)+j
    67 #        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 string
    73 ##xvel2=[]
    74 ##for line in file('xvel.txt'):
    75 ##    line = line.rstrip('\n')
    76 ##    xvel2.append(line)
    77 ## Coerce values to array
    78 ##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 Velocity
    100 #-------------------
    101 xvel=xmom*0
    102 yvel=ymom*0
    103 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.5
    10817#------------------
    10918# Select line
    11019#------------------
    111 v=(y==0)
     20py_central=p.y[scipy.argmin(abs(p.y-0.5))]
     21v=(p.y==p.y[py_central])
    11222
    11323#--------------------
    11424# Make plot animation
    11525#--------------------
    116 pylab.close() #If the plot is open, there will be problems
    117 pylab.ion()
     26pyplot.close() #If the plot is open, there will be problems
     27pyplot.ion()
    11828
    11929if True:
    120     line, = pylab.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         pylab.draw()
    125         pylab.plot( (0,1),(0,0), 'r' )
    126         pylab.title(str(i)+'/200') # : velocity does not converge to zero' )
    127         pylab.xlabel('x')
    128         pylab.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)')
    12939
    130     pylab.savefig('runup_x_velocities.png')
     40    pyplot.savefig('runup_x_velocities.png')
    13141
    132 #pylab.clf()
    133 #pylab.close()
     42#pyplot.clf()
     43#pyplot.close()
    13444
    13545#------------------------------------------------
     
    13949#highx=yvel[3,:].argmax()
    14050#v=(x==x[highx])
    141 #pylab.plot(yvel[3,v])
    142 #pylab.title('y-velocity is not always zero at the boundaries, e.g. x='+str(x[highx])+' , t=0.3s')
    143 #pylab.xlabel('y')
    144 #pylab.ylabel('Velocity (m/s)')
    145 #pylab.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')
    14656
    147 pylab.clf()
    148 pylab.plot(x[y==0.5],stage[5,y==0.5])
    149 pylab.plot(x[y==0.5],stage[5,y==0.5],'o')
    150 pylab.plot(x[y==0.5],elev[y==0.5])
    151 pylab.xlabel('x (m)')
    152 pylab.ylabel('z (m)')
    153 pylab.title('Free surface and bed at y==0.5, time = 1.0 second')
    154 pylab.savefig('elev_1s_v2.png')
     57pyplot.clf()
     58pyplot.plot(p.x[v],p.stage[5,v])
     59pyplot.plot(p.x[v],p.stage[5,v],'o')
     60pyplot.plot(p.x[v],p.elev[v])
     61pyplot.xlabel('x (m)')
     62pyplot.ylabel('z (m)')
     63pyplot.title('Free surface and bed at y==0.5, time = 1.0 second')
     64pyplot.savefig('elev_1s_v2.png')
    15565
    156 pylab.clf()
    157 pylab.plot(x[y==0.5],xvel[5,y==0.5])
    158 pylab.plot(x[y==0.5],xvel[5,y==0.5],'o')
    159 pylab.title('Velocity at y==0.500, time = 1.0 second')
    160 pylab.xlabel('x (m)')
    161 pylab.ylabel('Velocity (m/s)')
    162 pylab.savefig('vel1d_1s_v2.png')
     66pyplot.clf()
     67pyplot.plot(p.x[v],p.xvel[5,v])
     68pyplot.plot(p.x[v],p.xvel[5,v],'o')
     69pyplot.title('Velocity at y==0.500, time = 1.0 second')
     70pyplot.xlabel('x (m)')
     71pyplot.ylabel('Velocity (m/s)')
     72pyplot.savefig('vel1d_1s_v2.png')
    16373
    164 #pylab.clf()
    165 #pylab.plot(x_cent[y_cent==y_cent[80]],xvel_cent[15,y_cent==y_cent[80]])
    166 #pylab.plot(x_cent[y_cent==y_cent[80]],xvel_cent[15,y_cent==y_cent[80]],'o')
    167 #pylab.title('Velocity at y==0.500, time = 3.0 second')
    168 #pylab.xlabel('x (m)')
    169 #pylab.ylabel('Velocity (m/s)')
    170 #pylab.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')
    17181#-------------------------------------
    17282# Final velocities plot
    17383#-------------------------------------
    174 #pylab.clf()
    175 #pylab.quiver(x,y,xvel[200,:],yvel[200,:])
    176 #pylab.xlabel('x')
    177 #pylab.ylabel('y')
    178 #pylab.title('The maximum speed is '+ str(vel[200,:].max()) + ' m/s')
    179 #pylab.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')
    18090#print vel[200,:].max()
    18191
    182 pylab.clf()
    183 pylab.scatter(x,y,c=elev,edgecolors='none', s=25)
    184 pylab.colorbar()
    185 #pylab.quiver(x_cent,y_cent,xvel_cent[15,:],yvel_cent[15,:])
    186 #pylab.title('The maximum speed is '+ str(vel_cent[15,:].max()) + ' m/s at time 3.0s')
    187 pylab.quiver(x,y,xvel[5,:],yvel[5,:])
    188 pylab.title('The maximum speed is '+ str(vel[5,:].max()) + ' m/s at time 1.0s')
    189 pylab.savefig('vel_1s_v2.png')
     92pyplot.clf()
     93pyplot.scatter(p.x,p.y,c=p.elev,edgecolors='none', s=25)
     94pyplot.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')
     97pyplot.quiver(p.x,p.y,p.xvel[5,:],p.yvel[5,:])
     98pyplot.title('The maximum speed is '+ str(p.vel[5,:].max()) + ' m/s at time 1.0s')
     99pyplot.savefig('vel_1s_v2.png')
    190100
    191 pylab.clf()
    192 pylab.scatter(x,y,c=elev,edgecolors='none', s=25)
    193 pylab.colorbar()
    194 #pylab.quiver(x_cent,y_cent,xvel_cent[150,:],yvel_cent[150,:])
    195 #pylab.title('The maximum speed is '+ str(vel_cent[150,:].max()) + ' m/s at time 30.0s')
    196 pylab.quiver(x,y,xvel[150,:],yvel[150,:])
    197 pylab.title('The maximum speed is '+ str(vel[150,:].max()) + ' m/s at time 30.0s')
    198 pylab.savefig('vel_30s_v2.png')
     101pyplot.clf()
     102pyplot.scatter(p.x,p.y,c=p.elev,edgecolors='none', s=25)
     103pyplot.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')
     106pyplot.quiver(p.x,p.y,p.xvel[150,:],p.yvel[150,:])
     107pyplot.title('The maximum speed is '+ str(p.vel[150,:].max()) + ' m/s at time 30.0s')
     108pyplot.savefig('vel_30s_v2.png')
    199109
    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')
     110pyplot.clf()
     111pyplot.plot(p.x[v],p.stage[150,v])
     112pyplot.plot(p.x[v],p.stage[150,v],'o')
     113pyplot.plot(p.x[v],p.elev[v])
     114pyplot.xlabel('x (m)')
     115pyplot.ylabel('z (m)')
     116pyplot.title('Free surface and bed at y==0.5, time = 30.0 second')
     117pyplot.savefig('elev_30s_v2.png')
     118pyplot.clf()
     119pyplot.plot(p.x[v],p.xvel[150,v])
     120pyplot.plot(p.x[v],p.xvel[150,v],'o')
     121pyplot.title('Velocity at y==0.500, time = 30.0 second')
     122pyplot.xlabel('x (m)')
     123pyplot.ylabel('Velocity (m/s)')
     124pyplot.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.