1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | import unittest |
---|
4 | import sys |
---|
5 | from math import sqrt |
---|
6 | |
---|
7 | |
---|
8 | from anuga.interface import Domain |
---|
9 | from anuga.interface import rectangular_cross |
---|
10 | |
---|
11 | from parallel_shallow_water import Parallel_Domain |
---|
12 | |
---|
13 | from anuga_parallel.pmesh_divide import pmesh_divide_metis |
---|
14 | from anuga_parallel.build_submesh import build_submesh |
---|
15 | from anuga_parallel.build_submesh import submesh_full, submesh_ghost, submesh_quantities |
---|
16 | from anuga_parallel.build_commun import extract_hostmesh, rec_submesh, send_submesh |
---|
17 | |
---|
18 | #import numpy as num |
---|
19 | import Numeric as num |
---|
20 | |
---|
21 | def topography(x,y): |
---|
22 | return -x/2 |
---|
23 | |
---|
24 | |
---|
25 | def xcoord(x,y): |
---|
26 | return x |
---|
27 | |
---|
28 | def ycoord(x,y): |
---|
29 | return y |
---|
30 | |
---|
31 | |
---|
32 | |
---|
33 | class Test_Domain(unittest.TestCase): |
---|
34 | def setUp(self): |
---|
35 | pass |
---|
36 | |
---|
37 | |
---|
38 | def tearDown(self): |
---|
39 | pass |
---|
40 | |
---|
41 | |
---|
42 | |
---|
43 | def test_pmesh_1(self): |
---|
44 | |
---|
45 | points, vertices, boundary = rectangular_cross(2,2) |
---|
46 | |
---|
47 | |
---|
48 | true_points = [[0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [0.5, 0.0], [0.5, 0.5], [0.5, 1.0], [1.0, 0.0], [1.0, 0.5], [1.0, 1.0], [0.25, 0.25], [0.25, 0.75], [0.75, 0.25], [0.75, 0.75]] |
---|
49 | |
---|
50 | true_vertices = [[0, 9, 1], [3, 9, 0], [4, 9, 3], [1, 9, 4], [1, 10, 2], [4, 10, 1], [5, 10, 4], [2, 10, 5], [3, 11, 4], [6, 11, 3], [7, 11, 6], [4, 11, 7], [4, 12, 5], [7, 12, 4], [8, 12, 7], [5, 12, 8]] |
---|
51 | |
---|
52 | |
---|
53 | assert num.allclose(points,true_points) |
---|
54 | assert num.allclose(vertices,true_vertices) |
---|
55 | |
---|
56 | domain = Domain(points, vertices, boundary) |
---|
57 | |
---|
58 | |
---|
59 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
60 | domain.set_quantity('friction', 0.0) # Constant friction |
---|
61 | domain.set_quantity('stage', expression='elevation') # Dry initial stage |
---|
62 | domain.set_quantity('xmomentum', expression='friction + 2.0') # |
---|
63 | domain.set_quantity('ymomentum', ycoord) # |
---|
64 | |
---|
65 | |
---|
66 | #print domain.quantities['ymomentum'].centroid_values |
---|
67 | |
---|
68 | nodes, triangles, boundary, triangles_per_proc, quantities = pmesh_divide_metis(domain,1) |
---|
69 | |
---|
70 | |
---|
71 | true_nodes = [[0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [0.5, 0.0], [0.5, 0.5], [0.5, 1.0], [1.0, 0.0], [1.0, 0.5], [1.0, 1.0], [0.25, 0.25], [0.25, 0.75], [0.75, 0.25], [0.75, 0.75]] |
---|
72 | |
---|
73 | true_triangles = [[0, 9, 1], [3, 9, 0], [4, 9, 3], [1, 9, 4], [1, 10, 2], [4, 10, 1], [5, 10, 4], [2, 10, 5], [3, 11, 4], [6, 11, 3], [7, 11, 6], [4, 11, 7], [4, 12, 5], [7, 12, 4], [8, 12, 7], [5, 12, 8]] |
---|
74 | |
---|
75 | |
---|
76 | assert num.allclose(nodes,true_nodes) |
---|
77 | assert num.allclose(triangles,true_triangles) |
---|
78 | |
---|
79 | |
---|
80 | assert num.allclose(triangles_per_proc,[16]) |
---|
81 | |
---|
82 | |
---|
83 | |
---|
84 | def test_pmesh_2(self): |
---|
85 | |
---|
86 | points, vertices, boundary = rectangular_cross(2,2) |
---|
87 | |
---|
88 | |
---|
89 | true_points = [[0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [0.5, 0.0], [0.5, 0.5], [0.5, 1.0], [1.0, 0.0], [1.0, 0.5], [1.0, 1.0], [0.25, 0.25], [0.25, 0.75], [0.75, 0.25], [0.75, 0.75]] |
---|
90 | |
---|
91 | true_vertices = [[0, 9, 1], [3, 9, 0], [4, 9, 3], [1, 9, 4], [1, 10, 2], [4, 10, 1], [5, 10, 4], [2, 10, 5], [3, 11, 4], [6, 11, 3], [7, 11, 6], [4, 11, 7], [4, 12, 5], [7, 12, 4], [8, 12, 7], [5, 12, 8]] |
---|
92 | |
---|
93 | |
---|
94 | assert num.allclose(points,true_points) |
---|
95 | assert num.allclose(vertices,true_vertices) |
---|
96 | |
---|
97 | domain = Domain(points, vertices, boundary) |
---|
98 | |
---|
99 | |
---|
100 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
101 | domain.set_quantity('friction', 0.0) # Constant friction |
---|
102 | domain.set_quantity('stage', expression='elevation') # Dry initial stage |
---|
103 | domain.set_quantity('xmomentum', expression='friction + 2.0') # |
---|
104 | domain.set_quantity('ymomentum', ycoord) # |
---|
105 | |
---|
106 | |
---|
107 | #print domain.quantities['ymomentum'].centroid_values |
---|
108 | |
---|
109 | nodes, triangles, boundary, triangles_per_proc, quantities = pmesh_divide_metis(domain,2) |
---|
110 | |
---|
111 | |
---|
112 | true_nodes = [[0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [0.5, 0.0], [0.5, 0.5], [0.5, 1.0], [1.0, 0.0], [1.0, 0.5], [1.0, 1.0], [0.25, 0.25], [0.25, 0.75], [0.75, 0.25], [0.75, 0.75]] |
---|
113 | |
---|
114 | |
---|
115 | true_triangles = [[0, 9, 1], [3, 9, 0], [4, 9, 3], [1, 9, 4], [4, 10, 1], [3, 11, 4], [4, 11, 7], [4, 12, 5], [1, 10, 2], [5, 10, 4], [2, 10, 5], [6, 11, 3], [7, 11, 6], [7, 12, 4], [8, 12, 7], [5, 12, 8]] |
---|
116 | |
---|
117 | |
---|
118 | assert num.allclose(nodes,true_nodes) |
---|
119 | assert num.allclose(triangles,true_triangles) |
---|
120 | |
---|
121 | |
---|
122 | assert num.allclose(triangles_per_proc,[8,8]) |
---|
123 | |
---|
124 | |
---|
125 | print triangles_per_proc |
---|
126 | |
---|
127 | |
---|
128 | def test_distibute_3(self): |
---|
129 | |
---|
130 | import pypar |
---|
131 | |
---|
132 | myid = pypar.rank() |
---|
133 | numprocs = pypar.size() |
---|
134 | |
---|
135 | assert numprocs == 3, 'Should be run on 3 processors' |
---|
136 | |
---|
137 | if myid == 0: |
---|
138 | |
---|
139 | points, vertices, boundary = rectangular_cross(2,2) |
---|
140 | |
---|
141 | domain = Domain(points, vertices, boundary) |
---|
142 | |
---|
143 | |
---|
144 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
145 | domain.set_quantity('friction', 0.0) # Constant friction |
---|
146 | domain.set_quantity('stage', expression='elevation') # Dry initial stage |
---|
147 | domain.set_quantity('xmomentum', expression='friction + 2.0') # |
---|
148 | domain.set_quantity('ymomentum', ycoord) # |
---|
149 | |
---|
150 | |
---|
151 | |
---|
152 | |
---|
153 | #---------------------------------------------------------------------------------- |
---|
154 | # Test pmesh_divide_metis |
---|
155 | #---------------------------------------------------------------------------------- |
---|
156 | nodes, triangles, boundary, triangles_per_proc, quantities = pmesh_divide_metis(domain,numprocs) |
---|
157 | |
---|
158 | |
---|
159 | assert num.allclose(nodes,points) |
---|
160 | |
---|
161 | |
---|
162 | true_vertices = [[0, 9, 1], [3, 9, 0], [4, 9, 3], [1, 9, 4], [1, 10, 2], [4, 10, 1], [5, 10, 4], [2, 10, 5], [3, 11, 4], [6, 11, 3], [7, 11, 6], [4, 11, 7], [4, 12, 5], [7, 12, 4], [8, 12, 7], [5, 12, 8]] |
---|
163 | |
---|
164 | true_triangles = [[4, 9, 3], [4, 12, 5], [7, 12, 4], [8, 12, 7], [5, 12, 8], [0, 9, 1], [1, 9, 4], [1, 10, 2], [4, 10, 1], [5, 10, 4], [2, 10, 5], [3, 9, 0], [3, 11, 4], [6, 11, 3], [7, 11, 6], [4, 11, 7]] |
---|
165 | |
---|
166 | assert num.allclose(vertices,true_vertices) |
---|
167 | assert num.allclose(triangles,true_triangles) |
---|
168 | |
---|
169 | assert num.allclose(triangles_per_proc,[5,6,5]) |
---|
170 | |
---|
171 | |
---|
172 | #---------------------------------------------------------------------------------- |
---|
173 | # Test build_submesh |
---|
174 | #---------------------------------------------------------------------------------- |
---|
175 | submesh = build_submesh(nodes, triangles, boundary, quantities, triangles_per_proc) |
---|
176 | |
---|
177 | |
---|
178 | assert num.allclose(submesh['full_nodes'][0],[[3.0, 0.5, 0.0], [4.0, 0.5, 0.5], [5.0, 0.5, 1.0], [7.0, 1.0, 0.5], [8.0, 1.0, 1.0], [9.0, 0.25, 0.25], [12.0, 0.75, 0.75]]) |
---|
179 | assert num.allclose(submesh['full_nodes'][1],[[0.0, 0.0, 0.0], [1.0, 0.0, 0.5], [2.0, 0.0, 1.0], [4.0, 0.5, 0.5], [5.0, 0.5, 1.0], [9.0, 0.25, 0.25], [10.0, 0.25, 0.75]]) |
---|
180 | assert num.allclose(submesh['full_nodes'][2],[[0.0, 0.0, 0.0], [3.0, 0.5, 0.0], [4.0, 0.5, 0.5], [6.0, 1.0, 0.0], [7.0, 1.0, 0.5], [9.0, 0.25, 0.25], [11.0, 0.75, 0.25]]) |
---|
181 | |
---|
182 | |
---|
183 | assert num.allclose(submesh['ghost_nodes'][0],[[0.0, 0.0, 0.0], [1.0, 0.0, 0.5], [2.0, 0.0, 1.0], [6.0, 1.0, 0.0], [10.0, 0.25, 0.75], [11.0, 0.75, 0.25]]) |
---|
184 | assert num.allclose(submesh['ghost_nodes'][1],[[3.0, 0.5, 0.0], [7.0, 1.0, 0.5], [8.0, 1.0, 1.0], [11.0, 0.75, 0.25], [12.0, 0.75, 0.75]]) |
---|
185 | assert num.allclose(submesh['ghost_nodes'][2],[[1.0, 0.0, 0.5], [5.0, 0.5, 1.0], [8.0, 1.0, 1.0], [12.0, 0.75, 0.75]]) |
---|
186 | |
---|
187 | |
---|
188 | |
---|
189 | true_full_triangles = [num.array([[ 4, 9, 3], |
---|
190 | [ 4, 12, 5], |
---|
191 | [ 7, 12, 4], |
---|
192 | [ 8, 12, 7], |
---|
193 | [ 5, 12, 8]]), |
---|
194 | num.array([[ 0, 9, 1], |
---|
195 | [ 1, 9, 4], |
---|
196 | [ 1, 10, 2], |
---|
197 | [ 4, 10, 1], |
---|
198 | [ 5, 10, 4], |
---|
199 | [ 2, 10, 5]]), |
---|
200 | num.array([[ 3, 9, 0], |
---|
201 | [ 3, 11, 4], |
---|
202 | [ 6, 11, 3], |
---|
203 | [ 7, 11, 6], |
---|
204 | [ 4, 11, 7]])] |
---|
205 | |
---|
206 | |
---|
207 | assert num.allclose(submesh['full_triangles'][0],true_full_triangles[0]) |
---|
208 | assert num.allclose(submesh['full_triangles'][1],true_full_triangles[1]) |
---|
209 | assert num.allclose(submesh['full_triangles'][2],true_full_triangles[2]) |
---|
210 | |
---|
211 | true_ghost_triangles = [num.array([[ 5, 0, 9, 1], |
---|
212 | [ 6, 1, 9, 4], |
---|
213 | [ 8, 4, 10, 1], |
---|
214 | [ 9, 5, 10, 4], |
---|
215 | [10, 2, 10, 5], |
---|
216 | [11, 3, 9, 0], |
---|
217 | [12, 3, 11, 4], |
---|
218 | [13, 6, 11, 3], |
---|
219 | [14, 7, 11, 6], |
---|
220 | [15, 4, 11, 7]]), |
---|
221 | num.array([[ 0, 4, 9, 3], |
---|
222 | [ 1, 4, 12, 5], |
---|
223 | [ 2, 7, 12, 4], |
---|
224 | [ 4, 5, 12, 8], |
---|
225 | [11, 3, 9, 0], |
---|
226 | [12, 3, 11, 4]]), |
---|
227 | num.array([[ 0, 4, 9, 3], |
---|
228 | [ 1, 4, 12, 5], |
---|
229 | [ 2, 7, 12, 4], |
---|
230 | [ 3, 8, 12, 7], |
---|
231 | [ 5, 0, 9, 1], |
---|
232 | [ 6, 1, 9, 4]])] |
---|
233 | |
---|
234 | |
---|
235 | |
---|
236 | assert num.allclose(submesh['ghost_triangles'][0],true_ghost_triangles[0]) |
---|
237 | assert num.allclose(submesh['ghost_triangles'][1],true_ghost_triangles[1]) |
---|
238 | assert num.allclose(submesh['ghost_triangles'][2],true_ghost_triangles[2]) |
---|
239 | |
---|
240 | true_full_commun = [{0: [1, 2], 1: [1, 2], 2: [1, 2], 3: [2], 4: [1]}, {5: [0, 2], 6: [0, 2], 7: [], 8: [0], 9: [0], 10: [0]}, {11: [0, 1], 12: [0, 1], 13: [0], 14: [0], 15: [0]}] |
---|
241 | |
---|
242 | assert true_full_commun == submesh['full_commun'] |
---|
243 | |
---|
244 | |
---|
245 | true_ghost_commun = [num.array([[ 5, 1], |
---|
246 | [ 6, 1], |
---|
247 | [ 8, 1], |
---|
248 | [ 9, 1], |
---|
249 | [10, 1], |
---|
250 | [11, 2], |
---|
251 | [12, 2], |
---|
252 | [13, 2], |
---|
253 | [14, 2], |
---|
254 | [15, 2]]), |
---|
255 | num.array([[ 0, 0], |
---|
256 | [ 1, 0], |
---|
257 | [ 2, 0], |
---|
258 | [ 4, 0], |
---|
259 | [11, 2], |
---|
260 | [12, 2]]), |
---|
261 | num.array([[0, 0], |
---|
262 | [1, 0], |
---|
263 | [2, 0], |
---|
264 | [3, 0], |
---|
265 | [5, 1], |
---|
266 | [6, 1]])] |
---|
267 | |
---|
268 | assert num.allclose(submesh['ghost_commun'][0],true_ghost_commun[0]) |
---|
269 | assert num.allclose(submesh['ghost_commun'][1],true_ghost_commun[1]) |
---|
270 | assert num.allclose(submesh['ghost_commun'][2],true_ghost_commun[2]) |
---|
271 | |
---|
272 | |
---|
273 | #---------------------------------------------------------------------------------- |
---|
274 | # Test send_submesh |
---|
275 | #---------------------------------------------------------------------------------- |
---|
276 | for p in range(1, numprocs): |
---|
277 | send_submesh(submesh, triangles_per_proc, p) |
---|
278 | |
---|
279 | #---------------------------------------------------------------------------------- |
---|
280 | # Test extract_hostmesh |
---|
281 | #---------------------------------------------------------------------------------- |
---|
282 | points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict =\ |
---|
283 | extract_hostmesh(submesh, triangles_per_proc) |
---|
284 | |
---|
285 | |
---|
286 | true_points = [[0.5, 0.0], [0.5, 0.5], [0.5, 1.0], [1.0, 0.5], [1.0, 1.0], [0.25, 0.25], [0.75, 0.75], [0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [1.0, 0.0], [0.25, 0.75], [0.75, 0.25]] |
---|
287 | |
---|
288 | true_vertices = [[1, 5, 0], [1, 6, 2], [3, 6, 1], [4, 6, 3], [2, 6, 4], [7, 5, 8], [8, 5, 1], [1, 11, 8], [2, 11, 1], [9, 11, 2], [0, 5, 7], [0, 12, 1], [10, 12, 0], [3, 12, 10], [1, 12, 3]] |
---|
289 | |
---|
290 | |
---|
291 | true_ghost_recv = {1: [num.array([5, 6, 7, 8, 9]), num.array([ 5, 6, 8, 9, 10])], 2: [num.array([10, 11, 12, 13, 14]), num.array([11, 12, 13, 14, 15])]} |
---|
292 | |
---|
293 | |
---|
294 | true_full_send = {1: [num.array([0, 1, 2, 4]), num.array([0, 1, 2, 4])], 2: [num.array([0, 1, 2, 3]), num.array([0, 1, 2, 3])]} |
---|
295 | |
---|
296 | assert num.allclose(points, true_points) |
---|
297 | assert num.allclose(vertices, true_vertices) |
---|
298 | assert num.allclose(ghost_recv_dict[1],true_ghost_recv[1]) |
---|
299 | assert num.allclose(ghost_recv_dict[2],true_ghost_recv[2]) |
---|
300 | assert num.allclose(full_send_dict[1],true_full_send[1]) |
---|
301 | assert num.allclose(full_send_dict[2],true_full_send[2]) |
---|
302 | |
---|
303 | #print triangles_per_proc |
---|
304 | |
---|
305 | else: |
---|
306 | #---------------------------------------------------------------------------------- |
---|
307 | # Test rec_submesh |
---|
308 | #---------------------------------------------------------------------------------- |
---|
309 | points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict, no_full_nodes, no_full_trigs = rec_submesh(0) |
---|
310 | |
---|
311 | if myid == 1: |
---|
312 | |
---|
313 | |
---|
314 | true_points = [[0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [0.5, 0.5], [0.5, 1.0], [0.25, 0.25], [0.25, 0.75], [0.5, 0.0], [1.0, 0.5], [1.0, 1.0], [0.75, 0.25], [0.75, 0.75]] |
---|
315 | |
---|
316 | true_vertices = [[0, 5, 1], [1, 5, 3], [1, 6, 2], [3, 6, 1], [4, 6, 3], [2, 6, 4], [3, 5, 7], [3, 11, 4], [8, 11, 3], [4, 11, 9], [7, 5, 0], [7, 10, 3]] |
---|
317 | |
---|
318 | true_ghost_recv = {0: [num.array([6, 7, 8, 9]), num.array([0, 1, 2, 4])], 2: [num.array([10, 11]), num.array([11, 12])]} |
---|
319 | |
---|
320 | true_full_send = {0: [num.array([0, 1, 3, 4, 5]), num.array([ 5, 6, 8, 9, 10])], 2: [num.array([0, 1]), num.array([5, 6])]} |
---|
321 | |
---|
322 | assert num.allclose(points, true_points) |
---|
323 | assert num.allclose(vertices, true_vertices) |
---|
324 | assert num.allclose(ghost_recv_dict[0],true_ghost_recv[0]) |
---|
325 | assert num.allclose(ghost_recv_dict[2],true_ghost_recv[2]) |
---|
326 | assert num.allclose(full_send_dict[0],true_full_send[0]) |
---|
327 | assert num.allclose(full_send_dict[2],true_full_send[2]) |
---|
328 | |
---|
329 | |
---|
330 | if myid == 2: |
---|
331 | |
---|
332 | true_points = [[0.0, 0.0], [0.5, 0.0], [0.5, 0.5], [1.0, 0.0], [1.0, 0.5], [0.25, 0.25], [0.75, 0.25], [0.0, 0.5], [0.5, 1.0], [1.0, 1.0], [0.75, 0.75]] |
---|
333 | |
---|
334 | true_vertices = [[1, 5, 0], [1, 6, 2], [3, 6, 1], [4, 6, 3], [2, 6, 4], [2, 5, 1], [2, 10, 8], [4, 10, 2], [9, 10, 4], [0, 5, 7], [7, 5, 2]] |
---|
335 | |
---|
336 | |
---|
337 | true_ghost_recv = {0: [num.array([5, 6, 7, 8]), num.array([0, 1, 2, 3])], 1: [num.array([ 9, 10]), num.array([5, 6])]} |
---|
338 | |
---|
339 | true_full_send = {0: [num.array([0, 1, 2, 3, 4]), num.array([11, 12, 13, 14, 15])], 1: [num.array([0, 1]), num.array([11, 12])]} |
---|
340 | |
---|
341 | |
---|
342 | assert num.allclose(points, true_points) |
---|
343 | assert num.allclose(vertices, true_vertices) |
---|
344 | assert num.allclose(ghost_recv_dict[0],true_ghost_recv[0]) |
---|
345 | assert num.allclose(ghost_recv_dict[1],true_ghost_recv[1]) |
---|
346 | assert num.allclose(full_send_dict[0],true_full_send[0]) |
---|
347 | assert num.allclose(full_send_dict[1],true_full_send[1]) |
---|
348 | |
---|
349 | |
---|
350 | par_domain = Parallel_Domain(points, vertices, boundary, |
---|
351 | full_send_dict = full_send_dict, |
---|
352 | ghost_recv_dict = ghost_recv_dict) |
---|
353 | |
---|
354 | |
---|
355 | |
---|
356 | |
---|
357 | |
---|
358 | |
---|
359 | |
---|
360 | |
---|
361 | def test_build_submesh_3(self): |
---|
362 | |
---|
363 | |
---|
364 | nodes = [[0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [0.5, 0.0], [0.5, 0.5], [0.5, 1.0], [1.0, 0.0], [1.0, 0.5], [1.0, 1.0], [0.25, 0.25], [0.25, 0.75], [0.75, 0.25], [0.75, 0.75]] |
---|
365 | |
---|
366 | |
---|
367 | triangles = [[4, 9, 3], [4, 12, 5], [7, 12, 4], [8, 12, 7], [5, 12, 8], [0, 9, 1], [1, 9, 4], [1, 10, 2], [4, 10, 1], [5, 10, 4], [2, 10, 5], [3, 9, 0], [3, 11, 4], [6, 11, 3], [7, 11, 6], [4, 11, 7]] |
---|
368 | |
---|
369 | |
---|
370 | edges = {(13, 1): 'bottom', (7, 1): 'left', (3, 1): 'right', (14, 1): 'right', (11, 1): 'bottom', (10, 1): 'top', (5, 1): 'left', (4, 1): 'top'} |
---|
371 | |
---|
372 | triangles_per_proc = [5, 6, 5] |
---|
373 | |
---|
374 | |
---|
375 | quantities = {'stage': num.array([[-0.25 , -0.125, -0.25 ], |
---|
376 | [-0.25 , -0.375, -0.25 ], |
---|
377 | [-0.5 , -0.375, -0.25 ], |
---|
378 | [-0.5 , -0.375, -0.5 ], |
---|
379 | [-0.25 , -0.375, -0.5 ], |
---|
380 | [-0. , -0.125, -0. ], |
---|
381 | [-0. , -0.125, -0.25 ], |
---|
382 | [-0. , -0.125, -0. ], |
---|
383 | [-0.25 , -0.125, -0. ], |
---|
384 | [-0.25 , -0.125, -0.25 ], |
---|
385 | [-0. , -0.125, -0.25 ], |
---|
386 | [-0.25 , -0.125, -0. ], |
---|
387 | [-0.25 , -0.375, -0.25 ], |
---|
388 | [-0.5 , -0.375, -0.25 ], |
---|
389 | [-0.5 , -0.375, -0.5 ], |
---|
390 | [-0.25 , -0.375, -0.5 ]]), 'elevation': num.array([[-0.25 , -0.125, -0.25 ], |
---|
391 | [-0.25 , -0.375, -0.25 ], |
---|
392 | [-0.5 , -0.375, -0.25 ], |
---|
393 | [-0.5 , -0.375, -0.5 ], |
---|
394 | [-0.25 , -0.375, -0.5 ], |
---|
395 | [-0. , -0.125, -0. ], |
---|
396 | [-0. , -0.125, -0.25 ], |
---|
397 | [-0. , -0.125, -0. ], |
---|
398 | [-0.25 , -0.125, -0. ], |
---|
399 | [-0.25 , -0.125, -0.25 ], |
---|
400 | [-0. , -0.125, -0.25 ], |
---|
401 | [-0.25 , -0.125, -0. ], |
---|
402 | [-0.25 , -0.375, -0.25 ], |
---|
403 | [-0.5 , -0.375, -0.25 ], |
---|
404 | [-0.5 , -0.375, -0.5 ], |
---|
405 | [-0.25 , -0.375, -0.5 ]]), 'ymomentum': num.array([[ 0.5 , 0.25, 0. ], |
---|
406 | [ 0.5 , 0.75, 1. ], |
---|
407 | [ 0.5 , 0.75, 0.5 ], |
---|
408 | [ 1. , 0.75, 0.5 ], |
---|
409 | [ 1. , 0.75, 1. ], |
---|
410 | [ 0. , 0.25, 0.5 ], |
---|
411 | [ 0.5 , 0.25, 0.5 ], |
---|
412 | [ 0.5 , 0.75, 1. ], |
---|
413 | [ 0.5 , 0.75, 0.5 ], |
---|
414 | [ 1. , 0.75, 0.5 ], |
---|
415 | [ 1. , 0.75, 1. ], |
---|
416 | [ 0. , 0.25, 0. ], |
---|
417 | [ 0. , 0.25, 0.5 ], |
---|
418 | [ 0. , 0.25, 0. ], |
---|
419 | [ 0.5 , 0.25, 0. ], |
---|
420 | [ 0.5 , 0.25, 0.5 ]]), 'friction': num.array([[ 0., 0., 0.], |
---|
421 | [ 0., 0., 0.], |
---|
422 | [ 0., 0., 0.], |
---|
423 | [ 0., 0., 0.], |
---|
424 | [ 0., 0., 0.], |
---|
425 | [ 0., 0., 0.], |
---|
426 | [ 0., 0., 0.], |
---|
427 | [ 0., 0., 0.], |
---|
428 | [ 0., 0., 0.], |
---|
429 | [ 0., 0., 0.], |
---|
430 | [ 0., 0., 0.], |
---|
431 | [ 0., 0., 0.], |
---|
432 | [ 0., 0., 0.], |
---|
433 | [ 0., 0., 0.], |
---|
434 | [ 0., 0., 0.], |
---|
435 | [ 0., 0., 0.]]), 'xmomentum': num.array([[ 2., 2., 2.], |
---|
436 | [ 2., 2., 2.], |
---|
437 | [ 2., 2., 2.], |
---|
438 | [ 2., 2., 2.], |
---|
439 | [ 2., 2., 2.], |
---|
440 | [ 2., 2., 2.], |
---|
441 | [ 2., 2., 2.], |
---|
442 | [ 2., 2., 2.], |
---|
443 | [ 2., 2., 2.], |
---|
444 | [ 2., 2., 2.], |
---|
445 | [ 2., 2., 2.], |
---|
446 | [ 2., 2., 2.], |
---|
447 | [ 2., 2., 2.], |
---|
448 | [ 2., 2., 2.], |
---|
449 | [ 2., 2., 2.], |
---|
450 | [ 2., 2., 2.]])} |
---|
451 | |
---|
452 | |
---|
453 | |
---|
454 | #---------------------------------------------------------------------------------- |
---|
455 | # Test build_submesh |
---|
456 | #---------------------------------------------------------------------------------- |
---|
457 | #submesh = build_submesh(nodes, triangles, edges, quantities, triangles_per_proc) |
---|
458 | |
---|
459 | # Temporarily build the mesh to find the neighbouring |
---|
460 | # triangles and true boundary polygon |
---|
461 | from anuga.abstract_2d_finite_volumes.neighbour_mesh import Mesh |
---|
462 | |
---|
463 | mesh = Mesh(nodes, triangles) |
---|
464 | boundary_polygon = mesh.get_boundary_polygon() |
---|
465 | |
---|
466 | |
---|
467 | # Subdivide into non-overlapping partitions |
---|
468 | |
---|
469 | submeshf = submesh_full(nodes, triangles, edges, \ |
---|
470 | triangles_per_proc) |
---|
471 | |
---|
472 | #print submeshf |
---|
473 | |
---|
474 | true_submesh = {'full_boundary': [{(3, 1): 'right', (4, 1): 'top'}, {(5, 1): 'left', (10, 1): 'top', (7, 1): 'left'}, {(13, 1): 'bottom', (14, 1): 'right', (11, 1): 'bottom'}], |
---|
475 | 'ghost_nodes': [num.array([[ 0. , 0. , 0. ], |
---|
476 | [ 1. , 0. , 0.5 ], |
---|
477 | [ 2. , 0. , 1. ], |
---|
478 | [ 6. , 1. , 0. ], |
---|
479 | [ 10. , 0.25, 0.75], |
---|
480 | [ 11. , 0.75, 0.25]]), num.array([[ 3. , 0.5 , 0. ], |
---|
481 | [ 7. , 1. , 0.5 ], |
---|
482 | [ 8. , 1. , 1. ], |
---|
483 | [ 11. , 0.75, 0.25], |
---|
484 | [ 12. , 0.75, 0.75]]), num.array([[ 1. , 0. , 0.5 ], |
---|
485 | [ 5. , 0.5 , 1. ], |
---|
486 | [ 8. , 1. , 1. ], |
---|
487 | [ 12. , 0.75, 0.75]])], 'full_nodes': [num.array([[ 3. , 0.5 , 0. ], |
---|
488 | [ 4. , 0.5 , 0.5 ], |
---|
489 | [ 5. , 0.5 , 1. ], |
---|
490 | [ 7. , 1. , 0.5 ], |
---|
491 | [ 8. , 1. , 1. ], |
---|
492 | [ 9. , 0.25, 0.25], |
---|
493 | [ 12. , 0.75, 0.75]]), num.array([[ 0. , 0. , 0. ], |
---|
494 | [ 1. , 0. , 0.5 ], |
---|
495 | [ 2. , 0. , 1. ], |
---|
496 | [ 4. , 0.5 , 0.5 ], |
---|
497 | [ 5. , 0.5 , 1. ], |
---|
498 | [ 9. , 0.25, 0.25], |
---|
499 | [ 10. , 0.25, 0.75]]), num.array([[ 0. , 0. , 0. ], |
---|
500 | [ 3. , 0.5 , 0. ], |
---|
501 | [ 4. , 0.5 , 0.5 ], |
---|
502 | [ 6. , 1. , 0. ], |
---|
503 | [ 7. , 1. , 0.5 ], |
---|
504 | [ 9. , 0.25, 0.25], |
---|
505 | [ 11. , 0.75, 0.25]])], 'ghost_triangles': [num.array([[ 5, 0, 9, 1], |
---|
506 | [ 6, 1, 9, 4], |
---|
507 | [ 8, 4, 10, 1], |
---|
508 | [ 9, 5, 10, 4], |
---|
509 | [10, 2, 10, 5], |
---|
510 | [11, 3, 9, 0], |
---|
511 | [12, 3, 11, 4], |
---|
512 | [13, 6, 11, 3], |
---|
513 | [14, 7, 11, 6], |
---|
514 | [15, 4, 11, 7]]), num.array([[ 0, 4, 9, 3], |
---|
515 | [ 1, 4, 12, 5], |
---|
516 | [ 2, 7, 12, 4], |
---|
517 | [ 4, 5, 12, 8], |
---|
518 | [11, 3, 9, 0], |
---|
519 | [12, 3, 11, 4]]), num.array([[ 0, 4, 9, 3], |
---|
520 | [ 1, 4, 12, 5], |
---|
521 | [ 2, 7, 12, 4], |
---|
522 | [ 3, 8, 12, 7], |
---|
523 | [ 5, 0, 9, 1], |
---|
524 | [ 6, 1, 9, 4]])], 'ghost_boundary': [{(13, 1): 'ghost', (8, 0): 'ghost', (14, 1): 'ghost', (11, 1): 'ghost', (10, 1): 'ghost', (5, 1): 'ghost', (10, 2): 'ghost'}, {(12, 2): 'ghost', (12, 0): 'ghost', (2, 1): 'ghost', (11, 1): 'ghost', (2, 2): 'ghost', (4, 1): 'ghost', (4, 0): 'ghost'}, {(3, 2): 'ghost', (6, 1): 'ghost', (3, 1): 'ghost', (5, 1): 'ghost', (1, 0): 'ghost', (1, 1): 'ghost'}], 'full_triangles': [[[4, 9, 3], [4, 12, 5], [7, 12, 4], [8, 12, 7], [5, 12, 8]], [[0, 9, 1], [1, 9, 4], [1, 10, 2], [4, 10, 1], [5, 10, 4], [2, 10, 5]], [[3, 9, 0], [3, 11, 4], [6, 11, 3], [7, 11, 6], [4, 11, 7]]], 'full_commun': [{0: [1, 2], 1: [1, 2], 2: [1, 2], 3: [2], 4: [1]}, {5: [0, 2], 6: [0, 2], 7: [], 8: [0], 9: [0], 10: [0]}, {11: [0, 1], 12: [0, 1], 13: [0], 14: [0], 15: [0]}], 'ghost_commun': [num.array([[ 5, 1], |
---|
525 | [ 6, 1], |
---|
526 | [ 8, 1], |
---|
527 | [ 9, 1], |
---|
528 | [10, 1], |
---|
529 | [11, 2], |
---|
530 | [12, 2], |
---|
531 | [13, 2], |
---|
532 | [14, 2], |
---|
533 | [15, 2]]), num.array([[ 0, 0], |
---|
534 | [ 1, 0], |
---|
535 | [ 2, 0], |
---|
536 | [ 4, 0], |
---|
537 | [11, 2], |
---|
538 | [12, 2]]), num.array([[0, 0], |
---|
539 | [1, 0], |
---|
540 | [2, 0], |
---|
541 | [3, 0], |
---|
542 | [5, 1], |
---|
543 | [6, 1]])]} |
---|
544 | |
---|
545 | |
---|
546 | |
---|
547 | for i in range(3): |
---|
548 | assert num.allclose(true_submesh['full_triangles'][i],submeshf['full_triangles'][i]) |
---|
549 | assert num.allclose(true_submesh['full_nodes'][i],submeshf['full_nodes'][i]) |
---|
550 | assert true_submesh['full_boundary'] == submeshf['full_boundary'] |
---|
551 | |
---|
552 | # Add any extra ghost boundary layer information |
---|
553 | |
---|
554 | submeshg = submesh_ghost(submeshf, mesh, triangles_per_proc) |
---|
555 | |
---|
556 | |
---|
557 | |
---|
558 | # Order the quantities information to be the same as the triangle |
---|
559 | # information |
---|
560 | |
---|
561 | submesh = submesh_quantities(submeshg, quantities, \ |
---|
562 | triangles_per_proc) |
---|
563 | |
---|
564 | submesh["boundary_polygon"] = boundary_polygon |
---|
565 | |
---|
566 | |
---|
567 | #-------------------------------------------------------- |
---|
568 | # Results we expect from build_submesh |
---|
569 | #-------------------------------------------------------- |
---|
570 | |
---|
571 | assert num.allclose(submesh['full_nodes'][0],[[3.0, 0.5, 0.0], [4.0, 0.5, 0.5], [5.0, 0.5, 1.0], [7.0, 1.0, 0.5], [8.0, 1.0, 1.0], [9.0, 0.25, 0.25], [12.0, 0.75, 0.75]]) |
---|
572 | assert num.allclose(submesh['full_nodes'][1],[[0.0, 0.0, 0.0], [1.0, 0.0, 0.5], [2.0, 0.0, 1.0], [4.0, 0.5, 0.5], [5.0, 0.5, 1.0], [9.0, 0.25, 0.25], [10.0, 0.25, 0.75]]) |
---|
573 | assert num.allclose(submesh['full_nodes'][2],[[0.0, 0.0, 0.0], [3.0, 0.5, 0.0], [4.0, 0.5, 0.5], [6.0, 1.0, 0.0], [7.0, 1.0, 0.5], [9.0, 0.25, 0.25], [11.0, 0.75, 0.25]]) |
---|
574 | |
---|
575 | |
---|
576 | assert num.allclose(submesh['ghost_nodes'][0],[[0.0, 0.0, 0.0], [1.0, 0.0, 0.5], [2.0, 0.0, 1.0], [6.0, 1.0, 0.0], [10.0, 0.25, 0.75], [11.0, 0.75, 0.25]]) |
---|
577 | assert num.allclose(submesh['ghost_nodes'][1],[[3.0, 0.5, 0.0], [7.0, 1.0, 0.5], [8.0, 1.0, 1.0], [11.0, 0.75, 0.25], [12.0, 0.75, 0.75]]) |
---|
578 | assert num.allclose(submesh['ghost_nodes'][2],[[1.0, 0.0, 0.5], [5.0, 0.5, 1.0], [8.0, 1.0, 1.0], [12.0, 0.75, 0.75]]) |
---|
579 | |
---|
580 | |
---|
581 | |
---|
582 | true_full_triangles = [num.array([[ 4, 9, 3], |
---|
583 | [ 4, 12, 5], |
---|
584 | [ 7, 12, 4], |
---|
585 | [ 8, 12, 7], |
---|
586 | [ 5, 12, 8]]), |
---|
587 | num.array([[ 0, 9, 1], |
---|
588 | [ 1, 9, 4], |
---|
589 | [ 1, 10, 2], |
---|
590 | [ 4, 10, 1], |
---|
591 | [ 5, 10, 4], |
---|
592 | [ 2, 10, 5]]), |
---|
593 | num.array([[ 3, 9, 0], |
---|
594 | [ 3, 11, 4], |
---|
595 | [ 6, 11, 3], |
---|
596 | [ 7, 11, 6], |
---|
597 | [ 4, 11, 7]])] |
---|
598 | |
---|
599 | |
---|
600 | assert num.allclose(submesh['full_triangles'][0],true_full_triangles[0]) |
---|
601 | assert num.allclose(submesh['full_triangles'][1],true_full_triangles[1]) |
---|
602 | assert num.allclose(submesh['full_triangles'][2],true_full_triangles[2]) |
---|
603 | |
---|
604 | true_ghost_triangles = [num.array([[ 5, 0, 9, 1], |
---|
605 | [ 6, 1, 9, 4], |
---|
606 | [ 8, 4, 10, 1], |
---|
607 | [ 9, 5, 10, 4], |
---|
608 | [10, 2, 10, 5], |
---|
609 | [11, 3, 9, 0], |
---|
610 | [12, 3, 11, 4], |
---|
611 | [13, 6, 11, 3], |
---|
612 | [14, 7, 11, 6], |
---|
613 | [15, 4, 11, 7]]), |
---|
614 | num.array([[ 0, 4, 9, 3], |
---|
615 | [ 1, 4, 12, 5], |
---|
616 | [ 2, 7, 12, 4], |
---|
617 | [ 4, 5, 12, 8], |
---|
618 | [11, 3, 9, 0], |
---|
619 | [12, 3, 11, 4]]), |
---|
620 | num.array([[ 0, 4, 9, 3], |
---|
621 | [ 1, 4, 12, 5], |
---|
622 | [ 2, 7, 12, 4], |
---|
623 | [ 3, 8, 12, 7], |
---|
624 | [ 5, 0, 9, 1], |
---|
625 | [ 6, 1, 9, 4]])] |
---|
626 | |
---|
627 | |
---|
628 | |
---|
629 | assert num.allclose(submesh['ghost_triangles'][0],true_ghost_triangles[0]) |
---|
630 | assert num.allclose(submesh['ghost_triangles'][1],true_ghost_triangles[1]) |
---|
631 | assert num.allclose(submesh['ghost_triangles'][2],true_ghost_triangles[2]) |
---|
632 | |
---|
633 | true_full_commun = [{0: [1, 2], 1: [1, 2], 2: [1, 2], 3: [2], 4: [1]}, {5: [0, 2], 6: [0, 2], 7: [], 8: [0], 9: [0], 10: [0]}, {11: [0, 1], 12: [0, 1], 13: [0], 14: [0], 15: [0]}] |
---|
634 | |
---|
635 | assert true_full_commun == submesh['full_commun'] |
---|
636 | |
---|
637 | |
---|
638 | true_ghost_commun = [num.array([[ 5, 1], |
---|
639 | [ 6, 1], |
---|
640 | [ 8, 1], |
---|
641 | [ 9, 1], |
---|
642 | [10, 1], |
---|
643 | [11, 2], |
---|
644 | [12, 2], |
---|
645 | [13, 2], |
---|
646 | [14, 2], |
---|
647 | [15, 2]]), |
---|
648 | num.array([[ 0, 0], |
---|
649 | [ 1, 0], |
---|
650 | [ 2, 0], |
---|
651 | [ 4, 0], |
---|
652 | [11, 2], |
---|
653 | [12, 2]]), |
---|
654 | num.array([[0, 0], |
---|
655 | [1, 0], |
---|
656 | [2, 0], |
---|
657 | [3, 0], |
---|
658 | [5, 1], |
---|
659 | [6, 1]])] |
---|
660 | |
---|
661 | assert num.allclose(submesh['ghost_commun'][0],true_ghost_commun[0]) |
---|
662 | assert num.allclose(submesh['ghost_commun'][1],true_ghost_commun[1]) |
---|
663 | assert num.allclose(submesh['ghost_commun'][2],true_ghost_commun[2]) |
---|
664 | |
---|
665 | |
---|
666 | |
---|
667 | #------------------------------------------------------------- |
---|
668 | |
---|
669 | if __name__ == "__main__": |
---|
670 | suite = unittest.makeSuite(Test_Domain,'test') |
---|
671 | runner = unittest.TextTestRunner() |
---|
672 | runner.run(suite) |
---|