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

Last change on this file since 7391 was 7391, checked in by steve, 15 years ago
File size: 27.1 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.pmesh_divide import pmesh_divide_metis
14from anuga_parallel.build_submesh import build_submesh
15from anuga_parallel.build_submesh import submesh_full, submesh_ghost, submesh_quantities
16from anuga_parallel.build_commun import extract_hostmesh, rec_submesh, send_submesh
17
18#import numpy as num
19import Numeric as num
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_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_submeshf = {'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_nodes': [num.array([[  3.  ,   0.5 ,   0.  ],
475       [  4.  ,   0.5 ,   0.5 ],
476       [  5.  ,   0.5 ,   1.  ],
477       [  7.  ,   1.  ,   0.5 ],
478       [  8.  ,   1.  ,   1.  ],
479       [  9.  ,   0.25,   0.25],
480       [ 12.  ,   0.75,   0.75]]), num.array([[  0.  ,   0.  ,   0.  ],
481       [  1.  ,   0.  ,   0.5 ],
482       [  2.  ,   0.  ,   1.  ],
483       [  4.  ,   0.5 ,   0.5 ],
484       [  5.  ,   0.5 ,   1.  ],
485       [  9.  ,   0.25,   0.25],
486       [ 10.  ,   0.25,   0.75]]), num.array([[  0.  ,   0.  ,   0.  ],
487       [  3.  ,   0.5 ,   0.  ],
488       [  4.  ,   0.5 ,   0.5 ],
489       [  6.  ,   1.  ,   0.  ],
490       [  7.  ,   1.  ,   0.5 ],
491       [  9.  ,   0.25,   0.25],
492       [ 11.  ,   0.75,   0.25]])], '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'}]}
493
494
495
496        for key, item in submeshf.iteritems():
497            assert submeshf[key] == true_submeshf[key]
498           
499        # Add any extra ghost boundary layer information
500
501        submeshg = submesh_ghost(submeshf, mesh, triangles_per_proc)
502
503        # Order the quantities information to be the same as the triangle
504        # information
505
506        submesh = submesh_quantities(submeshg, quantities, \
507                                 triangles_per_proc)
508
509        submesh["boundary_polygon"] = boundary_polygon
510
511
512        #--------------------------------------------------------
513        # Results we expect from build_submesh
514        #--------------------------------------------------------
515
516        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]])
517        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]])
518        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]])
519
520
521        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]])
522        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]])
523        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]])
524
525
526
527        true_full_triangles = [num.array([[ 4,  9,  3],
528                                          [ 4, 12,  5],
529                                          [ 7, 12,  4],
530                                          [ 8, 12,  7],
531                                          [ 5, 12,  8]]),
532                               num.array([[ 0,  9,  1],
533                                          [ 1,  9,  4],
534                                          [ 1, 10,  2],
535                                          [ 4, 10,  1],
536                                          [ 5, 10,  4],
537                                          [ 2, 10,  5]]),
538                               num.array([[ 3,  9,  0],
539                                          [ 3, 11,  4],
540                                          [ 6, 11,  3],
541                                          [ 7, 11,  6],
542                                          [ 4, 11,  7]])]
543
544
545        assert num.allclose(submesh['full_triangles'][0],true_full_triangles[0])
546        assert num.allclose(submesh['full_triangles'][1],true_full_triangles[1])
547        assert num.allclose(submesh['full_triangles'][2],true_full_triangles[2])
548
549        true_ghost_triangles = [num.array([[ 5,  0,  9,  1],
550                                           [ 6,  1,  9,  4],
551                                           [ 8,  4, 10,  1],
552                                           [ 9,  5, 10,  4],
553                                           [10,  2, 10,  5],
554                                           [11,  3,  9,  0],
555                                           [12,  3, 11,  4],
556                                           [13,  6, 11,  3],
557                                           [14,  7, 11,  6],
558                                           [15,  4, 11,  7]]),
559                                num.array([[ 0,  4,  9,  3],
560                                           [ 1,  4, 12,  5],
561                                           [ 2,  7, 12,  4],
562                                           [ 4,  5, 12,  8],
563                                           [11,  3,  9,  0],
564                                           [12,  3, 11,  4]]),
565                                num.array([[ 0,  4,  9,  3],
566                                           [ 1,  4, 12,  5],
567                                           [ 2,  7, 12,  4],
568                                           [ 3,  8, 12,  7],
569                                           [ 5,  0,  9,  1],
570                                           [ 6,  1,  9,  4]])]
571
572
573
574        assert num.allclose(submesh['ghost_triangles'][0],true_ghost_triangles[0])
575        assert num.allclose(submesh['ghost_triangles'][1],true_ghost_triangles[1])
576        assert num.allclose(submesh['ghost_triangles'][2],true_ghost_triangles[2])
577
578        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]}]
579
580        assert true_full_commun == submesh['full_commun']
581
582
583        true_ghost_commun = [num.array([[ 5,  1],
584                                        [ 6,  1],
585                                        [ 8,  1],
586                                        [ 9,  1],
587                                        [10,  1],
588                                        [11,  2],
589                                        [12,  2],
590                                        [13,  2],
591                                        [14,  2],
592                                        [15,  2]]),
593                             num.array([[ 0,  0],
594                                        [ 1,  0],
595                                        [ 2,  0],
596                                        [ 4,  0],
597                                        [11,  2],
598                                        [12,  2]]),
599                             num.array([[0, 0],
600                                        [1, 0],
601                                        [2, 0],
602                                        [3, 0],
603                                        [5, 1],
604                                        [6, 1]])]
605
606        assert num.allclose(submesh['ghost_commun'][0],true_ghost_commun[0])
607        assert num.allclose(submesh['ghost_commun'][1],true_ghost_commun[1])
608        assert num.allclose(submesh['ghost_commun'][2],true_ghost_commun[2])
609
610
611 
612#-------------------------------------------------------------
613
614if __name__ == "__main__":
615    suite = unittest.makeSuite(Test_Domain,'test')
616    runner = unittest.TextTestRunner()
617    runner.run(suite)
Note: See TracBrowser for help on using the repository browser.