1 | import os |
---|
2 | from math import sqrt, pi, sin, cos |
---|
3 | import numpy |
---|
4 | import time |
---|
5 | |
---|
6 | from anuga_1d.config import g, epsilon |
---|
7 | from anuga_1d.base.generic_mesh import uniform_mesh |
---|
8 | |
---|
9 | #=============================================================================== |
---|
10 | # setup problem |
---|
11 | #=============================================================================== |
---|
12 | |
---|
13 | |
---|
14 | z_infty = 10.0 ## max equilibrium water depth at lowest point. |
---|
15 | L_x = 2500.0 ## width of channel |
---|
16 | A0 = 0.5*L_x ## determines amplitudes of oscillations |
---|
17 | omega = sqrt(2*g*z_infty)/L_x ## angular frequency of osccilation |
---|
18 | |
---|
19 | def analytic_canal(x,t): |
---|
20 | u = numpy.zeros_like(x) ## water velocity |
---|
21 | h = numpy.zeros_like(x) ## water depth |
---|
22 | |
---|
23 | ## Define Basin Bathymetry |
---|
24 | z = numpy.zeros_like(x) ## elevation of basin |
---|
25 | w = numpy.zeros_like(x) ## elevation of water surface |
---|
26 | |
---|
27 | z[:] = z_infty*(x**2/L_x**2) |
---|
28 | u[:] = -A0*omega*sin(omega*t) |
---|
29 | w[:] = numpy.maximum(z_infty+2*A0*z_infty/L_x*cos(omega*t)*(x/L_x-0.5*A0/(L_x)*cos(omega*t)),z) |
---|
30 | h[:] = numpy.maximum(w-z, 0.0) |
---|
31 | |
---|
32 | T = 2.0*pi/omega |
---|
33 | |
---|
34 | return u,h,w,z, T |
---|
35 | |
---|
36 | |
---|
37 | def stage(x): |
---|
38 | t=0.0 |
---|
39 | u,h,w,z,T = analytic_canal(x,t) |
---|
40 | |
---|
41 | return w |
---|
42 | |
---|
43 | def elevation(x): |
---|
44 | t=0.0 |
---|
45 | u,h,w,z,T = analytic_canal(x,t) |
---|
46 | |
---|
47 | return z |
---|
48 | |
---|
49 | |
---|
50 | def height(x): |
---|
51 | t=0.0 |
---|
52 | u,h,w,z,T = analytic_canal(x,t) |
---|
53 | |
---|
54 | return h |
---|
55 | |
---|
56 | def width(x): |
---|
57 | return numpy.ones_like(x) |
---|
58 | |
---|
59 | def top(x): |
---|
60 | return 4.0 * numpy.ones_like(x) |
---|
61 | |
---|
62 | def area(x): |
---|
63 | return height(x)*width(x) |
---|
64 | |
---|
65 | |
---|
66 | #=============================================================================== |
---|
67 | |
---|
68 | def get_domain(dom): |
---|
69 | N = 100 |
---|
70 | print "Evaluating domain with %d cells" %N |
---|
71 | domain = dom.Domain(*uniform_mesh(N, x_0 = -2.0*L_x, x_1 = 2.0*L_x), bulk_modulus = 75.0) |
---|
72 | |
---|
73 | domain.set_spatial_order(2) |
---|
74 | domain.set_timestepping_method('rk2') |
---|
75 | domain.set_CFL(1.0) |
---|
76 | domain.set_limiter("vanleer") |
---|
77 | |
---|
78 | domain.set_beta(1.0) |
---|
79 | |
---|
80 | domain.set_quantity('area', area) |
---|
81 | domain.set_quantity('stage', stage) |
---|
82 | domain.set_quantity('elevation',elevation) |
---|
83 | domain.set_quantity('width',width) |
---|
84 | domain.set_quantity('top',top) |
---|
85 | |
---|
86 | Br = dom.Reflective_boundary(domain) |
---|
87 | |
---|
88 | domain.set_boundary({'left': Br, 'right' : Br}) |
---|
89 | |
---|
90 | return domain |
---|
91 | |
---|
92 | def animate_domain(domain, yieldstep, finaltime): |
---|
93 | import pylab |
---|
94 | pylab.ion() |
---|
95 | |
---|
96 | x = domain.get_centroids() |
---|
97 | z = domain.get_quantity('elevation', 'centroids') |
---|
98 | w = domain.get_quantity('stage', 'centroids') |
---|
99 | h = domain.get_quantity('height', 'centroids') |
---|
100 | v = domain.get_quantity('velocity', 'centroids') |
---|
101 | t = domain.get_quantity('top', 'centroids') |
---|
102 | |
---|
103 | plot1 = pylab.subplot(311) |
---|
104 | |
---|
105 | zplot, = pylab.plot(x, z) |
---|
106 | wplot, = pylab.plot(x, w) |
---|
107 | ztplot, = pylab.plot(x, z+t) |
---|
108 | |
---|
109 | plot1.set_ylim([-1,50]) |
---|
110 | pylab.xlabel('Position') |
---|
111 | pylab.ylabel('Stage') |
---|
112 | |
---|
113 | plot2 = pylab.subplot(312) |
---|
114 | |
---|
115 | hplot, = pylab.plot(x, h) |
---|
116 | tplot, = pylab.plot(x, t) |
---|
117 | |
---|
118 | plot2.set_ylim([-1,10]) |
---|
119 | pylab.xlabel('Position') |
---|
120 | pylab.ylabel('Height') |
---|
121 | |
---|
122 | plot3 = pylab.subplot(313) |
---|
123 | |
---|
124 | vplot, = pylab.plot(x, v) |
---|
125 | |
---|
126 | plot3.set_ylim([-15,15]) |
---|
127 | pylab.xlabel('Position') |
---|
128 | pylab.ylabel('Velocity') |
---|
129 | |
---|
130 | for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): |
---|
131 | z = domain.get_quantity('elevation', 'centroids') |
---|
132 | w = domain.get_quantity('stage', 'centroids') |
---|
133 | h = domain.get_quantity('height', 'centroids') |
---|
134 | t = domain.get_quantity('top', 'centroids') |
---|
135 | v = domain.get_quantity('velocity', 'centroids') |
---|
136 | |
---|
137 | zplot.set_ydata(z) |
---|
138 | ztplot.set_ydata(z+t) |
---|
139 | wplot.set_ydata(w) |
---|
140 | hplot.set_ydata(h) |
---|
141 | tplot.set_ydata(t) |
---|
142 | vplot.set_ydata(v) |
---|
143 | |
---|
144 | pylab.draw() |
---|
145 | |
---|
146 | |
---|
147 | |
---|
148 | def plot_domain(domain): |
---|
149 | import pylab |
---|
150 | |
---|
151 | x = domain.get_centroids() |
---|
152 | z = domain.get_quantity('elevation', 'centroids') |
---|
153 | w = domain.get_quantity('stage', 'centroids') |
---|
154 | h = domain.get_quantity('height', 'centroids') |
---|
155 | t = domain.get_quantity('top', 'centroids') |
---|
156 | u = domain.get_quantity('velocity', 'centroids') |
---|
157 | |
---|
158 | pylab.ioff() |
---|
159 | pylab.hold(False) |
---|
160 | |
---|
161 | plot1 = pylab.subplot(311) |
---|
162 | pylab.plot(x, z, x, w, x, z+t) |
---|
163 | plot1.set_ylim([-1,40]) |
---|
164 | pylab.xlabel('Position') |
---|
165 | pylab.ylabel('Stage') |
---|
166 | |
---|
167 | plot2 = pylab.subplot(312) |
---|
168 | pylab.plot(x, h, x, t) |
---|
169 | plot2.set_ylim([-1,10]) |
---|
170 | pylab.xlabel('Position') |
---|
171 | pylab.ylabel('Height') |
---|
172 | |
---|
173 | plot3 = pylab.subplot(313) |
---|
174 | pylab.plot(x, u) |
---|
175 | plot3.set_ylim([-15,15]) |
---|
176 | pylab.xlabel('Position') |
---|
177 | pylab.ylabel('Velocity') |
---|
178 | |
---|
179 | pylab.show() |
---|
180 | |
---|
181 | def write_domain(domain, outfile): |
---|
182 | x = domain.get_centroids() |
---|
183 | z = domain.get_quantity('elevation', 'centroids') |
---|
184 | w = domain.get_quantity('stage', 'centroids') |
---|
185 | |
---|
186 | f = open(outfile, 'w') |
---|
187 | for i in range(len(x)): |
---|
188 | f.write("%s %s %s\n" % (x[i], z[i], w[i])) |
---|
189 | f.close() |
---|