[3530] | 1 | """Simple water flow example using ANUGA |
---|
| 2 | |
---|
| 3 | Water driven up a linear slope and time varying boundary, |
---|
| 4 | similar to a beach environment. |
---|
| 5 | |
---|
| 6 | """ |
---|
| 7 | |
---|
| 8 | |
---|
| 9 | #------------------------------------------------------------------------------ |
---|
| 10 | # Import necessary modules |
---|
| 11 | #------------------------------------------------------------------------------ |
---|
| 12 | |
---|
| 13 | import sys |
---|
| 14 | |
---|
[3535] | 15 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
[3560] | 16 | from abstract_2d_finite_volumes.mesh_factory import rectangular_cross |
---|
[3618] | 17 | from anuga.config import g |
---|
[3563] | 18 | from anuga.shallow_water import Domain |
---|
| 19 | from anuga.shallow_water import Reflective_boundary |
---|
| 20 | from anuga.shallow_water import Dirichlet_boundary |
---|
| 21 | from anuga.shallow_water import Time_boundary |
---|
| 22 | from anuga.shallow_water import Transmissive_Momentum_Set_Stage_boundary |
---|
[3560] | 23 | from abstract_2d_finite_volumes.util import file_function |
---|
[3693] | 24 | from pylab import plot, xlabel, ylabel, title, ion, close, savefig,\ |
---|
| 25 | figure, axis, legend, grid, hold |
---|
[3530] | 26 | |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | #------------------------------------------------------------------------------ |
---|
| 30 | # Model constants |
---|
| 31 | |
---|
[3693] | 32 | slope = -0.02 # 1:50 Slope, reaches h=20m 1000m from western bndry, |
---|
| 33 | # and h=0 (coast) at 300m |
---|
[3530] | 34 | highest_point = 6 # Highest elevation (m) |
---|
| 35 | sea_level = 0 # Mean sea level |
---|
| 36 | min_elevation = -20 # Lowest elevation (elevation of offshore flat part) |
---|
[3689] | 37 | offshore_depth = sea_level-min_elevation # offshore water depth |
---|
[3693] | 38 | |
---|
| 39 | amplitude = 0.5 # Solitary wave height H |
---|
[3530] | 40 | normalized_amplitude = amplitude/offshore_depth |
---|
| 41 | simulation_name = 'runup_convergence' |
---|
[3630] | 42 | coastline_x = -highest_point/slope |
---|
[3530] | 43 | |
---|
| 44 | # Basin dimensions (m) |
---|
| 45 | west = 0 # left boundary |
---|
[3618] | 46 | east = 1500 # right boundary |
---|
[3530] | 47 | south = 0 # lower boundary |
---|
[3618] | 48 | north = 100 # upper boundary |
---|
[3530] | 49 | |
---|
| 50 | |
---|
| 51 | #------------------------------------------------------------------------------ |
---|
| 52 | # Setup computational domain all units in meters |
---|
| 53 | #------------------------------------------------------------------------------ |
---|
| 54 | |
---|
| 55 | # Structured mesh |
---|
[4145] | 56 | dx = 5 # Resolution: Length of subdivisions on x axis (length) |
---|
| 57 | dy = 5 # Resolution: Length of subdivisions on y axis (width) |
---|
[3530] | 58 | |
---|
| 59 | length = east-west |
---|
| 60 | width = north-south |
---|
[3693] | 61 | points, vertices, boundary = rectangular_cross(length/dx, width/dy, |
---|
| 62 | len1=length, len2=width, |
---|
[3530] | 63 | origin = (west, south)) |
---|
| 64 | |
---|
| 65 | domain = Domain(points, vertices, boundary) # Create domain |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | # Unstructured mesh |
---|
| 69 | polygon = [[east,north],[west,north],[west,south],[east,south]] |
---|
[3693] | 70 | interior_polygon = [[400,north-10],[west+10,north-10], |
---|
| 71 | [west+10,south+10],[400,south+10]] |
---|
[3530] | 72 | meshname = simulation_name + '.msh' |
---|
| 73 | create_mesh_from_regions(polygon, |
---|
[3693] | 74 | boundary_tags={'top': [0], 'left': [1], |
---|
| 75 | 'bottom': [2], 'right': [3]}, |
---|
| 76 | maximum_triangle_area=dx*dy/4, |
---|
[3530] | 77 | filename=meshname, |
---|
| 78 | interior_regions=[[interior_polygon,dx*dy/32]]) |
---|
[3693] | 79 | |
---|
[4025] | 80 | |
---|
| 81 | |
---|
[3530] | 82 | domain = Domain(meshname, use_cache=True, verbose = True) |
---|
[3689] | 83 | domain.set_minimum_storable_height(0.01) |
---|
[3530] | 84 | |
---|
| 85 | domain.set_name(simulation_name) |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | #------------------------------------------------------------------------------ |
---|
| 89 | # Setup initial conditions |
---|
| 90 | #------------------------------------------------------------------------------ |
---|
| 91 | |
---|
| 92 | #def topography(x,y): |
---|
[3693] | 93 | # return slope*x+highest_point # Return linear bed slope (vector) |
---|
[3530] | 94 | |
---|
| 95 | def topography(x,y): |
---|
| 96 | """Two part topography - slope and flat part |
---|
| 97 | """ |
---|
| 98 | |
---|
| 99 | from Numeric import zeros, Float |
---|
| 100 | |
---|
| 101 | z = zeros(len(x), Float) # Allocate space for return vector |
---|
| 102 | for i in range(len(x)): |
---|
| 103 | |
---|
| 104 | z[i] = slope*x[i]+highest_point # Linear bed slope bathymetry |
---|
| 105 | |
---|
| 106 | if z[i] < min_elevation: # Limit depth |
---|
| 107 | z[i] = min_elevation |
---|
| 108 | |
---|
| 109 | return z |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
| 115 | domain.set_quantity('friction', 0.0 ) # Constant friction |
---|
| 116 | domain.set_quantity('stage', sea_level) # Constant initial stage |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | #------------------------------------------------------------------------------ |
---|
| 120 | # Setup boundary conditions |
---|
| 121 | #------------------------------------------------------------------------------ |
---|
| 122 | |
---|
| 123 | from math import sin, pi, cosh, sqrt |
---|
| 124 | Br = Reflective_boundary(domain) # Solid reflective wall |
---|
| 125 | Bd = Dirichlet_boundary([0.,0.,0.]) # Constant boundary values |
---|
| 126 | |
---|
[3618] | 127 | |
---|
[3530] | 128 | def waveform(t): |
---|
[3693] | 129 | return sea_level +\ |
---|
| 130 | amplitude/cosh(((t-50)/offshore_depth)*(0.75*g*amplitude)**0.5)**2 |
---|
[3530] | 131 | |
---|
| 132 | # Time dependent boundary for stage, where momentum is set automatically |
---|
| 133 | Bts = Transmissive_Momentum_Set_Stage_boundary(domain, waveform) |
---|
| 134 | |
---|
| 135 | # Associate boundary tags with boundary objects |
---|
| 136 | domain.set_boundary({'left': Br, 'right': Bts, 'top': Br, 'bottom': Br}) |
---|
| 137 | |
---|
| 138 | |
---|
[3693] | 139 | # Find initial runup location and height (coastline) |
---|
[3689] | 140 | w0 = domain.get_maximum_inundation_elevation() |
---|
| 141 | x0, y0 = domain.get_maximum_inundation_location() |
---|
[3700] | 142 | print |
---|
| 143 | print 'Coastline elevation = %.2f at (x,y)=(%.2f, %.2f)' %(w0, x0, y0) |
---|
[3693] | 144 | |
---|
| 145 | # Sanity check |
---|
[3689] | 146 | w_i = domain.get_quantity('stage').get_values(interpolation_points=[[x0,y0]]) |
---|
[3700] | 147 | print 'Interpolated elevation at (x,y)=(%.2f, %.2f) is %.2f' %(x0, y0, w_i) |
---|
[3689] | 148 | |
---|
[3693] | 149 | |
---|
[3530] | 150 | #------------------------------------------------------------------------------ |
---|
| 151 | # Evolve system through time |
---|
| 152 | #------------------------------------------------------------------------------ |
---|
| 153 | |
---|
[3689] | 154 | w_max = w0 |
---|
[3617] | 155 | for t in domain.evolve(yieldstep = 1, finaltime = 300): |
---|
[3530] | 156 | domain.write_time() |
---|
| 157 | |
---|
[3689] | 158 | w = domain.get_maximum_inundation_elevation() |
---|
| 159 | x, y = domain.get_maximum_inundation_location() |
---|
[3700] | 160 | print ' Coastline elevation = %.2f at (x,y)=(%.2f, %.2f)' %(w, x, y) |
---|
| 161 | print |
---|
[3689] | 162 | |
---|
| 163 | if w > w_max: |
---|
| 164 | w_max = w |
---|
| 165 | x_max = x |
---|
| 166 | y_max = y |
---|
| 167 | |
---|
[3530] | 168 | |
---|
[4025] | 169 | y0 = y_max |
---|
[3700] | 170 | print '**********************************************' |
---|
[4025] | 171 | print 'Coastline elevation = %.2f at (x,y)=(%.2f, %.2f)' %(w0, x0, y0) |
---|
[3689] | 172 | print 'Max coastline elevation = %.2f at (%.2f, %.2f)' %(w_max, x_max, y_max) |
---|
[3693] | 173 | print 'Run up distance = %.2f' %sqrt( (x_max-x0)**2 + (y_max-y0)**2 ) |
---|
[3700] | 174 | print '**********************************************' |
---|
[3689] | 175 | |
---|
| 176 | |
---|
[3530] | 177 | #----------------------------------------------------------------------------- |
---|
[3693] | 178 | # Interrogate further |
---|
| 179 | #--------------------------------------------------------------- |
---|
[3530] | 180 | |
---|
[3700] | 181 | # Generate time series of one "gauge" situated at right hand boundary |
---|
[3630] | 182 | from anuga.abstract_2d_finite_volumes.util import sww2timeseries |
---|
| 183 | production_dirs = {'.': 'test'} |
---|
| 184 | swwfiles = {} |
---|
| 185 | for label_id in production_dirs.keys(): |
---|
| 186 | |
---|
| 187 | swwfile = simulation_name + '.sww' |
---|
| 188 | swwfiles[swwfile] = label_id |
---|
| 189 | |
---|
| 190 | texname, elev_output = sww2timeseries(swwfiles, |
---|
| 191 | 'boundary_gauge.xya', |
---|
| 192 | production_dirs, |
---|
| 193 | report = False, |
---|
| 194 | reportname = 'test', |
---|
| 195 | plot_quantity = ['stage', 'speed'], |
---|
| 196 | surface = False, |
---|
| 197 | time_min = None, |
---|
| 198 | time_max = None, |
---|
| 199 | title_on = True, |
---|
| 200 | verbose = True) |
---|
[3530] | 201 | |
---|
[3618] | 202 | |
---|
[3530] | 203 | |
---|
| 204 | |
---|