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