source: anuga_core/source/anuga_parallel/test_distribute_mesh.py @ 7449

Last change on this file since 7449 was 7449, checked in by steve, 15 years ago

Testing unit tests

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