Ignore:
Timestamp:
Oct 4, 2006, 2:36:27 PM (17 years ago)
Author:
ole
Message:

Incorporated coastline and runup detection for Rosh

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/examples/runup_convergence.py

    r3689 r3693  
    44similar to a beach environment.
    55
    6 The study area is discretised as a regular triangular grid 100m x 100m
    76"""
    87
     
    2322from anuga.shallow_water import Transmissive_Momentum_Set_Stage_boundary
    2423from abstract_2d_finite_volumes.util import file_function
    25 from pylab import plot, xlabel, ylabel, title, ion, close, savefig, figure, axis, legend, grid, hold
     24from pylab import plot, xlabel, ylabel, title, ion, close, savefig,\
     25     figure, axis, legend, grid, hold
    2626
    2727
     
    3030# Model constants
    3131
    32 slope = -0.02       # 1:50 Slope, reaches h=20m 1000m from western bndry, and h=0 (coast) at 300m
     32slope = -0.02       # 1:50 Slope, reaches h=20m 1000m from western bndry,
     33                    # and h=0 (coast) at 300m
    3334highest_point = 6   # Highest elevation (m)
    3435sea_level = 0       # Mean sea level
    3536min_elevation = -20 # Lowest elevation (elevation of offshore flat part)
    3637offshore_depth = sea_level-min_elevation # offshore water depth
    37 amplitude = 0.5       # Solitary wave height H
     38
     39amplitude = 0.5     # Solitary wave height H
    3840normalized_amplitude = amplitude/offshore_depth
    3941simulation_name = 'runup_convergence'   
     
    5759length = east-west
    5860width = north-south
    59 points, vertices, boundary = rectangular_cross(length/dx, width/dy, len1=length, len2=width,
     61points, vertices, boundary = rectangular_cross(length/dx, width/dy,
     62                                               len1=length, len2=width,
    6063                                               origin = (west, south))
    6164
     
    6366
    6467
    65 
    6668# Unstructured mesh
    6769polygon = [[east,north],[west,north],[west,south],[east,south]]
    68 interior_polygon = [[400,north-10],[west+10,north-10],[west+10,south+10],[400,south+10]]
     70interior_polygon = [[400,north-10],[west+10,north-10],
     71                    [west+10,south+10],[400,south+10]]
    6972meshname = simulation_name + '.msh'
    7073create_mesh_from_regions(polygon,
    71                          boundary_tags={'top': [0], 'left': [1], 'bottom': [2], 'right': [3]},
    72                          maximum_triangle_area=dx*dy/4, # Triangle area commensurate with structured mesh
     74                         boundary_tags={'top': [0], 'left': [1],
     75                                        'bottom': [2], 'right': [3]},
     76                         maximum_triangle_area=dx*dy/4,
    7377                         filename=meshname,
    7478                         interior_regions=[[interior_polygon,dx*dy/32]])
     79
    7580domain = Domain(meshname, use_cache=True, verbose = True)
    7681domain.set_minimum_storable_height(0.01)
    77 
    7882
    7983domain.set_name(simulation_name)
     
    8589
    8690#def topography(x,y):
    87 #    return slope*x+highest_point  # Return linear bed slope bathymetry as vector
     91#    return slope*x+highest_point  # Return linear bed slope (vector)
    8892
    8993def topography(x,y):
     
    121125
    122126def waveform(t):
    123     return sea_level + amplitude/cosh(((t-50)/offshore_depth)*(0.75*g*amplitude)**0.5)**2
    124 
    125 Bw = Time_boundary(domain=domain,     # Time dependent boundary 
    126                    f=lambda t: [waveform(t), 0.0, 0.0])
     127    return sea_level +\
     128           amplitude/cosh(((t-50)/offshore_depth)*(0.75*g*amplitude)**0.5)**2
    127129
    128130# Time dependent boundary for stage, where momentum is set automatically
    129131Bts = Transmissive_Momentum_Set_Stage_boundary(domain, waveform)
    130 
    131132
    132133# Associate boundary tags with boundary objects
     
    134135
    135136
     137# Find initial runup location and height (coastline)
    136138w0 = domain.get_maximum_inundation_elevation()
    137139x0, y0 = domain.get_maximum_inundation_location()
    138140print 'Coastline elevation = %.2f at (%.2f, %.2f)' %(w0, x0, y0)
     141
     142# Sanity check
    139143w_i = domain.get_quantity('stage').get_values(interpolation_points=[[x0,y0]])
    140144print 'Interpolated elevation at (%.2f, %.2f) is %.2f' %(x0, y0, w_i)
     145
    141146
    142147#------------------------------------------------------------------------------
     
    145150
    146151w_max = w0
    147 stagestep = []
    148152for t in domain.evolve(yieldstep = 1, finaltime = 300):
    149153    domain.write_time()
     
    151155    w = domain.get_maximum_inundation_elevation()
    152156    x, y = domain.get_maximum_inundation_location()
    153     print '  Coastline elevation = %.2f at (%.2f, %.2f)' %(w, x, y)   
    154     #w_i = domain.get_quantity('stage').get_values(interpolation_points=[[x,y]])
    155     #print '  Interpolated elevation at (%.2f, %.2f) is %.2f' %(x, y, w_i)
    156                                                              
     157    print '  Coastline elevation = %.2f at (x,y)=(%.2f, %.2f)' %(w, x, y)   
    157158
    158159    if w > w_max:
     
    161162        y_max = y
    162163
    163     # Let's find the maximum runup here working directly with the quantities,
    164     # and stop when it has been detected.
    165 
    166     # 1 Find coastline as x where z==0
    167     # 2 Workout travel time to coastline
    168     # 3 Find min x where h>0 over all t.
    169     # 4 Perhaps do this across a number of ys
    170164
    171165print 'Max coastline elevation = %.2f at (%.2f, %.2f)' %(w_max, x_max, y_max)
    172 
    173 print 'Run up distance - %.2f' %sqrt( (x-x0)**2 + (y-y0)**2 )
     166print 'Run up distance = %.2f' %sqrt( (x_max-x0)**2 + (y_max-y0)**2 )
    174167
    175168
    176169
    177170#-----------------------------------------------------------------------------
    178 # Interrogate solution
    179 #-----------------------------------------------------------------------------
     171# Interrogate further
     172#---------------------------------------------------------------
    180173
    181 '''
    182 # Define line of gauges through center of domain
    183 def gauge_line(west,east,north,south):
    184     from Numeric import arange
    185     x_vector = arange(west,600, 10) # Gauges every 1 meter from west to 600m from western bdry
    186     y = (north+south)/2.
    187 
    188     gauges = []
    189     for x in x_vector:
    190         gauges.append([x,y])
    191        
    192     return gauges, x_vector
    193 
    194 gauges, x_vector = gauge_line(west,east,north,south)
    195 
    196 # Obtain interpolated timeseries at gauges
    197 f = file_function(domain.get_name()+'.sww',
    198                   quantities = ['stage', 'elevation', 'xmomentum', 'ymomentum'],
    199                   interpolation_points = gauges,
    200                   verbose = True,
    201                   use_cache = True)
    202 
    203 
    204 # Find runup distance from western boundary through a linear search
    205 max_stage = []
    206 min_stage = []
    207 runup_point = west
    208 coastline = east       
    209 for k, g in enumerate(gauges):
    210     z = f(0, point_id=k)[1] # Elevation
    211 
    212     min_w = sys.maxint
    213     max_w = -min_w
    214     for i, t in enumerate(f.get_time()):
    215         w = f(t, point_id = k)[0]
    216         if w > max_w: max_w = w
    217         if w < min_w: min_w = w       
    218 
    219     if max_w-z <= 0.01:  # Find first gauge where max depth > eps (runup)
    220         runup_point = g[0]
    221 
    222     if min_w-z <= 0.01:  # Find first gauge where min depth > eps (coastline)
    223         coastline = g[0]       
    224        
    225     max_stage.append(max_w)
    226     min_stage.append(min_w)   
    227 
    228 
    229 # Print
    230 print 'wave height [m]:                    ', amplitude
    231 runup_height = topography([runup_point], [(north+south)/2.])[0]
    232 print 'run up height [m]:                  ', runup_height
    233 
    234 runup_distance = runup_point-coastline
    235 print 'run up distance from coastline [m]: ', runup_distance
    236 
    237 print 'Coastline (meters form west):       ', coastline
    238 
    239 '''
    240174# Generate time series of "gauge" situated at right hand boundary
    241175from anuga.abstract_2d_finite_volumes.util import sww2timeseries
     
    259193                                      verbose = True)
    260194
    261 # Stop here
    262 import sys; sys.exit()
    263 
    264 # Take snapshots and plot
    265 ion()
    266 figure(1)
    267 plot(x_vector, topography(x_vector,(north+south)/2.), 'r-')
    268 xlabel('x')
    269 ylabel('Elevation')
    270 #legend(('Max stage', 'Min stage', 'Elevation'), shadow=True, loc='upper right')
    271 title('Stage snapshots (t=0, 10, ...) for gauge line')
    272 grid()
    273 hold(True)
    274 
    275 for i, t in enumerate(f.get_time()):
    276     if i % 10 == 0:
    277         # Take only some timesteps to avoid clutter
    278         stages = []   
    279         for k, g in enumerate(gauges):
    280             w = f(t, point_id = k)[0]       
    281             stages.append(w)
    282 
    283         plot(x_vector, stages, 'b-')
    284          
    285 savefig('snapshots')
    286195
    287196
    288197
    289 # Store
    290 filename = 'maxrunup'+str(amplitude)+'.csv'
    291 fid = open(filename,'w')   
    292 s = 'Waveheight,Runup distance,Runup height\n'
    293 fid.write(s)
    294 
    295 s = '%.2f,%.2f,%.2f\n' %(amplitude, runup_distance, runup_height)
    296 fid.write(s)
    297 
    298 fid.close()
    299 
    300 # Plot max runup etc
    301 ion()
    302 figure(1)
    303 plot(x_vector, max_stage, 'g+',
    304      x_vector, min_stage, 'b+',     
    305      x_vector, topography(x_vector,(north+south)/2.), 'r-')
    306 xlabel('x')
    307 ylabel('stage')
    308 legend(('Max stage', 'Min stage', 'Elevation'), shadow=True, loc='upper right')
    309 title('Maximum stage for gauge line')
    310 grid()
    311 #axis([33000, 47000, -1000, 3000])
    312 savefig('max_stage')
    313 
    314 close('all')
    315    
    316 
    317 
Note: See TracChangeset for help on using the changeset viewer.