1 | """ANUGA simulation of simple rip current. |
---|
2 | |
---|
3 | Source: Geometry and wave properties loosely based on those presented in |
---|
4 | OBSERVATIONS OF LABORATORY RIP CURRENTS by Brian K. Sapp, |
---|
5 | School of Civil and Environmental Engineering |
---|
6 | Georgia Institute of Technology |
---|
7 | May 2006 |
---|
8 | |
---|
9 | I will need to make a version which has the exact same geometry as the |
---|
10 | Georgia Tech wavetank if we wish to use a comparison to the results of |
---|
11 | this study as ANUGA validation as i played with the geometry somewhat |
---|
12 | as i completed this model. |
---|
13 | """ |
---|
14 | |
---|
15 | #------------------------------------------------------------------------------ |
---|
16 | # Import necessary modules |
---|
17 | #------------------------------------------------------------------------------ |
---|
18 | from anuga.interface import create_domain_from_regions |
---|
19 | from anuga.shallow_water.shallow_water_domain import Dirichlet_boundary |
---|
20 | from anuga.shallow_water.shallow_water_domain import Reflective_boundary |
---|
21 | from anuga.shallow_water.shallow_water_domain import Time_boundary |
---|
22 | from anuga.shallow_water.data_manager import get_mesh_and_quantities_from_file |
---|
23 | from pylab import figure, plot, axis, quiver, quiverkey, show, title, axhline |
---|
24 | from pylab import cos, sin, pi |
---|
25 | import numpy |
---|
26 | import csv |
---|
27 | import time |
---|
28 | |
---|
29 | |
---|
30 | #------------------------------------------------------------------------------ |
---|
31 | # Parameters |
---|
32 | #------------------------------------------------------------------------------ |
---|
33 | |
---|
34 | filename = 'WORKING-RIP-LAB_Expt-Geometry_Triangular_Mesh' |
---|
35 | |
---|
36 | location_of_shore = 140 # The position along the y axis of the shorefront |
---|
37 | sandbar = 1.2 # Height of sandbar |
---|
38 | sealevel = 0 # Height of coast above sea level |
---|
39 | steepness = 8000 # Period of sandbar - |
---|
40 | # larger number gives smoother slope - longer period |
---|
41 | halfchannelwidth = 5 |
---|
42 | bank_slope = 0.1 |
---|
43 | simulation_length = 1 |
---|
44 | timestep = 1 |
---|
45 | |
---|
46 | |
---|
47 | #------------------------------------------------------------------------------ |
---|
48 | # Setup computational domain |
---|
49 | #------------------------------------------------------------------------------ |
---|
50 | length = 120 |
---|
51 | width = 170 |
---|
52 | seafloor_resolution = 60.0 # Resolution: Max area of triangles in the mesh |
---|
53 | feature_resolution = 1.0 |
---|
54 | beach_resolution = 10.0 |
---|
55 | |
---|
56 | sea_boundary_polygon = [[0,0],[length,0],[length,width],[0,width]] |
---|
57 | feature_boundary_polygon = [[0,100],[length,100],[length,150],[0,150]] |
---|
58 | beach_interior_polygon = [[0,150],[length,150],[length,width],[0,width]] |
---|
59 | |
---|
60 | meshname = str(filename)+'.msh' |
---|
61 | |
---|
62 | # Interior regions |
---|
63 | feature_regions = [[feature_boundary_polygon, feature_resolution], |
---|
64 | [beach_interior_polygon, beach_resolution]] |
---|
65 | |
---|
66 | domain = create_domain_from_regions(sea_boundary_polygon, |
---|
67 | boundary_tags={'bottom': [0], |
---|
68 | 'right' : [1], |
---|
69 | 'top' : [2], |
---|
70 | 'left': [3]}, |
---|
71 | maximum_triangle_area=seafloor_resolution, |
---|
72 | mesh_filename=meshname, |
---|
73 | interior_regions=feature_regions, |
---|
74 | use_cache=True, |
---|
75 | verbose=True) |
---|
76 | |
---|
77 | domain.set_name(filename) # Output name |
---|
78 | print domain.statistics() |
---|
79 | |
---|
80 | |
---|
81 | #------------------------------------------------------------------------------ |
---|
82 | # Setup initial conditions |
---|
83 | #------------------------------------------------------------------------------ |
---|
84 | def topography(x,y): |
---|
85 | """Complex topography defined by a function of vectors x and y.""" |
---|
86 | |
---|
87 | # General slope, sets the shore at the location defined previously |
---|
88 | z=0.05*(y-location_of_shore) |
---|
89 | |
---|
90 | # Steeper slope close to the seaward boundary giving a region of deep water |
---|
91 | N = len(x) |
---|
92 | for i in range(N): |
---|
93 | if y[i] < 25: |
---|
94 | z[i] = 0.2*(y[i]-25) + 0.05*(y[i]-location_of_shore) |
---|
95 | |
---|
96 | # Steeper slope close to the landward boundary, simulating a beach etc |
---|
97 | # This helps to prevent too much reflection of wave energy off the |
---|
98 | # landward boundary |
---|
99 | for i in range(N): |
---|
100 | if y[i]>150: |
---|
101 | z[i] = 0.1*(y[i]-150) + 0.05*(y[i]-location_of_shore) |
---|
102 | |
---|
103 | return z |
---|
104 | |
---|
105 | |
---|
106 | def topography3(x,y): |
---|
107 | z=0*x |
---|
108 | |
---|
109 | N = len(x) |
---|
110 | |
---|
111 | # Set up the left hand side of the sandbank |
---|
112 | # amount which it deviates from parallel with the beach is controlled |
---|
113 | # by 'bank_slope' |
---|
114 | # width of the channel (the gap between the two segments of the sandbank) |
---|
115 | # is controlled by 'halfchannelwidth' |
---|
116 | # The height of the sandbar is controlled by 'sandbar' |
---|
117 | # 'steepness' provides control over the slope of the soundbar |
---|
118 | # (smaller values give a more rounded shape, if too small will produce |
---|
119 | # peaks and troughs) |
---|
120 | for i in range(N): |
---|
121 | ymin = -bank_slope*x[i] + 112 |
---|
122 | ymax = -bank_slope*x[i] + 124 |
---|
123 | xmin = 0 |
---|
124 | xmax = length/2-halfchannelwidth |
---|
125 | if ymin < y[i] < ymax and xmin < x[i]< xmax: |
---|
126 | z[i] += sandbar*cos((y[i]-118)/steepness) |
---|
127 | |
---|
128 | # Set up the right hand side of the sandbank |
---|
129 | # changing the sign in y min and y max allows the two halves of the |
---|
130 | # sandbank to form a v shape |
---|
131 | for i in range(N): |
---|
132 | ymin = -bank_slope*(x[i]-length/2) - bank_slope*length/2 + 112 |
---|
133 | ymax = -bank_slope*(x[i]-length/2) - bank_slope*length/2 + 124 |
---|
134 | xmin = length/2+halfchannelwidth |
---|
135 | xmax = 183 |
---|
136 | if ymin < y[i] < ymax and xmin < x[i] < xmax: |
---|
137 | z[i] += sandbar*cos((y[i]-118)/steepness) |
---|
138 | |
---|
139 | return z |
---|
140 | |
---|
141 | domain.set_quantity('elevation', topography) # Apply base elevation function |
---|
142 | domain.add_quantity('elevation', topography3) # Add elevation modification |
---|
143 | domain.set_quantity('friction', 0.01) # Constant friction |
---|
144 | domain.set_quantity('stage', 0) # Constant initial condition at |
---|
145 | # mean sea level |
---|
146 | |
---|
147 | |
---|
148 | #------------------------------------------------------------------------------ |
---|
149 | # Setup boundary conditions |
---|
150 | #------------------------------------------------------------------------------ |
---|
151 | Bi = Dirichlet_boundary([0.4, 0, 0]) # Inflow |
---|
152 | Br = Reflective_boundary(domain) # Solid reflective wall |
---|
153 | Bo = Dirichlet_boundary([-5, 0, 0]) # Outflow |
---|
154 | |
---|
155 | def wave(t): |
---|
156 | """Define wave driving the system |
---|
157 | """ |
---|
158 | |
---|
159 | A = 0.4 # Amplitude of wave [m] (wave height) |
---|
160 | T = 5 # Wave period [s] |
---|
161 | |
---|
162 | if t < 30000000000: |
---|
163 | return [A*sin(2*pi*t/T) + 1, 0, 0] |
---|
164 | else: |
---|
165 | return [0.0, 0, 0] |
---|
166 | |
---|
167 | Bt = Time_boundary(domain, f=wave) |
---|
168 | |
---|
169 | |
---|
170 | domain.set_boundary({'left': Br, 'right': Br, 'top': Bo, 'bottom': Bt}) |
---|
171 | |
---|
172 | |
---|
173 | #------------------------------------------------------------------------------ |
---|
174 | # Evolve system through time |
---|
175 | #------------------------------------------------------------------------------ |
---|
176 | |
---|
177 | # Allocate space for velocity values |
---|
178 | u = numpy.zeros(len(domain)) |
---|
179 | v = numpy.zeros(len(domain)) |
---|
180 | |
---|
181 | t0 = time.time() |
---|
182 | for t in domain.evolve(yieldstep = timestep, finaltime = simulation_length): |
---|
183 | print domain.timestepping_statistics() |
---|
184 | |
---|
185 | S = domain.get_quantity('stage').get_values(location='centroids') |
---|
186 | E = domain.get_quantity('elevation').get_values(location='centroids') |
---|
187 | depth = S-E |
---|
188 | |
---|
189 | uh = domain.get_quantity('xmomentum').get_values(location='centroids') |
---|
190 | vh = domain.get_quantity('ymomentum').get_values(location='centroids') |
---|
191 | u += uh/depth |
---|
192 | v += vh/depth |
---|
193 | |
---|
194 | |
---|
195 | #------------------------------------------------------------------------------ |
---|
196 | # Post processing |
---|
197 | #------------------------------------------------------------------------------ |
---|
198 | |
---|
199 | n_time_intervals = simulation_length/timestep |
---|
200 | print 'There were %i time steps' % n_time_intervals |
---|
201 | |
---|
202 | nodes = domain.get_nodes() |
---|
203 | |
---|
204 | X = nodes[:,0] |
---|
205 | Y = nodes[:,1] |
---|
206 | U = u/n_time_intervals |
---|
207 | V = v/n_time_intervals |
---|
208 | |
---|
209 | print 'Computation took %.2f seconds' % (time.time()-t0) |
---|
210 | |
---|
211 | key_auto_length = (max(V))/5 # Make the key vector a sensible length not |
---|
212 | # sure how to label it with the correct value |
---|
213 | # though |
---|
214 | |
---|
215 | |
---|
216 | figure() |
---|
217 | Q = quiver(X,Y,U,V) |
---|
218 | qk = quiverkey(Q, 0.8, 0.05, key_auto_length, r'$unknown \frac{m}{s}$', |
---|
219 | labelpos='E', # Need to get the label to show the value of key_auto_length |
---|
220 | coordinates='figure', |
---|
221 | fontproperties={'weight': 'bold'}) |
---|
222 | |
---|
223 | axis([-10,length + 10, -10, width +10]) |
---|
224 | title('Simulation of a Rip-Current, Average Velocity Vector Field') |
---|
225 | |
---|
226 | axhline(y=25,color='b') |
---|
227 | axhline(y=(location_of_shore),color='r') |
---|
228 | |
---|
229 | x1 = numpy.arange(0,55,1) |
---|
230 | y1 = -(bank_slope)*x1 + 112 |
---|
231 | y12 = -(bank_slope)*x1 + 124 |
---|
232 | |
---|
233 | x2 = numpy.arange(65,length,1) |
---|
234 | y2 = -(bank_slope)*x2 + 112 |
---|
235 | y22 = -(bank_slope)*x2 + 124 |
---|
236 | |
---|
237 | plot(x1,y1,x1,y12,x2,y2,x2,y22,color='g') |
---|
238 | show() |
---|
239 | |
---|
240 | |
---|