source: anuga_validation/solitary_waves/solitary_wave_runup.py @ 4354

Last change on this file since 4354 was 4353, checked in by ole, 18 years ago

Extended refined region all the way to external boundary.

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