1 | import os |
---|
2 | from math import sqrt, pi, sin, cos |
---|
3 | import numpy |
---|
4 | import time |
---|
5 | |
---|
6 | |
---|
7 | from anuga_1d.sww.sww_domain import * |
---|
8 | from anuga_1d.config import g, epsilon |
---|
9 | from anuga_1d.base.generic_mesh import uniform_mesh |
---|
10 | |
---|
11 | #=============================================================================== |
---|
12 | # setup problem |
---|
13 | #=============================================================================== |
---|
14 | |
---|
15 | |
---|
16 | z_infty = 10.0 ## max equilibrium water depth at lowest point. |
---|
17 | L_x = 2500.0 ## width of channel |
---|
18 | A0 = 0.5*L_x ## determines amplitudes of oscillations |
---|
19 | omega = sqrt(2*g*z_infty)/L_x ## angular frequency of osccilation |
---|
20 | |
---|
21 | def analytic_canal(x,t): |
---|
22 | u = numpy.zeros_like(x) ## water velocity |
---|
23 | h = numpy.zeros_like(x) ## water depth |
---|
24 | |
---|
25 | ## Define Basin Bathymetry |
---|
26 | z = numpy.zeros_like(x) ## elevation of basin |
---|
27 | w = numpy.zeros_like(x) ## elevation of water surface |
---|
28 | |
---|
29 | z[:] = z_infty*(x**2/L_x**2) |
---|
30 | u[:] = -A0*omega*sin(omega*t) |
---|
31 | 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) |
---|
32 | h[:] = numpy.maximum(w-z, 0.0) |
---|
33 | |
---|
34 | T = 2.0*pi/omega |
---|
35 | |
---|
36 | return u,h,w,z, T |
---|
37 | |
---|
38 | |
---|
39 | def stage(x): |
---|
40 | t=0.0 |
---|
41 | u,h,w,z,T = analytic_canal(x,t) |
---|
42 | |
---|
43 | return w |
---|
44 | |
---|
45 | def elevation(x): |
---|
46 | t=0.0 |
---|
47 | u,h,w,z,T = analytic_canal(x,t) |
---|
48 | |
---|
49 | return z |
---|
50 | |
---|
51 | |
---|
52 | def height(x): |
---|
53 | t=0.0 |
---|
54 | u,h,w,z,T = analytic_canal(x,t) |
---|
55 | |
---|
56 | return h |
---|
57 | |
---|
58 | |
---|
59 | #=============================================================================== |
---|
60 | finaltime = 500.0 |
---|
61 | yieldstep = 10.0 |
---|
62 | |
---|
63 | |
---|
64 | |
---|
65 | N = 100 |
---|
66 | print "Evaluating domain with %d cells" %N |
---|
67 | domain = Domain(*uniform_mesh(N, x_0 = -2.0*L_x, x_1 = 2.0*L_x)) |
---|
68 | |
---|
69 | domain.set_spatial_order(2) |
---|
70 | domain.set_timestepping_method('rk2') |
---|
71 | domain.set_CFL(1.0) |
---|
72 | #domain.set_limiter("minmod_kurganov") |
---|
73 | domain.set_limiter("vanleer") |
---|
74 | |
---|
75 | domain.set_beta(1.0) |
---|
76 | |
---|
77 | domain.set_quantity('stage', stage) |
---|
78 | domain.set_quantity('elevation',elevation) |
---|
79 | |
---|
80 | domain.quantities['elevation'].extrapolate_second_order() |
---|
81 | domain.quantities['stage'].extrapolate_second_order() |
---|
82 | |
---|
83 | Br = Reflective_boundary(domain) |
---|
84 | |
---|
85 | domain.set_boundary({'left': Br, 'right' : Br}) |
---|
86 | |
---|
87 | #domain.h0=0.0001 |
---|
88 | |
---|
89 | t0 = time.time() |
---|
90 | |
---|
91 | for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): |
---|
92 | domain.write_time() |
---|
93 | |
---|
94 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
95 | |
---|
96 | |
---|
97 | N = float(N) |
---|
98 | HeightC = domain.quantities['height'].centroid_values |
---|
99 | StageC = domain.quantities['stage'].centroid_values |
---|
100 | BedC = domain.quantities['elevation'].centroid_values |
---|
101 | C = domain.centroids |
---|
102 | |
---|
103 | HeightV = domain.quantities['height'].vertex_values |
---|
104 | StageV = domain.quantities['stage'].vertex_values |
---|
105 | BedV = domain.quantities['elevation'].vertex_values |
---|
106 | VelocityV = domain.quantities['velocity'].vertex_values |
---|
107 | X = domain.vertices |
---|
108 | |
---|
109 | |
---|
110 | import pylab |
---|
111 | |
---|
112 | pylab.hold(False) |
---|
113 | |
---|
114 | plot1 = pylab.subplot(311) |
---|
115 | |
---|
116 | pylab.plot(X.flat,BedV.flat,X.flat,StageV.flat) |
---|
117 | |
---|
118 | plot1.set_ylim([-1,40]) |
---|
119 | |
---|
120 | pylab.xlabel('Position') |
---|
121 | pylab.ylabel('Stage') |
---|
122 | pylab.legend(('Analytical Solution', 'Numerical Solution'), |
---|
123 | 'upper right', shadow=True) |
---|
124 | |
---|
125 | |
---|
126 | plot2 = pylab.subplot(312) |
---|
127 | |
---|
128 | pylab.plot(X.flat,HeightV.flat) |
---|
129 | |
---|
130 | plot2.set_ylim([-1,10]) |
---|
131 | |
---|
132 | pylab.xlabel('Position') |
---|
133 | pylab.ylabel('Height') |
---|
134 | |
---|
135 | plot3 = pylab.subplot(313) |
---|
136 | |
---|
137 | pylab.plot(X.flat,VelocityV.flat) |
---|
138 | plot3.set_ylim([-15,15]) |
---|
139 | |
---|
140 | pylab.xlabel('Position') |
---|
141 | pylab.ylabel('Velocity') |
---|
142 | |
---|
143 | pylab.show() |
---|
144 | |
---|
145 | |
---|
146 | |
---|
147 | |
---|
148 | |
---|
149 | |
---|