1 | """Example of shallow water wave equation. |
---|
2 | |
---|
3 | This is called Netherlands because it shows a dam with a gap in it and |
---|
4 | stylised housed behind it and below the water surface. |
---|
5 | |
---|
6 | """ |
---|
7 | |
---|
8 | #------------------------------------------------------------------------------ |
---|
9 | # Import necessary modules |
---|
10 | #------------------------------------------------------------------------------ |
---|
11 | |
---|
12 | from anuga.shallow_water import Domain |
---|
13 | from anuga.shallow_water import Reflective_boundary, Dirichlet_boundary |
---|
14 | from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross |
---|
15 | import os |
---|
16 | |
---|
17 | #from anuga.visualiser import RealtimeVisualiser |
---|
18 | #import rpdb |
---|
19 | #rpdb.set_active() |
---|
20 | |
---|
21 | |
---|
22 | #------------------------------------------------------------------------------ |
---|
23 | # Setup computational domain |
---|
24 | #------------------------------------------------------------------------------ |
---|
25 | |
---|
26 | N = 150 # size = 45000 |
---|
27 | N = 130 # size = 33800 |
---|
28 | N = 600 # Size = 720000 |
---|
29 | N = 50 |
---|
30 | |
---|
31 | points, elements, boundary = rectangular_cross(N, N) |
---|
32 | domain = Domain(points, elements, boundary, use_inscribed_circle=True) |
---|
33 | |
---|
34 | domain.check_integrity() |
---|
35 | |
---|
36 | import sys |
---|
37 | base = os.path.basename(sys.argv[0]) |
---|
38 | domain.simulation_name = 'netherlands' |
---|
39 | domain.set_name(os.path.splitext(__file__)[0]) |
---|
40 | domain.set_timestepping_method('rk2') |
---|
41 | domain.set_default_order(2) |
---|
42 | domain.set_store_vertices_uniquely(True) # Store as internally represented |
---|
43 | domain.tight_slope_limiters = True |
---|
44 | print domain.statistics() |
---|
45 | |
---|
46 | |
---|
47 | # Setup order and all the beta's for the limiters (these should become defaults |
---|
48 | |
---|
49 | #domain.beta_w = 1.0 |
---|
50 | #domain.beta_w_dry = 0.2 |
---|
51 | #domain.beta_uh = 1.0 |
---|
52 | #domain.beta_uh_dry = 0.2 |
---|
53 | #domain.beta_vh = 1.0 |
---|
54 | #domain.beta_vh_dry = 0.2 |
---|
55 | |
---|
56 | #domain.alpha_balance = 100.0 |
---|
57 | |
---|
58 | |
---|
59 | |
---|
60 | #------------------------------------------------------------------------------ |
---|
61 | # Setup initial conditions |
---|
62 | #------------------------------------------------------------------------------ |
---|
63 | |
---|
64 | class Weir: |
---|
65 | """Set a bathymetry for simple weir with a hole. |
---|
66 | x,y are assumed to be in the unit square |
---|
67 | """ |
---|
68 | |
---|
69 | def __init__(self, stage): |
---|
70 | self.inflow_stage = stage |
---|
71 | |
---|
72 | def __call__(self, x, y): |
---|
73 | from Numeric import zeros, Float |
---|
74 | |
---|
75 | N = len(x) |
---|
76 | assert N == len(y) |
---|
77 | |
---|
78 | z = zeros(N, Float) |
---|
79 | for i in range(N): |
---|
80 | z[i] = -x[i]/20 # General slope |
---|
81 | |
---|
82 | # Flattish bit to the left |
---|
83 | if x[i] <= 0.3: |
---|
84 | #z[i] = -x[i]/5 |
---|
85 | z[i] = -x[i]/20 |
---|
86 | |
---|
87 | |
---|
88 | # Weir |
---|
89 | if x[i] > 0.3 and x[i] < 0.4: |
---|
90 | z[i] = -x[i]/20+1.2 |
---|
91 | |
---|
92 | # Dip |
---|
93 | #if x[i] > 0.6 and x[i] < 0.9: |
---|
94 | # z[i] = -x[i]/20-0.5 #-y[i]/5 |
---|
95 | |
---|
96 | # Hole in weir |
---|
97 | #if x[i] > 0.3 and x[i] < 0.4 and y[i] > 0.2 and y[i] < 0.4: |
---|
98 | if x[i] > 0.3 and x[i] < 0.4 and y[i] > 0.4 and y[i] < 0.6: |
---|
99 | #z[i] = -x[i]/5 |
---|
100 | z[i] = -x[i]/20 |
---|
101 | |
---|
102 | # Poles |
---|
103 | #if x[i] > 0.65 and x[i] < 0.8 and y[i] > 0.55 and y[i] < 0.65 or\ |
---|
104 | # x[i] > 0.75 and x[i] < 0.9 and y[i] > 0.35 and y[i] < 0.45: |
---|
105 | # z[i] = -x[i]/20+0.4 |
---|
106 | |
---|
107 | if (x[i] - 0.72)**2 + (y[i] - 0.6)**2 < 0.05**2:# or\ |
---|
108 | #x[i] > 0.75 and x[i] < 0.9 and y[i] > 0.35 and y[i] < 0.45: |
---|
109 | z[i] = -x[i]/20+0.4 |
---|
110 | |
---|
111 | |
---|
112 | # Wall |
---|
113 | if x[i] > 0.995: |
---|
114 | z[i] = -x[i]/20+0.3 |
---|
115 | |
---|
116 | return z/2 |
---|
117 | |
---|
118 | |
---|
119 | inflow_stage = 0.5 |
---|
120 | manning = 0.0 |
---|
121 | |
---|
122 | domain.set_quantity('elevation', Weir(inflow_stage)) |
---|
123 | domain.set_quantity('friction', manning) |
---|
124 | domain.set_quantity('stage', expression='elevation + 0.0') |
---|
125 | |
---|
126 | |
---|
127 | #------------------------------------------------------------------------------ |
---|
128 | # Setup boundary conditions |
---|
129 | #------------------------------------------------------------------------------ |
---|
130 | |
---|
131 | Br = Reflective_boundary(domain) |
---|
132 | Bd = Dirichlet_boundary([inflow_stage, 0.0, 0.0]) # Constant inflow |
---|
133 | domain.set_boundary({'left': Bd, 'right': Br, 'bottom': Br, 'top': Br}) |
---|
134 | |
---|
135 | #------------------------------------------------------------------------------- |
---|
136 | # Copy scripts to time stamped output directory and capture screen |
---|
137 | # output to file |
---|
138 | #------------------------------------------------------------------------------- |
---|
139 | time = strftime('%Y%m%d_%H%M%S',localtime()) |
---|
140 | |
---|
141 | output_dir = 'dam_break_'+time |
---|
142 | output_file = 'dam_break' |
---|
143 | |
---|
144 | copy_code_files(output_dir,__file__) |
---|
145 | #start_screen_catcher(output_dir+'_') |
---|
146 | |
---|
147 | |
---|
148 | #------------------------------------------------------------------------------ |
---|
149 | # Evolve system through time |
---|
150 | #------------------------------------------------------------------------------ |
---|
151 | |
---|
152 | |
---|
153 | if N <= 150: |
---|
154 | # Initialise real-time visualiser |
---|
155 | |
---|
156 | #pass |
---|
157 | visualise = True |
---|
158 | if visualise: |
---|
159 | from anuga.visualiser import RealtimeVisualiser |
---|
160 | vis = RealtimeVisualiser(domain) |
---|
161 | vis.render_quantity_height("elevation", offset=0.01, dynamic=False) |
---|
162 | vis.render_quantity_height("stage", dynamic=True) |
---|
163 | vis.colour_height_quantity('stage', (0.2, 0.2, 0.8)) |
---|
164 | vis.start() |
---|
165 | import time |
---|
166 | time.sleep(2.0) |
---|
167 | |
---|
168 | |
---|
169 | |
---|
170 | |
---|
171 | |
---|
172 | import time |
---|
173 | t0 = time.time() |
---|
174 | |
---|
175 | for t in domain.evolve(yieldstep = 0.05, finaltime = 5.0): |
---|
176 | print domain.timestepping_statistics() |
---|
177 | #print domain.quantities['stage'].get_values(location='centroids', |
---|
178 | #indices=[0]) |
---|
179 | if visualise: |
---|
180 | vis.update() |
---|
181 | |
---|
182 | |
---|
183 | |
---|
184 | if visualise: vis.evolveFinished() |
---|
185 | |
---|
186 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
187 | |
---|
188 | #vis.join() |
---|