1 | """Example of shallow water wave equation analytical solution of the |
---|
2 | one-dimensional Carrier and Greenspan wave run-up treated as a two-dimensional solution. |
---|
3 | |
---|
4 | Copyright 2004 |
---|
5 | Christopher Zoppou, Stephen Roberts, Ole Nielsen, Duncan Gray |
---|
6 | Geoscience Australia |
---|
7 | |
---|
8 | Modified by Sudi Mungkasi, ANU, 2011 |
---|
9 | |
---|
10 | Specific methods pertaining to the 2D shallow water equation |
---|
11 | are imported from shallow_water |
---|
12 | for use with the generic finite volume framework |
---|
13 | |
---|
14 | Conserved quantities are h, uh and vh stored as elements 0, 1 and 2 in the |
---|
15 | numerical vector named conserved_quantities. |
---|
16 | """ |
---|
17 | |
---|
18 | #------------------- |
---|
19 | # Module imports |
---|
20 | import sys |
---|
21 | import anuga |
---|
22 | from math import sqrt, cos, sin, pi |
---|
23 | from numpy import asarray |
---|
24 | from time import localtime, strftime, gmtime |
---|
25 | |
---|
26 | #------------------------------------------------------------------------------- |
---|
27 | # Copy scripts to time stamped output directory and capture screen |
---|
28 | # output to file |
---|
29 | #------------------------------------------------------------------------------- |
---|
30 | time = strftime('%Y%m%d_%H%M%S',localtime()) |
---|
31 | |
---|
32 | output_dir = 'transient_carrier_greenspan_'+time |
---|
33 | output_file = 'transient_carrier_greenspan' |
---|
34 | |
---|
35 | #anuga.copy_code_files(output_dir,__file__) |
---|
36 | #start_screen_catcher(output_dir+'_') |
---|
37 | |
---|
38 | |
---|
39 | #------------------- |
---|
40 | #Convenience functions |
---|
41 | #------------------- |
---|
42 | def imag(a): |
---|
43 | return a.imag |
---|
44 | |
---|
45 | def real(a): |
---|
46 | return a.real |
---|
47 | |
---|
48 | |
---|
49 | #------------------------------------------------------------------------------ |
---|
50 | # Setup domain |
---|
51 | #------------------------------------------------------------------------------ |
---|
52 | dx = 10. |
---|
53 | dy = dx |
---|
54 | L = 100. |
---|
55 | W = 10*dx |
---|
56 | |
---|
57 | # structured mesh |
---|
58 | points, vertices, boundary = anuga.rectangular_cross(int(L/dx), int(W/dy), L, W, (0.0, -W/2)) |
---|
59 | |
---|
60 | domain = anuga.Domain(points, vertices, boundary) |
---|
61 | |
---|
62 | domain.set_name(output_file) |
---|
63 | domain.set_datadir(output_dir) |
---|
64 | |
---|
65 | #------------------------------------------------------------------------------ |
---|
66 | # Setup Algorithm |
---|
67 | #------------------------------------------------------------------------------ |
---|
68 | domain.set_default_order(2) |
---|
69 | domain.set_timestepping_method(2) |
---|
70 | domain.set_beta(0.7) |
---|
71 | domain.set_CFL(0.6) |
---|
72 | |
---|
73 | |
---|
74 | #----------------------- |
---|
75 | #Define the boundary condition |
---|
76 | #----------------------- |
---|
77 | def stage_setup(x,t): |
---|
78 | vh = 0 |
---|
79 | alpha = 0.1 |
---|
80 | eta = 0.1 |
---|
81 | a = 1.5*sqrt(1.+0.9*eta) |
---|
82 | l_0 = 200. |
---|
83 | ii = complex(0,1) |
---|
84 | g = 9.81 |
---|
85 | v_0 = sqrt(g*l_0*alpha) |
---|
86 | v1 = 0. |
---|
87 | |
---|
88 | sigma_max = 100. |
---|
89 | sigma_min = -100. |
---|
90 | for j in range (1,50): |
---|
91 | sigma0 = (sigma_max+sigma_min)/2. |
---|
92 | lambda_prime = 2./a*(t/sqrt(l_0/alpha/g)+v1) |
---|
93 | sigma_prime = sigma0/a |
---|
94 | const = (1.-ii*lambda_prime)**2+sigma_prime**2 |
---|
95 | |
---|
96 | v1 = 8.*eta/a*imag(1./const**(3./2.) \ |
---|
97 | -3./4.*(1.-ii*lambda_prime)/const**(5./2.)) |
---|
98 | |
---|
99 | x1 = -v1**2/2.-a**2*sigma_prime**2/16.+eta \ |
---|
100 | *real(1.-2.*(5./4.-ii*lambda_prime) \ |
---|
101 | /const**(3./2.)+3./2.*(1.-ii*lambda_prime)**2 \ |
---|
102 | /const**(5./2.)) |
---|
103 | |
---|
104 | neta1 = x1 + a*a*sigma_prime**2/16. |
---|
105 | |
---|
106 | v_star1 = v1*v_0 |
---|
107 | x_star1 = x1*l_0 |
---|
108 | neta_star1 = neta1*alpha*l_0 |
---|
109 | stage = neta_star1 |
---|
110 | z = stage - x_star1*alpha |
---|
111 | uh = z*v_star1 |
---|
112 | |
---|
113 | if x_star1-x > 0: |
---|
114 | sigma_max = sigma0 |
---|
115 | else: |
---|
116 | sigma_min = sigma0 |
---|
117 | |
---|
118 | if abs(abs(sigma0)-100.) < 10: |
---|
119 | #solution does not converge because bed is dry |
---|
120 | stage = 0. |
---|
121 | uh = 0. |
---|
122 | z = 0. |
---|
123 | |
---|
124 | return [stage, uh, vh] |
---|
125 | |
---|
126 | def boundary_stage(t): |
---|
127 | x = -200 |
---|
128 | return stage_setup(x,t) |
---|
129 | |
---|
130 | |
---|
131 | #------------------------------------------------------------------------------- |
---|
132 | #Initial condition |
---|
133 | #------------------------------------------------------------------------------- |
---|
134 | t_star1 = 0.0 |
---|
135 | slope = -0.1 |
---|
136 | |
---|
137 | #Set bed-elevation and friction(None) |
---|
138 | def x_slope(x,y): |
---|
139 | n = x.shape[0] |
---|
140 | z = 0*x |
---|
141 | for i in range(n): |
---|
142 | z[i] = -slope*x[i] |
---|
143 | return z |
---|
144 | domain.set_quantity('elevation', x_slope) |
---|
145 | |
---|
146 | #Set the water depth |
---|
147 | def stage(x,y): |
---|
148 | z = x_slope(x,y) |
---|
149 | n = x.shape[0] |
---|
150 | w = 0*x |
---|
151 | for i in range(n): |
---|
152 | w[i], uh, vh = stage_setup(x[i],t_star1) |
---|
153 | h = w[i] - z[i] |
---|
154 | if h < 0: |
---|
155 | h = 0 |
---|
156 | w[i] = z[i] |
---|
157 | return w |
---|
158 | domain.set_quantity('stage', stage) |
---|
159 | |
---|
160 | |
---|
161 | #----------------------------------------------------------------------------- |
---|
162 | # Setup boundary conditions |
---|
163 | #------------------------------------------------------------------------------ |
---|
164 | Br = anuga.Reflective_boundary(domain) |
---|
165 | Bt = anuga.Time_boundary(domain, boundary_stage) |
---|
166 | |
---|
167 | # Associate boundary tags with boundary objects |
---|
168 | domain.set_boundary({'left': Bt, 'right': Br, 'top': Br, 'bottom': Br}) |
---|
169 | |
---|
170 | ##visualize = True |
---|
171 | ##if visualize: |
---|
172 | ## from anuga.visualiser import RealtimeVisualiser |
---|
173 | ## vis = RealtimeVisualiser(domain) |
---|
174 | ## vis.render_quantity_height("elevation", zScale=3.0, offset = 0.01, dynamic=False) |
---|
175 | ## vis.render_quantity_height("stage", zScale = 3.0, dynamic=True, opacity = 0.6, wireframe=False) |
---|
176 | ## #vis.colour_height_quantity('stage', (lambda q:q['stage'], 1.0, 2.0)) |
---|
177 | ## vis.colour_height_quantity('stage', (0.4, 0.6, 0.4)) |
---|
178 | ## vis.start() |
---|
179 | ## time.sleep(2.0) |
---|
180 | |
---|
181 | #domain.visualise = True |
---|
182 | |
---|
183 | |
---|
184 | #------------------------------------------------------------------------------ |
---|
185 | # Evolve system through time |
---|
186 | #------------------------------------------------------------------------------ |
---|
187 | import time |
---|
188 | t0 = time.time() |
---|
189 | for t in domain.evolve(yieldstep = 1., finaltime = 1000): |
---|
190 | domain.write_time() |
---|
191 | #print boundary_stage(domain.time) |
---|
192 | #if visualize: vis.update() |
---|
193 | |
---|
194 | #if visualize: vis.evolveFinished() |
---|
195 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
196 | |
---|