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

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

Reorganising parallel files

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