1 | import os |
---|
2 | import random |
---|
3 | from math import sqrt, pow, pi |
---|
4 | from channel_domain import * |
---|
5 | from numpy import allclose, array, zeros, ones, take, sqrt |
---|
6 | from anuga_1d.config import g, epsilon |
---|
7 | |
---|
8 | from anuga_1d.base.generic_mesh import uniform_mesh |
---|
9 | |
---|
10 | |
---|
11 | print "varying width to mimic rotationally symmetric dam break" |
---|
12 | |
---|
13 | # Define functions for initial quantities |
---|
14 | |
---|
15 | |
---|
16 | |
---|
17 | def initialize_plotting(domain, style = '-k', |
---|
18 | stage_lim = [-1.0, 40.0], |
---|
19 | velocity_lim = [-5.0, 5.0]): |
---|
20 | |
---|
21 | import pylab |
---|
22 | pylab.ion() |
---|
23 | |
---|
24 | |
---|
25 | x = domain.get_vertices().flatten() |
---|
26 | |
---|
27 | z = domain.quantities['elevation'].vertex_values.flatten() |
---|
28 | w = domain.quantities['stage'].vertex_values.flatten() |
---|
29 | h = domain.quantities['height'].vertex_values.flatten() |
---|
30 | v = domain.quantities['velocity'].vertex_values.flatten() |
---|
31 | b = domain.quantities['width'].vertex_values.flatten() |
---|
32 | |
---|
33 | print x.shape |
---|
34 | print z.shape |
---|
35 | |
---|
36 | #------------------------------- |
---|
37 | # Top plot |
---|
38 | #------------------------------- |
---|
39 | domain.plot1 = pylab.subplot(211) |
---|
40 | |
---|
41 | domain.zplot, = pylab.plot(x, z) |
---|
42 | domain.wplot, = pylab.plot(x, w, style) |
---|
43 | |
---|
44 | domain.plot1.set_ylim(stage_lim) |
---|
45 | #pylab.xlabel('Position') |
---|
46 | pylab.ylabel('Stage') |
---|
47 | |
---|
48 | |
---|
49 | #------------------------------- |
---|
50 | # Bottom Plot |
---|
51 | #------------------------------- |
---|
52 | domain.plot3 = pylab.subplot(212) |
---|
53 | |
---|
54 | domain.vplot, = pylab.plot(x, v, style) |
---|
55 | |
---|
56 | domain.plot3.set_ylim(velocity_lim) |
---|
57 | |
---|
58 | pylab.xlabel('Position') |
---|
59 | pylab.ylabel('Velocity') |
---|
60 | |
---|
61 | |
---|
62 | def update_plotting(domain): |
---|
63 | |
---|
64 | import pylab |
---|
65 | |
---|
66 | #x = domain.get_vertices().flatten() |
---|
67 | z = domain.quantities['elevation'].vertex_values.flatten() |
---|
68 | w = domain.quantities['stage'].vertex_values.flatten() |
---|
69 | h = domain.quantities['height'].vertex_values.flatten() |
---|
70 | v = domain.quantities['velocity'].vertex_values.flatten() |
---|
71 | b = domain.quantities['width'].vertex_values.flatten() |
---|
72 | |
---|
73 | |
---|
74 | domain.zplot.set_ydata(z) |
---|
75 | domain.wplot.set_ydata(w) |
---|
76 | #domain.bplot.set_ydata(b) |
---|
77 | domain.vplot.set_ydata(v) |
---|
78 | |
---|
79 | pylab.draw() |
---|
80 | |
---|
81 | |
---|
82 | def hold_plotting(domain,save=None): |
---|
83 | |
---|
84 | update_plotting(domain) |
---|
85 | import pylab |
---|
86 | |
---|
87 | pylab.ioff() |
---|
88 | |
---|
89 | if save != None: |
---|
90 | file = save+".pdf" |
---|
91 | pylab.savefig(file) |
---|
92 | |
---|
93 | pylab.show() |
---|
94 | |
---|
95 | |
---|
96 | |
---|
97 | def finalize_plotting(domain): |
---|
98 | |
---|
99 | pass |
---|
100 | |
---|
101 | |
---|
102 | |
---|
103 | |
---|
104 | |
---|
105 | def bed(x): |
---|
106 | y = zeros(len(x),'f') |
---|
107 | return y |
---|
108 | |
---|
109 | |
---|
110 | def width(x): |
---|
111 | |
---|
112 | return x*2.0*pi |
---|
113 | |
---|
114 | |
---|
115 | |
---|
116 | def initial_area(x): |
---|
117 | |
---|
118 | a_width = width(x) |
---|
119 | |
---|
120 | y = numpy.where (x <= 50.0, 15.0*a_width, 2.0*a_width ) |
---|
121 | |
---|
122 | return y |
---|
123 | |
---|
124 | |
---|
125 | import time |
---|
126 | |
---|
127 | |
---|
128 | # Define cells for finite volume and their size |
---|
129 | N = 100 |
---|
130 | |
---|
131 | domain = Domain(*uniform_mesh(N, x_0 = 0.0, x_1 = 100.0)) |
---|
132 | |
---|
133 | |
---|
134 | # Set initial values of quantities - default to zero |
---|
135 | #domain.set_quantity('stage',6.0) |
---|
136 | domain.set_quantity('elevation',bed) |
---|
137 | domain.set_quantity('width',width) |
---|
138 | domain.set_quantity('area', initial_area) |
---|
139 | |
---|
140 | |
---|
141 | #domain.setstageflag = True |
---|
142 | # Set boundry type, order, timestepping method and limiter |
---|
143 | Br = Reflective_boundary(domain) |
---|
144 | domain.set_boundary({'left':Br, 'right':Br}) |
---|
145 | domain.order = 2 |
---|
146 | domain.set_timestepping_method('rk2') |
---|
147 | domain.set_CFL(1.0) |
---|
148 | domain.set_limiter("vanleer") |
---|
149 | |
---|
150 | |
---|
151 | #AreaC = domain.quantities['area'].centroid_values |
---|
152 | #BedC = domain.quantities['elevation'].centroid_values |
---|
153 | #WidthC = domain.quantities['width'].centroid_values |
---|
154 | ## |
---|
155 | #AreaC[:] = (8.0 - BedC)* WidthC |
---|
156 | |
---|
157 | |
---|
158 | # Start timer |
---|
159 | t0 = time.time() |
---|
160 | i=0 |
---|
161 | |
---|
162 | #print 'elevation vertex values' |
---|
163 | #print domain.quantities['elevation'].vertex_values |
---|
164 | #print 'stage vertex values' |
---|
165 | #print domain.quantities['stage'].vertex_values |
---|
166 | #print 'area vertex values' |
---|
167 | #print domain.quantities['area'].vertex_values |
---|
168 | #print 'width vertex values' |
---|
169 | #print domain.quantities['width'].vertex_values |
---|
170 | |
---|
171 | |
---|
172 | domain.distribute_to_vertices_and_edges() |
---|
173 | |
---|
174 | |
---|
175 | |
---|
176 | # Set final time and yield time for simulation |
---|
177 | finaltime = 2.0 |
---|
178 | yieldstep = 0.2 |
---|
179 | |
---|
180 | initialize_plotting(domain, style = '.k', stage_lim = [0.0, 16.0], |
---|
181 | velocity_lim = [-10.0, 10.0]) |
---|
182 | |
---|
183 | for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): |
---|
184 | domain.write_time() |
---|
185 | |
---|
186 | update_plotting(domain) |
---|
187 | |
---|
188 | #------------------------------------------------------------- |
---|
189 | # Fine grid solution |
---|
190 | #------------------------------------------------------------- |
---|
191 | |
---|
192 | domain1 = Domain(*uniform_mesh(1000, x_0 = 0.0, x_1 = 100.0)) |
---|
193 | |
---|
194 | |
---|
195 | # Set initial values of quantities - default to zero |
---|
196 | #domain.set_quantity('stage',6.0) |
---|
197 | domain1.set_quantity('elevation',bed) |
---|
198 | domain1.set_quantity('width',width) |
---|
199 | domain1.set_quantity('area', initial_area) |
---|
200 | |
---|
201 | |
---|
202 | #domain.setstageflag = True |
---|
203 | # Set boundry type, order, timestepping method and limiter |
---|
204 | Br = Reflective_boundary(domain1) |
---|
205 | domain1.set_boundary({'left':Br, 'right':Br}) |
---|
206 | domain1.order = 2 |
---|
207 | domain1.set_timestepping_method('rk2') |
---|
208 | domain1.set_CFL(1.0) |
---|
209 | domain1.set_limiter("vanleer") |
---|
210 | |
---|
211 | finaltime = 2.0 |
---|
212 | yieldstep = finaltime |
---|
213 | |
---|
214 | initialize_plotting(domain1, stage_lim = [0.0, 16.0], |
---|
215 | velocity_lim = [-10.0, 10.0]) |
---|
216 | |
---|
217 | for t in domain1.evolve(yieldstep = yieldstep, finaltime = finaltime): |
---|
218 | domain1.write_time() |
---|
219 | |
---|
220 | update_plotting(domain1) |
---|
221 | |
---|
222 | |
---|
223 | hold_plotting(domain1, save="circular_dam_break_well_balanced") |
---|
224 | |
---|
225 | |
---|
226 | |
---|
227 | |
---|