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 | import anuga_1d.sqpipe.sqpipe_domain as dom |
---|
9 | |
---|
10 | #=============================================================================== |
---|
11 | # setup problem |
---|
12 | #=============================================================================== |
---|
13 | |
---|
14 | L_x = 50.0 ## length of channel |
---|
15 | |
---|
16 | def elevation(x): |
---|
17 | z = -x*0.1 |
---|
18 | return z |
---|
19 | |
---|
20 | def stage(x): |
---|
21 | |
---|
22 | w = elevation(x) + 1.0 |
---|
23 | |
---|
24 | return w |
---|
25 | |
---|
26 | |
---|
27 | def height(x): |
---|
28 | |
---|
29 | h = stage(x) - elevation(x) |
---|
30 | |
---|
31 | return h |
---|
32 | |
---|
33 | def width(x): |
---|
34 | return numpy.ones_like(x) |
---|
35 | |
---|
36 | def top(x): |
---|
37 | |
---|
38 | t = numpy.ones_like(x)*4 |
---|
39 | |
---|
40 | t = numpy.where(x<-40, 20, t) |
---|
41 | t = numpy.where(x>40, 20, t) |
---|
42 | return t |
---|
43 | |
---|
44 | def area(x): |
---|
45 | return height(x)*width(x) |
---|
46 | |
---|
47 | def friction(x): |
---|
48 | return numpy.ones_like(x)*0.01 |
---|
49 | |
---|
50 | |
---|
51 | #=============================================================================== |
---|
52 | |
---|
53 | def get_domain(): |
---|
54 | N = 20 |
---|
55 | print "Evaluating domain with %d cells" %N |
---|
56 | |
---|
57 | points, boundary = uniform_mesh(N, x_0 = -L_x, x_1 = L_x) |
---|
58 | |
---|
59 | domain = dom.Domain(points, boundary, bulk_modulus = 100.0) |
---|
60 | |
---|
61 | domain.set_spatial_order(2) |
---|
62 | domain.set_timestepping_method('rk2') |
---|
63 | domain.set_CFL(0.5) |
---|
64 | domain.set_limiter("vanleer") |
---|
65 | |
---|
66 | domain.set_beta(1.0) |
---|
67 | |
---|
68 | domain.set_quantity('area', area) |
---|
69 | domain.set_quantity('stage', stage) |
---|
70 | domain.set_quantity('elevation',elevation) |
---|
71 | domain.set_quantity('width',width) |
---|
72 | domain.set_quantity('top',top) |
---|
73 | domain.set_quantity('friction',friction) |
---|
74 | |
---|
75 | Br = dom.Reflective_boundary(domain) |
---|
76 | Bt = dom.Transmissive_boundary(domain) |
---|
77 | |
---|
78 | domain.set_boundary({'left': Br, 'right' : Br}) |
---|
79 | |
---|
80 | return domain |
---|
81 | |
---|
82 | def animate_domain(domain, yieldstep, finaltime): |
---|
83 | import pylab |
---|
84 | |
---|
85 | pylab.ion() |
---|
86 | |
---|
87 | x, z, w, h, v, t, s, m, M = get_quantities(domain) |
---|
88 | |
---|
89 | zplot, wplot, ztplot, hplot, tplot, vplot, splot, Mplot, mplot = make_plots(x, z, w, h, v, t, s, m, M) |
---|
90 | |
---|
91 | for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): |
---|
92 | |
---|
93 | domain.write_time() |
---|
94 | x, z, w, h, v, t, s, m, M = get_quantities(domain) |
---|
95 | |
---|
96 | zplot.set_ydata(z) |
---|
97 | ztplot.set_ydata(z+t) |
---|
98 | wplot.set_ydata(w) |
---|
99 | hplot.set_ydata(h) |
---|
100 | tplot.set_ydata(t) |
---|
101 | vplot.set_ydata(v) |
---|
102 | splot.set_ydata(s) |
---|
103 | mplot.set_ydata(m) |
---|
104 | Mplot.set_ydata(M) |
---|
105 | |
---|
106 | |
---|
107 | pylab.ion() |
---|
108 | pylab.draw() |
---|
109 | |
---|
110 | |
---|
111 | |
---|
112 | |
---|
113 | def plot_domain(domain): |
---|
114 | import pylab |
---|
115 | |
---|
116 | x, z, w, h, v, t, s, m, M = get_quantities(domain) |
---|
117 | |
---|
118 | pylab.ioff() |
---|
119 | pylab.hold(False) |
---|
120 | |
---|
121 | make_plots(x, z, w, h, v, t, s, m, M) |
---|
122 | |
---|
123 | pylab.show() |
---|
124 | |
---|
125 | def write_domain(domain, outfile): |
---|
126 | x = domain.get_centroids() |
---|
127 | z = domain.get_quantity('elevation', 'centroids') |
---|
128 | w = domain.get_quantity('stage', 'centroids') |
---|
129 | |
---|
130 | f = open(outfile, 'w') |
---|
131 | for i in range(len(x)): |
---|
132 | f.write("%s %s %s\n" % (x[i], z[i], w[i])) |
---|
133 | f.close() |
---|
134 | |
---|
135 | def get_quantities(domain): |
---|
136 | x = domain.get_centroids() |
---|
137 | z = domain.get_quantity('elevation', 'centroids') |
---|
138 | w = domain.get_quantity('stage', 'centroids') |
---|
139 | h = domain.get_quantity('height', 'centroids') |
---|
140 | v = domain.get_quantity('velocity', 'centroids') |
---|
141 | t = domain.get_quantity('top', 'centroids') |
---|
142 | s = domain.state |
---|
143 | m = domain.get_mass() |
---|
144 | M = m.sum() * numpy.ones_like(x) |
---|
145 | |
---|
146 | return x, z, w, h, v, t, s, m, M |
---|
147 | |
---|
148 | def make_plots(x, z, w, h, v, t, s, m, M): |
---|
149 | import pylab |
---|
150 | |
---|
151 | #fig = pylab.gcf() |
---|
152 | #fig.set_size_inches(12,12, forward=True) |
---|
153 | |
---|
154 | |
---|
155 | |
---|
156 | |
---|
157 | plot1 = pylab.subplot(321) |
---|
158 | zplot, = pylab.plot(x, z) |
---|
159 | wplot, = pylab.plot(x, w) |
---|
160 | ztplot, = pylab.plot(x, z+t) |
---|
161 | plot1.set_xlim([-60,60]) |
---|
162 | plot1.set_ylim([-10,10]) |
---|
163 | pylab.xlabel('Position') |
---|
164 | pylab.ylabel('Stage') |
---|
165 | |
---|
166 | plot2 = pylab.subplot(322) |
---|
167 | hplot, = pylab.plot(x, h) |
---|
168 | tplot, = pylab.plot(x, t) |
---|
169 | plot2.set_xlim([-60,60]) |
---|
170 | plot2.set_ylim([-1,5]) |
---|
171 | pylab.xlabel('Position') |
---|
172 | pylab.ylabel('Height') |
---|
173 | |
---|
174 | plot3 = pylab.subplot(323) |
---|
175 | vplot, = pylab.plot(x, v) |
---|
176 | plot3.set_xlim([-60,60]) |
---|
177 | plot3.set_ylim([-6,6]) |
---|
178 | pylab.xlabel('Position') |
---|
179 | pylab.ylabel('Velocity') |
---|
180 | |
---|
181 | plot4 = pylab.subplot(324) |
---|
182 | splot, = pylab.plot(x, s) |
---|
183 | plot4.set_xlim([-60,60]) |
---|
184 | plot4.set_ylim([-1,2]) |
---|
185 | pylab.xlabel('Position') |
---|
186 | pylab.ylabel('State') |
---|
187 | |
---|
188 | plot5 = pylab.subplot(325) |
---|
189 | mplot, = pylab.plot(x, m) |
---|
190 | plot5.set_xlim([-60,60]) |
---|
191 | plot5.set_ylim([-1,10]) |
---|
192 | pylab.xlabel('Position') |
---|
193 | pylab.ylabel('Mass') |
---|
194 | |
---|
195 | plot6 = pylab.subplot(326) |
---|
196 | Mplot, = pylab.plot(x, M) |
---|
197 | plot6.set_xlim([-60,60]) |
---|
198 | plot6.set_ylim([-1,450]) |
---|
199 | pylab.xlabel('Position') |
---|
200 | pylab.ylabel('Total Mass') |
---|
201 | |
---|
202 | |
---|
203 | |
---|
204 | |
---|
205 | return zplot, wplot, ztplot, hplot, tplot, vplot, splot, Mplot, mplot |
---|