source: inundation/examples/runup_convergence.py @ 3508

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

Demos for Rosh

File size: 6.4 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
6The study area is discretised as a regular triangular grid 100m x 100m
7"""
8
9
10#------------------------------------------------------------------------------
11# Import necessary modules
12#------------------------------------------------------------------------------
13
14import sys
15
16from pmesh.mesh_interface import create_mesh_from_regions
17from pyvolution.mesh_factory import rectangular_cross
18from pyvolution.shallow_water import Domain
19from pyvolution.shallow_water import Reflective_boundary
20from pyvolution.shallow_water import Dirichlet_boundary
21from pyvolution.shallow_water import Time_boundary
22from pyvolution.shallow_water import Transmissive_Momentum_Set_Stage_boundary
23from pyvolution.util import file_function
24from pylab import plot, xlabel, ylabel, title, ion, close, savefig, figure, axis
25ion()
26
27
28#------------------------------------------------------------------------------
29# Model constants
30
31slope = -0.02     # 1:50 Slope
32highest_point = 3 # Highest elevation (m)
33sea_level = -1    # Mean sea level
34amplitude = 2     # Solitary wave height H
35simulation_name = 'runup_convergence'   
36
37
38# Basin dimensions (m)
39west = 0          # left boundary
40east = 500        # right boundary
41south = 0         # lower boundary
42north = 100       # upper bourdary
43
44
45#------------------------------------------------------------------------------
46# Setup computational domain all units in meters
47#------------------------------------------------------------------------------
48
49# Structured mesh
50dx = 10           # Resolution: Lenght of subdivisions on x axis (length)
51dy = 10           # Resolution: Lenght of subdivisions on y axis (width)
52
53length = east-west
54width = north-south
55points, vertices, boundary = rectangular_cross(length/dx, width/dy, len1=length, len2=width,
56                                               origin = (west, south)) 
57
58domain = Domain(points, vertices, boundary) # Create domain
59
60
61
62# Unstructured mesh
63#polygon = [[east,north],[west,north],[west,south],[east,south]]
64#meshname = simulation_name + '.msh'
65#create_mesh_from_regions(polygon,
66#                         boundary_tags={'top': [0], 'left': [1], 'bottom': [2], 'right': [3]},
67#                         maximum_triangle_area=dx*dy/2,
68#                         filename=meshname)
69#                         #interior_regions=interior_regions)
70#domain = Domain(meshname, use_cache=True, verbose = True)
71
72
73
74domain.set_name(simulation_name)
75
76
77#------------------------------------------------------------------------------
78# Setup initial conditions
79#------------------------------------------------------------------------------
80
81def topography(x,y):
82    return slope*x+highest_point  # Return linear bed slope bathymetry as vector
83
84domain.set_quantity('elevation', topography) # Use function for elevation
85domain.set_quantity('friction', 0.0 )        # Constant friction
86domain.set_quantity('stage', sea_level)      # Constant initial stage
87
88
89#------------------------------------------------------------------------------
90# Setup boundary conditions
91#------------------------------------------------------------------------------
92
93from math import sin, pi, cosh, sqrt
94Br = Reflective_boundary(domain)      # Solid reflective wall
95Bd = Dirichlet_boundary([0.,0.,0.])   # Constant boundary values
96
97def waveform(t): 
98    return sea_level + amplitude/cosh(t-5)**2
99
100Bw = Time_boundary(domain=domain,     # Time dependent boundary 
101                   f=lambda t: [waveform(t), 0.0, 0.0])
102
103# Time dependent boundary for stage, where momentum is set automatically
104Bts = Transmissive_Momentum_Set_Stage_boundary(domain, waveform)
105
106
107# Associate boundary tags with boundary objects
108domain.set_boundary({'left': Br, 'right': Bts, 'top': Br, 'bottom': Br})
109
110
111#------------------------------------------------------------------------------
112# Evolve system through time
113#------------------------------------------------------------------------------
114
115stagestep = []
116for t in domain.evolve(yieldstep = 1, finaltime = 100):
117    domain.write_time()
118
119
120#-----------------------------------------------------------------------------
121# Interrogate solution
122#-----------------------------------------------------------------------------
123
124
125# Define line of gauges through center of domain
126def gauge_line(west,east,north,south):
127    from Numeric import arange
128    x_vector = arange(west, (east-west)/2, 10) # Gauges every 1 meter from west to midpt
129    y = (north+south)/2.
130
131    gauges = []
132    for x in x_vector:
133        gauges.append([x,y])
134       
135    return gauges, x_vector
136
137gauges, x_vector = gauge_line(west,east,north,south)
138
139# Obtain interpolated timeseries at gauges
140f = file_function(domain.get_name()+'.sww',
141                  quantities = ['stage', 'elevation', 'xmomentum', 'ymomentum'],
142                  interpolation_points = gauges,
143                  verbose = True,
144                  use_cache = True)
145
146
147# Find runup distance from western boundary through a linear search
148max_stage = []
149min_stage = []
150runup_point = west
151coastline = east       
152for k, g in enumerate(gauges):
153    z = f(0, point_id=k)[1] # Elevation
154
155    min_w = sys.maxint
156    max_w = -min_w
157    for i, t in enumerate(f.get_time()):
158        w = f(t, point_id = k)[0]
159        if w > max_w: max_w = w
160        if w < min_w: min_w = w       
161
162    if max_w-z <= 0.01:  # Find first gauge where max depth > eps (runup)
163        runup_point = g[0]
164
165    if min_w-z <= 0.01:  # Find first gauge where min depth > eps (coastline)
166        coastline = g[0]       
167       
168    max_stage.append(max_w)
169    min_stage.append(min_w)   
170
171
172# Print
173
174print 'wave height [m]:                    ', amplitude
175runup_height = topography(runup_point, (north+south)/2.)
176print 'run up height [m]:                  ', runup_height
177
178runup_distance = runup_point-coastline
179print 'run up distance from coastline [m]: ', runup_distance
180
181print 'Coastline (meters form west):       ', coastline
182
183
184
185# Store
186filename = 'maxrunup'+str(amplitude)+'.csv'
187fid = open(filename,'w')   
188s = 'Depth at eastern boundary,Waveheight,Runup distance,Runup height\n'
189fid.write(s)
190
191s = '%.2f,%.2f,%.2f\n' %(amplitude, runup_distance, runup_height)
192fid.write(s)
193
194fid.close()
195
196# Plot
197figure(1)
198plot(x_vector, max_stage, 'g+',
199     x_vector, min_stage, 'b+',     
200     x_vector, topography(x_vector,(north+south)/2.), 'r-')
201xlabel('x')
202ylabel('stage')
203title('Maximum stage for gauge line')
204#axis([33000, 47000, -1000, 3000])
205savefig('max_stage')
206
207close('all')
208   
209
210
Note: See TracBrowser for help on using the repository browser.