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
Files:
5 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_work/development/gareth/tests/channel_floodplain/channel_floodplain1.py

    r8309 r8353  
    1010import numpy
    1111from anuga.structures.inlet_operator import Inlet_operator
    12 
     12from anuga import *
     13#from swb_domain import domain
    1314#from anuga import *
    1415#from balanced_basic import *
     
    2324floodplain_width = 14.0 # Model domain width
    2425floodplain_slope = 1./300.
    25 chan_initial_depth = 0.8 # Initial depth of water in the channel
     26chan_initial_depth = 0.65 # Initial depth of water in the channel
    2627chan_bankfull_depth = 1.0 # Bankfull depth of the channel
    2728chan_width = 10.0 # Bankfull width of the channel
    2829bankwidth = 2. # Width of the bank regions -- note that these protrude into the channel
    2930man_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)
     31l0 = 1.000 # Length scale associated with triangle side length in channel (min_triangle area = 0.5*l0^2)
    3132
    3233assert chan_width < floodplain_width, \
     
    8182
    8283
    83 domain.set_name('channel_floodplain1_test') # Output name
    84 domain.extrapolate_velocity_second_order=True
     84domain.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
    8588#------------------------------------------------------------------------------
    8689#
     
    139142
    140143# Define inlet operator
     144flow_in_yval=100.0
    141145if 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] \
    144148              ]
    145149    Qin = 0.5*(floodplain_slope*(chan_width*chan_initial_depth)**2.*man_n**(-2.)\
     
    191195Br = anuga.Reflective_boundary(domain) # Solid reflective wall
    192196Bt = 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
     199Bout_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
    196202
    197203def outflow_stage_boundary(t):
     
    226232#------------------------------------------------------------------------------
    227233
    228 for t in domain.evolve(yieldstep=1.0, finaltime=800.0):
     234for t in domain.evolve(yieldstep=2.0, finaltime=3200.0):
    229235    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
    230254    #print domain.quantities['ymomentum'].get_integral()
    231255    #print 'Qin = ', Qin
  • trunk/anuga_work/development/gareth/tests/channel_floodplain/plotme.py

    r8308 r8353  
    11import util
    2 import pylab
     2from matplotlib import pyplot as pyplot
     3#import pylab
    34
    45# Time-index to plot outputs from
    56index=800
    67
    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
     12p2 = util.get_output('channel_floodplain1_bal_dev.sww', 0.01)
     13p=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
     25v = (p.x>6.0)*(p.x<8.0)
    926#util.animate_1D(p.time, p.stage[:, v], p.y[v])
    1027
     
    1835##########################################################################
    1936
    20 Qin=6.6339  # Inflow discharge
     37#Qin=6.6339  # Inflow discharge
     38#Qin=5.2
     39Qin=4.6932
     40#Qin=4.693286 # Inflow discharge
    2141slp=1./300. # Floodplain slope (= water slope for steady uniform flow)
    2242man_n=0.03  # Manning's n
     
    5373# Analytical solution has U*abs(U)*n^2 / D^(4./3.) = Sf = bed slope
    5474# Hence, the following two variables should be equal -- I have checked that x velocities are fairly small
    55 pylab.clf()
    56 pylab.figure(figsize=(12.,8.))
    57 pylab.plot(p.y[v], (V2**2)**0.5,'o', label='computed velocity')
    58 pylab.plot(p.y[v], V2*0+k*dc_analytical**(2./3.), 'o', label='Analytical velocity')
    59 pylab.plot(p.y[v], V1, 'o',label='computed depth')
    60 pylab.plot(p.y[v], V1*0. + dc_analytical, 'o', label='analytical depth')
    61 #pylab.plot( ( (1./300.)*V1**(4./3.)*(1./0.03)**2.)**0.5,'o', label='Analytical velocity based on computed depth')
    62 pylab.title('Mid channel velocities and depths, vs analytical velocities and depths')
     75pyplot.clf()
     76pyplot.figure(figsize=(12.,8.))
     77pyplot.plot(p.y[v], (V2**2)**0.5,'o', label='computed velocity')
     78pyplot.plot(p.y[v], V2*0+k*dc_analytical**(2./3.), 'o', label='Analytical velocity')
     79pyplot.plot(p.y[v], V1, 'o',label='computed depth')
     80pyplot.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')
     82pyplot.title('Mid channel velocities and depths, vs analytical velocities and depths')
    6383# But in my tests, they are not equal
    64 #pylab.legend( ('computed velocity', 'Analytical velocity', 'computed depth', 'analytical depth'))
    65 pylab.savefig('trapz_velocity_downstream_l0_eq_2t.png')
     84pyplot.legend( ('computed velocity', 'Analytical velocity', 'computed depth', 'analytical depth'), loc=4)
     85pyplot.savefig('trapz_velocity_downstream_l0_eq_1_EL.png')
    6686
    6787# Plot velocity over the cross-section
    68 v1 = (p.y<500.0)&(p.y>470.0)
     88v1 = (p.y<500.0)&(p.y>490.0)
    6989
    70 pylab.clf()
     90pyplot.clf()
    7191analytical_stage = min(p.elev[v1]) + dc_analytical
    7292analytic_vel = ( (1./300.)*(analytical_stage-p.elev[v1])**(4./3.)*(1./0.03)**2.)**0.5
    7393analytic_vel = analytic_vel*(analytical_stage>p.elev[v1])
    74 pylab.figure(figsize=(12.,8.))
    75 pylab.plot(p.x[v1], p.yvel[index,v1],'o', label='computed velocity (m/s)')
    76 pylab.plot(p.x[v1], analytic_vel,'o', label='analytical velocity (m/s)')
    77 pylab.plot(p.x[v1],p.elev[v1],'o', label='bed elevation (m)')
    78 pylab.plot(p.x[v1],p.stage[index,v1],'o', label='computed stage (m)')
    79 pylab.plot(p.x[v1],p.stage[index,v1]*0. + analytical_stage,'o', label='analytical stage (m)')
     94pyplot.figure(figsize=(12.,8.))
     95pyplot.plot(p.x[v1], p.yvel[index,v1],'o', label='computed velocity (m/s)')
     96pyplot.plot(p.x[v1], analytic_vel,'o', label='analytical velocity (m/s)')
     97pyplot.plot(p.x[v1],p.elev[v1],'o', label='bed elevation (m)')
     98pyplot.plot(p.x[v1],p.stage[index,v1],'o', label='computed stage (m)')
     99pyplot.plot(p.x[v1],p.stage[index,v1]*0. + analytical_stage,'o', label='analytical stage (m)')
    80100
    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 
     101pyplot.legend( ('computed velocity (m/s)', 'analytical velocity (m/s)', 'bed elevation (m)', 'computed stage (m)', 'analytical_stage (m)') ,loc=10)
     102pyplot.title('Velocity (analytical and numerical) and Stage:' + '\n' +'Central channel regions (470 to 500m)' +'\n')
     103pyplot.savefig('trapz_velocity_cross_channel_l0_eq_1_EL.png')
    85104
    86105
    87106# Plot velocity over the cross-section
    88 v1 = (p.y<800.0)&(p.y>770.0)
     107v1 = (p.y<800.0)&(p.y>790.0)
    89108
    90 pylab.clf()
     109pyplot.clf()
    91110analytical_stage = min(p.elev[v1]) + dc_analytical
    92111analytic_vel = ( (1./300.)*(analytical_stage-p.elev[v1])**(4./3.)*(1./0.03)**2.)**0.5
    93112analytic_vel = analytic_vel*(analytical_stage>p.elev[v1])
    94 pylab.figure(figsize=(12.,8.))
    95 pylab.plot(p.x[v1], p.yvel[index,v1],'o', label='computed velocity (m/s)')
    96 pylab.plot(p.x[v1], analytic_vel,'o', label='analytical velocity (m/s)')
    97 pylab.plot(p.x[v1],p.elev[v1],'o', label='bed elevation (m)')
    98 pylab.plot(p.x[v1],p.stage[index,v1],'o', label='computed stage (m)')
    99 pylab.plot(p.x[v1],p.stage[index,v1]*0. + analytical_stage,'o', label='analytical stage (m)')
     113pyplot.figure(figsize=(12.,8.))
     114pyplot.plot(p.x[v1], p.yvel[index,v1],'o', label='computed velocity (m/s)')
     115pyplot.plot(p.x[v1], analytic_vel,'o', label='analytical velocity (m/s)')
     116pyplot.plot(p.x[v1],p.elev[v1],'o', label='bed elevation (m)')
     117pyplot.plot(p.x[v1],p.stage[index,v1],'o', label='computed stage (m)')
     118pyplot.plot(p.x[v1],p.stage[index,v1]*0. + analytical_stage,'o', label='analytical stage (m)')
    100119
    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 
     120pyplot.legend( ('computed velocity (m/s)', 'analytical velocity (m/s)', 'bed elevation (m)', 'computed stage (m)', 'analytical_stage (m)') ,loc=10)
     121pyplot.title('Velocity (analytical and numerical) and Stage:' + '\n' +'Central channel regions (470 to 500m)' +'\n')
     122pyplot.savefig('trapz_velocity_cross_channel_l0_eq_1b_EL.png')
    106123
    107124# Plot velocity over the cross-section
    108 v1 = (p.y<900.0)&(p.y>870.0)
     125v1 = (p.y<900.0)&(p.y>890.0)
    109126
    110 pylab.clf()
     127pyplot.clf()
    111128analytical_stage = min(p.elev[v1]) + dc_analytical
    112129analytic_vel = ( (1./300.)*(analytical_stage-p.elev[v1])**(4./3.)*(1./0.03)**2.)**0.5
    113130analytic_vel = analytic_vel*(analytical_stage>p.elev[v1])
    114 pylab.figure(figsize=(12.,8.))
    115 pylab.plot(p.x[v1], p.yvel[index,v1],'o', label='computed velocity (m/s)')
    116 pylab.plot(p.x[v1], analytic_vel,'o', label='analytical velocity (m/s)')
    117 pylab.plot(p.x[v1],p.elev[v1],'o', label='bed elevation (m)')
    118 pylab.plot(p.x[v1],p.stage[index,v1],'o', label='computed stage (m)')
    119 pylab.plot(p.x[v1],p.stage[index,v1]*0. + analytical_stage,'o', label='analytical stage (m)')
     131pyplot.figure(figsize=(12.,8.))
     132pyplot.plot(p.x[v1], p.yvel[index,v1],'o', label='computed velocity (m/s)')
     133pyplot.plot(p.x[v1], analytic_vel,'o', label='analytical velocity (m/s)')
     134pyplot.plot(p.x[v1],p.elev[v1],'o', label='bed elevation (m)')
     135pyplot.plot(p.x[v1],p.stage[index,v1],'o', label='computed stage (m)')
     136pyplot.plot(p.x[v1],p.stage[index,v1]*0. + analytical_stage,'o', label='analytical stage (m)')
    120137
    121 #pylab.legend( ('computed velocity (m/s)', 'analytical velocity (m/s)', 'bed elevation (m)', 'computed stage (m)', 'analytical_stage (m)') )
    122 pylab.title('Velocity (analytical and numerical) and Stage:' + '\n' +'Central channel regions (870 to 900m)' +'\n')
    123 pylab.savefig('trapz_velocity_cross_channel_l0_eq_2tc.png')
     138pyplot.legend( ('computed velocity (m/s)', 'analytical velocity (m/s)', 'bed elevation (m)', 'computed stage (m)', 'analytical_stage (m)') , loc=10)
     139pyplot.title('Velocity (analytical and numerical) and Stage:' + '\n' +'Central channel regions (870 to 900m)' +'\n')
     140pyplot.savefig('trapz_velocity_cross_channel_l0_eq_1c_EL.png')
  • trunk/anuga_work/development/gareth/tests/parabolic/parabolaplot.py

    r8308 r8353  
    55#---------------
    66import anuga
    7 import struct
     7#import struct
    88import numpy
    9 import scipy
    10 import pylab
     9#import scipy
     10from matplotlib import pyplot as pyplot
     11import util
    1112
    12 from Scientific.IO.NetCDF import NetCDFFile
     13p=util.get_output('parabola_v2.sww', 0.01)
     14p2=util.get_centroids(p, velocity_extrapolation=True)
    1315
    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
     17v=(p2.y==p2.y[0])
    12118
    12219#--------------------
    12320# Make plot animation
    12421#--------------------
    125 pylab.close() #If the plot is open, there will be problems
    126 pylab.ion()
     22pyplot.close() #If the plot is open, there will be problems
     23pyplot.ion()
    12724
    128 if 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)')
     25if 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)')
    13936
    140 if True:
    141     pylab.clf()
     37if False:
     38    pyplot.clf()
    14239 
    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)')
    16550
    16651D0=4.0
     
    17257omega=numpy.sqrt(2*D0*g)/L
    17358T= 2*numpy.pi/omega
    174 ppp= (abs(x-4.*L/2.)).argmin()
    175 ppp2= (abs(x-4.*L/4.)).argmin()
     59ppp= (abs(p2.x-4.*L/2.)).argmin()
     60ppp2= (abs(p2.x-4.*L/4.)).argmin()
    17661
    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])
     62w = D0 + 2*A*D0/(L**2)*numpy.cos(omega*p2.time)*( (p2.x[ppp]-4.*L/2.) -A/2.*numpy.cos(omega*p2.time))
     63w2 = D0 + 2*A*D0/(L**2)*numpy.cos(omega*p2.time)*( (p2.x[ppp2]-4.*L/2.) -A/2.*numpy.cos(omega*p2.time))
     64w2 = w2*(w2>p2.elev[ppp2])+p2.elev[ppp2]*(w2<=p2.elev[ppp2])
    18065
    181 pylab.clf()
    182 pylab.plot(time,w)
    183 pylab.plot(time,stage[:,ppp])
    184 pylab.savefig('Stage_centre_v2.png')
    185 #       pylab.savefig('runup_x_velocities.png')
    186 pylab.clf()
    187 pylab.plot(time,w2)
    188 pylab.plot(time,stage[:,ppp2])
    189 pylab.savefig('Stage_centre_v3.png')
     66pyplot.clf()
     67pyplot.plot(p2.time,w, color='blue')
     68pyplot.plot(p2.time,p2.stage[:,ppp], color='green')
     69pyplot.savefig('Stage_centre_v2.png')
     70#       pyplot.savefig('runup_x_velocities.png')
     71pyplot.clf()
     72pyplot.plot(p2.time,w2, color='blue')
     73pyplot.plot(p2.time,p2.stage[:,ppp2], color='green')
     74pyplot.savefig('Stage_centre_v3.png')
    19075
    19176
    192 pltind=numpy.argmin(abs(time-T*3))
     77pltind=numpy.argmin(abs(p2.time-T*3))
    19378
    194 pylab.clf()
    195 pylab.plot(x[v],xvel[pltind,v])
    196 pylab.title('Velocity near to time=3T')
    197 pylab.savefig('Vel_3T_v2.png')
     79pyplot.clf()
     80pyplot.plot(p2.x[v],p2.xvel[pltind,v])
     81pyplot.title('Velocity near to time=3T')
     82pyplot.savefig('Vel_3T_v2.png')
    19883
    199 pltind=numpy.argmin(abs(time-T*3.25))
     84pltind=numpy.argmin(abs(p2.time-T*3.25))
    20085
    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')
     86pyplot.clf()
     87pyplot.plot(p2.x[v],p2.xvel[pltind,v])
     88pyplot.title('Velocity near to time=3.25T')
     89pyplot.savefig('Vel_3_5T_v2.png')
     90#pyplot.clf()
     91#pyplot.close()
  • trunk/anuga_work/development/gareth/tests/parabolic/parabolic.py

    r8308 r8353  
    55#--------
    66import anuga
    7 
     7#from anuga.shallow_water.shallow_water_domain import Domain as Domain
    88import numpy
    99
    10 import struct
    11 #import scipy
    12 
    13 #from Numeric import *
    14 
    15 from math import sin, pi, exp
     10from balanced_dev import *
     11#from balanced_basic import *
    1612#from anuga.shallow_water_balanced2.swb2_domain import Domain as Domain
    17 from anuga.shallow_water.shallow_water_domain import Domain as Domain
     13#from anuga.shallow_water.shallow_water_domain import Domain as Domain
    1814#---------
    1915#Setup computational domain
     
    2521domain.set_datadir('.')                          # Use current folder
    2622domain.set_quantities_to_be_stored({'stage': 2, 'xmomentum': 2, 'ymomentum': 2, 'elevation': 1})
    27 #domain.set_minimum_allowed_height(0.01)
     23domain.set_minimum_allowed_height(0.01)
    2824# Time stepping
    2925#domain.set_timestepping_method('euler') # Default
     
    8177#Evolve the system through time
    8278#------------------------------
    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' statement
    87 numpy.set_printoptions(threshold=numpy.nan, linewidth=numpy.nan)
    88 
    8979for t in domain.evolve(yieldstep=0.1,finaltime=90.0):
    9080    print domain.timestepping_statistics()
    91     # Calculate velocity at centroids, and record
    92     momx=domain.quantities['xmomentum'].centroid_values
    93     momy=domain.quantities['ymomentum'].centroid_values
    94     dep1=(domain.quantities['stage'].centroid_values-domain.quantities['elevation'].centroid_values+1.0e-06)
    95     velx=momx/dep1
    96     vely=momy/dep1
    97    
    98     for i in velx:
    99         data=struct.pack('f',i)
    100         xwrite.write(data)
    10181
    102     for j in vely:
    103         data2=struct.pack('f',j)
    104         ywrite.write(data2)
    105 
    106 
    107 xwrite.close()
    108 ywrite.close()
    10982print 'Finished'
  • 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')
  • trunk/anuga_work/development/gareth/tests/runup_sinusoid/runup_sinusoid.py

    r8308 r8353  
    88import numpy
    99
    10 import struct
    11 #import scipy
    12 from sys import path
    13 #from Numeric import *
    14 
    1510from math import sin, pi, exp
    1611#from anuga.shallow_water.shallow_water_domain import Domain as Domain
     
    1813#path.append('/home/gareth/storage/anuga_clean/anuga_jan12/trunk/anuga_work/development/gareth/balanced_basic')
    1914#from swb2_domain import *
    20 from balanced_basic import *
     15#from balanced_basic import *
     16from balanced_dev import *
    2117#---------
    2218#Setup computational domain
     
    2824domain.set_datadir('.')                          # Use current folder
    2925domain.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)
    4127
    4228#------------------
     
    4531
    4632def 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) 
    4934
    5035def stagefun(x,y):
     
    8873#------------------------------
    8974
    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' statement
    93 numpy.set_printoptions(threshold=numpy.nan, linewidth=numpy.nan)
    94 
    9575for t in domain.evolve(yieldstep=0.1,finaltime=20.0):
    9676    print domain.timestepping_statistics()
    97     momx=domain.quantities['xmomentum'].centroid_values
    98     momy=domain.quantities['ymomentum'].centroid_values
    99     #mom2=domain.quantities['xmomentum'].vertex_values
    100     dep1=domain.quantities['stage'].centroid_values-domain.quantities['elevation'].centroid_values
    101     dep1=dep1*(dep1>1.0e-03) +1.0e-06
    102     #dep2=(domain.quantities['stage'].vertex_values-domain.quantities['elevation'].vertex_values+1.0e-06)
    103     velx=momx/dep1
    104     vely=momy/dep1
    105     #vel2=mom2/dep2
    106     #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, \n
    120     #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()
    12777
    12878print 'Finished'
  • trunk/anuga_work/development/gareth/tests/runup_sinusoid/runup_sinusoidplot.py

    r8308 r8353  
    88import numpy
    99
    10 p1=util.get_output('runup_sinusoid_v2.sww')
    11 p2=util.get_centroids(p1)
     10p1=util.get_output('runup_sinusoid_v2.sww', 0.001)
     11p2=util.get_centroids(p1, velocity_extrapolation=True)
    1212
    1313#------------------
  • trunk/anuga_work/development/gareth/tests/util.py

    r8308 r8353  
    44class get_output:
    55    """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
    710    """
    8     def __init__(self, filename):
     11    def __init__(self, filename, minimum_allowed_height=1.0e-03):
    912        self.x, self.y, self.time, self.vols, self.stage, \
    1013                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)
    1316
    1417
    15 def read_output(filename):
     18def read_output(filename, minimum_allowed_height):
    1619    # Input: The name of an .sww file to read data from,
    1720    #                    e.g. read_sww('channel3.sww')
     
    6164
    6265    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)
    6568
    6669    vel = (xvel**2+yvel**2)**0.5
    6770
    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
    6972
    7073##############
     
    102105class get_centroids:
    103106    """
    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
    105111    """
    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,\
    108114             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                                 
    110118
    111 def get_centroid_values(p):
     119def get_centroid_values(p, velocity_extrapolation):
    112120    # Input: p is the result of e.g. p=util.get_output('mysww.sww'). See the get_output class defined above
    113121    # Output: Values of x, y, Stage, xmom, ymom, elev, xvel, yvel, vel at centroids
     
    120128    vols2=numpy.zeros(l, dtype='int')
    121129
     130    # FIXME: 22/2/12/ - I think this loop is slow, should be able to do this
     131    # another way
    122132    for i in range(l):
    123133        vols0[i]=p.vols[i][0]
     
    130140
    131141    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.0
    133     ymom_cent=(p.ymom[:,vols0]+p.ymom[:,vols1]+p.ymom[:,vols2])/3.0
    134142    elev_cent=(p.elev[vols0]+p.elev[vols1]+p.elev[vols2])/3.0
    135143
    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
    140153
    141     t=len(p.time)
     154        t=len(p.time)
    142155
    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
    147178    vel_cent=(xvel_cent**2 + yvel_cent**2)**0.5
    148179
    149     return x_cent, y_cent, stage_cent, xmom_cent,\
     180    return p.time, x_cent, y_cent, stage_cent, xmom_cent,\
    150181             ymom_cent, elev_cent, xvel_cent, yvel_cent, vel_cent
    151182
Note: See TracChangeset for help on using the changeset viewer.