1 | """Simulation of the nonsymmetrical dam dreak problem. |
---|
2 | |
---|
3 | Copyright 2005 |
---|
4 | Christopher Zoppou, Stephen Roberts |
---|
5 | Australian National University |
---|
6 | |
---|
7 | """ |
---|
8 | |
---|
9 | #--------------------------------------- |
---|
10 | # Setup Path and import modules |
---|
11 | import sys |
---|
12 | from os import sep, path |
---|
13 | sys.path.append('..'+sep+'pyvolution') |
---|
14 | |
---|
15 | from shallow_water import Domain, Transmissive_boundary, Reflective_boundary,\ |
---|
16 | Dirichlet_boundary |
---|
17 | #from pmesh2domain import pmesh_to_domain_instance |
---|
18 | from anuga.pyvolution.util import Polygon_function |
---|
19 | from mesh_factory import rectangular_cross |
---|
20 | |
---|
21 | |
---|
22 | def cut_out_region(domain): |
---|
23 | """ |
---|
24 | To do: make better comments! |
---|
25 | Deal with passing the boundary info as well |
---|
26 | """ |
---|
27 | |
---|
28 | points = domain.coordinates |
---|
29 | elements = domain.triangles |
---|
30 | boundary = domain.boundary |
---|
31 | centroid_coordinates = domain.centroid_coordinates |
---|
32 | N = domain.number_of_elements |
---|
33 | |
---|
34 | elements_in = [] |
---|
35 | elements_out = [] |
---|
36 | for i in range(N): |
---|
37 | element = elements[i] |
---|
38 | #print element |
---|
39 | [x,y] = centroid_coordinates[i] |
---|
40 | #print x,y |
---|
41 | if x>10 and y>10: |
---|
42 | #print i,'Out region' |
---|
43 | elements_out.append(i) |
---|
44 | else: |
---|
45 | #print i,'In region' |
---|
46 | elements_in.append(i) |
---|
47 | |
---|
48 | #print elements_in |
---|
49 | #print elements_out |
---|
50 | |
---|
51 | points_in = {} |
---|
52 | for i in elements_in: |
---|
53 | #print i |
---|
54 | [v0,v1,v2] = elements[i] |
---|
55 | #print v0,v1,v2 |
---|
56 | points_in[v0] = v0 |
---|
57 | points_in[v1] = v1 |
---|
58 | points_in[v2] = v2 |
---|
59 | |
---|
60 | |
---|
61 | new_index = [] |
---|
62 | for i,value in enumerate(points_in): |
---|
63 | #print i , value |
---|
64 | points_in[value] = i |
---|
65 | |
---|
66 | |
---|
67 | #print points_in |
---|
68 | new_elements = [] |
---|
69 | for i in elements_in: |
---|
70 | #print i |
---|
71 | [v0,v1,v2] = elements[i] |
---|
72 | #print v0,v1,v2 |
---|
73 | |
---|
74 | nv0 = points_in[v0] |
---|
75 | nv1 = points_in[v1] |
---|
76 | nv2 = points_in[v2] |
---|
77 | |
---|
78 | new_elements.append([nv0,nv1,nv2]) |
---|
79 | |
---|
80 | new_points = [] |
---|
81 | for key,value in points_in.iteritems(): |
---|
82 | [x,y] = points[key] |
---|
83 | new_points.append([x,y]) |
---|
84 | |
---|
85 | #print new_points |
---|
86 | |
---|
87 | return new_points, new_elements |
---|
88 | |
---|
89 | |
---|
90 | |
---|
91 | |
---|
92 | |
---|
93 | |
---|
94 | |
---|
95 | #--------------------------------------- |
---|
96 | # Boundary conditions |
---|
97 | h0 = 1.0 |
---|
98 | h1 = 10.0 |
---|
99 | print 'Boundary conditions' |
---|
100 | |
---|
101 | #--------------------------------------- |
---|
102 | # Domain |
---|
103 | n = 100 |
---|
104 | m = 100 |
---|
105 | lenx = 20.0 |
---|
106 | leny = 20.0 |
---|
107 | delta_x = lenx/n |
---|
108 | delta_y = leny/m |
---|
109 | origin = (0.0, 0.0) |
---|
110 | |
---|
111 | points, elements, boundary = rectangular_cross(m, n, lenx, leny, origin) |
---|
112 | domain = Domain(points, elements, boundary) |
---|
113 | |
---|
114 | new_points, new_elements = cut_out_region(domain) |
---|
115 | domain = Domain(new_points, new_elements) |
---|
116 | |
---|
117 | |
---|
118 | R = Reflective_boundary(domain) |
---|
119 | T = Transmissive_boundary(domain) |
---|
120 | D = Dirichlet_boundary([h1, 0.0, 0.0]) |
---|
121 | domain.set_boundary({'exterior': R}) |
---|
122 | |
---|
123 | |
---|
124 | |
---|
125 | |
---|
126 | |
---|
127 | |
---|
128 | |
---|
129 | print "Number of triangles = ", len(domain) |
---|
130 | |
---|
131 | |
---|
132 | #--------------------------------------- |
---|
133 | #Initial condition |
---|
134 | p0 = [[0.0, 0.0], [10.0, 0.0], [10.0, 20.0], [0.0, 20.0]] |
---|
135 | domain.set_quantity('stage',Polygon_function([(p0,h1)],default = h0)) |
---|
136 | |
---|
137 | |
---|
138 | #--------------------------------------- |
---|
139 | # Provide file name for storing output |
---|
140 | domain.store = True |
---|
141 | domain.format = 'sww' |
---|
142 | domain.set_name('Non_symetrical_Dam_Break_second_order') |
---|
143 | |
---|
144 | |
---|
145 | # Visualization smoothing |
---|
146 | domain.visualise=True |
---|
147 | |
---|
148 | #--------------------------------------- |
---|
149 | #Decide which quantities are to be stored at each timestep |
---|
150 | domain.quantities_to_be_stored = ['stage', 'xmomentum', 'ymomentum'] |
---|
151 | |
---|
152 | |
---|
153 | #--------------------------------------- |
---|
154 | # Set bed elevation |
---|
155 | def x_slope(x,y): |
---|
156 | n = x.shape[0] |
---|
157 | z = 0*x |
---|
158 | return z |
---|
159 | domain.set_quantity('elevation', x_slope) |
---|
160 | |
---|
161 | |
---|
162 | #---------------------------- |
---|
163 | # Friction |
---|
164 | domain.set_quantity('friction', 0.0) |
---|
165 | |
---|
166 | |
---|
167 | #-------------------------------------- |
---|
168 | # Evolution |
---|
169 | |
---|
170 | yieldstep = 0.1 |
---|
171 | finaltime = 15.0 |
---|
172 | |
---|
173 | domain.CFL = 0.75 |
---|
174 | |
---|
175 | domain.default_order = 1 |
---|
176 | domain.smooth = True |
---|
177 | |
---|
178 | import time |
---|
179 | t0 = time.time() |
---|
180 | for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): |
---|
181 | domain.write_time() |
---|
182 | |
---|
183 | print 'That took %.2f seconds' %(time.time()-t0) |
---|