source: trunk/anuga_core/source/anuga_parallel/test_distribute_mesh.py @ 8022

Last change on this file since 8022 was 8011, checked in by steve, 14 years ago

Tested parallel code with new anuga interface. Seems to be working

File size: 18.2 KB
Line 
1#!/usr/bin/env python
2
3import unittest
4import sys
5from math import sqrt
6
7
8from anuga import Domain
9from anuga 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        test distributing with just one processor
44        """
45       
46        points, vertices, boundary = rectangular_cross(2,2)
47
48
49        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]]
50
51        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]]
52
53
54        assert num.allclose(points,true_points)
55        assert num.allclose(vertices,true_vertices)
56
57        domain = Domain(points, vertices, boundary)
58
59
60        domain.set_quantity('elevation', topography) # Use function for elevation
61        domain.set_quantity('friction', 0.0)         # Constant friction
62        domain.set_quantity('stage', expression='elevation') # Dry initial stage
63        domain.set_quantity('xmomentum', expression='friction + 2.0') #
64        domain.set_quantity('ymomentum', ycoord) #
65
66
67        #print domain.quantities['ymomentum'].centroid_values
68 
69        nodes, triangles, boundary, triangles_per_proc, quantities = pmesh_divide_metis(domain,1)
70
71
72        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]]
73
74        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]]
75
76
77        assert num.allclose(nodes,true_nodes)
78        assert num.allclose(triangles,true_triangles)
79
80
81        assert num.allclose(triangles_per_proc,[16])
82       
83       
84
85    def test_pmesh_2(self):
86        """
87        Test 2 way pmesh
88        """
89        points, vertices, boundary = rectangular_cross(2,2)
90
91
92        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]]
93
94        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]]
95
96
97        assert num.allclose(points,true_points)
98        assert num.allclose(vertices,true_vertices)
99
100        domain = Domain(points, vertices, boundary)
101
102
103        domain.set_quantity('elevation', topography) # Use function for elevation
104        domain.set_quantity('friction', 0.0)         # Constant friction
105        domain.set_quantity('stage', expression='elevation') # Dry initial stage
106        domain.set_quantity('xmomentum', expression='friction + 2.0') #
107        domain.set_quantity('ymomentum', ycoord) #
108
109
110        #print domain.quantities['ymomentum'].centroid_values
111 
112        nodes, triangles, boundary, triangles_per_proc, quantities = pmesh_divide_metis(domain,2)
113
114
115        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]]
116
117
118        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]]
119
120
121        assert num.allclose(nodes,true_nodes)
122        assert num.allclose(triangles,true_triangles)
123
124
125        assert num.allclose(triangles_per_proc,[8,8])
126
127
128           
129    def test_build_submesh_3(self):
130        """
131        Test 3 way build_submesh
132        """
133
134        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]]
135
136
137        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]]
138
139
140        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'}
141
142        triangles_per_proc = [5, 6, 5]
143
144
145        quantities = {'stage': num.array([[-0.25 , -0.125, -0.25 ],
146       [-0.25 , -0.375, -0.25 ],
147       [-0.5  , -0.375, -0.25 ],
148       [-0.5  , -0.375, -0.5  ],
149       [-0.25 , -0.375, -0.5  ],
150       [-0.   , -0.125, -0.   ],
151       [-0.   , -0.125, -0.25 ],
152       [-0.   , -0.125, -0.   ],
153       [-0.25 , -0.125, -0.   ],
154       [-0.25 , -0.125, -0.25 ],
155       [-0.   , -0.125, -0.25 ],
156       [-0.25 , -0.125, -0.   ],
157       [-0.25 , -0.375, -0.25 ],
158       [-0.5  , -0.375, -0.25 ],
159       [-0.5  , -0.375, -0.5  ],
160       [-0.25 , -0.375, -0.5  ]]),  'elevation': num.array([[-0.25 , -0.125, -0.25 ],
161       [-0.25 , -0.375, -0.25 ],
162       [-0.5  , -0.375, -0.25 ],
163       [-0.5  , -0.375, -0.5  ],
164       [-0.25 , -0.375, -0.5  ],
165       [-0.   , -0.125, -0.   ],
166       [-0.   , -0.125, -0.25 ],
167       [-0.   , -0.125, -0.   ],
168       [-0.25 , -0.125, -0.   ],
169       [-0.25 , -0.125, -0.25 ],
170       [-0.   , -0.125, -0.25 ],
171       [-0.25 , -0.125, -0.   ],
172       [-0.25 , -0.375, -0.25 ],
173       [-0.5  , -0.375, -0.25 ],
174       [-0.5  , -0.375, -0.5  ],
175       [-0.25 , -0.375, -0.5  ]]),  'ymomentum': num.array([[ 0.5 ,  0.25,  0.  ],
176       [ 0.5 ,  0.75,  1.  ],
177       [ 0.5 ,  0.75,  0.5 ],
178       [ 1.  ,  0.75,  0.5 ],
179       [ 1.  ,  0.75,  1.  ],
180       [ 0.  ,  0.25,  0.5 ],
181       [ 0.5 ,  0.25,  0.5 ],
182       [ 0.5 ,  0.75,  1.  ],
183       [ 0.5 ,  0.75,  0.5 ],
184       [ 1.  ,  0.75,  0.5 ],
185       [ 1.  ,  0.75,  1.  ],
186       [ 0.  ,  0.25,  0.  ],
187       [ 0.  ,  0.25,  0.5 ],
188       [ 0.  ,  0.25,  0.  ],
189       [ 0.5 ,  0.25,  0.  ],
190       [ 0.5 ,  0.25,  0.5 ]]),  'friction': num.array([[ 0.,  0.,  0.],
191       [ 0.,  0.,  0.],
192       [ 0.,  0.,  0.],
193       [ 0.,  0.,  0.],
194       [ 0.,  0.,  0.],
195       [ 0.,  0.,  0.],
196       [ 0.,  0.,  0.],
197       [ 0.,  0.,  0.],
198       [ 0.,  0.,  0.],
199       [ 0.,  0.,  0.],
200       [ 0.,  0.,  0.],
201       [ 0.,  0.,  0.],
202       [ 0.,  0.,  0.],
203       [ 0.,  0.,  0.],
204       [ 0.,  0.,  0.],
205       [ 0.,  0.,  0.]]),  'xmomentum': num.array([[ 2.,  2.,  2.],
206       [ 2.,  2.,  2.],
207       [ 2.,  2.,  2.],
208       [ 2.,  2.,  2.],
209       [ 2.,  2.,  2.],
210       [ 2.,  2.,  2.],
211       [ 2.,  2.,  2.],
212       [ 2.,  2.,  2.],
213       [ 2.,  2.,  2.],
214       [ 2.,  2.,  2.],
215       [ 2.,  2.,  2.],
216       [ 2.,  2.,  2.],
217       [ 2.,  2.,  2.],
218       [ 2.,  2.,  2.],
219       [ 2.,  2.,  2.],
220       [ 2.,  2.,  2.]])}
221
222
223       
224        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'}],
225                        'ghost_nodes': [num.array([[  0.  ,   0.  ,   0.  ],
226       [  1.  ,   0.  ,   0.5 ],
227       [  2.  ,   0.  ,   1.  ],
228       [  6.  ,   1.  ,   0.  ],
229       [ 10.  ,   0.25,   0.75],
230       [ 11.  ,   0.75,   0.25]]), num.array([[  3.  ,   0.5 ,   0.  ],
231       [  7.  ,   1.  ,   0.5 ],
232       [  8.  ,   1.  ,   1.  ],
233       [ 11.  ,   0.75,   0.25],
234       [ 12.  ,   0.75,   0.75]]), num.array([[  1.  ,   0.  ,   0.5 ],
235       [  5.  ,   0.5 ,   1.  ],
236       [  8.  ,   1.  ,   1.  ],
237       [ 12.  ,   0.75,   0.75]])],
238                        'full_nodes': [num.array([[  3.  ,   0.5 ,   0.  ],
239       [  4.  ,   0.5 ,   0.5 ],
240       [  5.  ,   0.5 ,   1.  ],
241       [  7.  ,   1.  ,   0.5 ],
242       [  8.  ,   1.  ,   1.  ],
243       [  9.  ,   0.25,   0.25],
244       [ 12.  ,   0.75,   0.75]]), num.array([[  0.  ,   0.  ,   0.  ],
245       [  1.  ,   0.  ,   0.5 ],
246       [  2.  ,   0.  ,   1.  ],
247       [  4.  ,   0.5 ,   0.5 ],
248       [  5.  ,   0.5 ,   1.  ],
249       [  9.  ,   0.25,   0.25],
250       [ 10.  ,   0.25,   0.75]]), num.array([[  0.  ,   0.  ,   0.  ],
251       [  3.  ,   0.5 ,   0.  ],
252       [  4.  ,   0.5 ,   0.5 ],
253       [  6.  ,   1.  ,   0.  ],
254       [  7.  ,   1.  ,   0.5 ],
255       [  9.  ,   0.25,   0.25],
256       [ 11.  ,   0.75,   0.25]])],
257                        'ghost_triangles': [num.array([[ 5,  0,  9,  1],
258       [ 6,  1,  9,  4],
259       [ 8,  4, 10,  1],
260       [ 9,  5, 10,  4],
261       [10,  2, 10,  5],
262       [11,  3,  9,  0],
263       [12,  3, 11,  4],
264       [13,  6, 11,  3],
265       [14,  7, 11,  6],
266       [15,  4, 11,  7]]), num.array([[ 0,  4,  9,  3],
267       [ 1,  4, 12,  5],
268       [ 2,  7, 12,  4],
269       [ 4,  5, 12,  8],
270       [11,  3,  9,  0],
271       [12,  3, 11,  4]]), num.array([[ 0,  4,  9,  3],
272       [ 1,  4, 12,  5],
273       [ 2,  7, 12,  4],
274       [ 3,  8, 12,  7],
275       [ 5,  0,  9,  1],
276       [ 6,  1,  9,  4]])],
277                        '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'}],
278                        '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]]],
279                        '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]}],
280                        'ghost_commun': [num.array([[ 5,  1],
281       [ 6,  1],
282       [ 8,  1],
283       [ 9,  1],
284       [10,  1],
285       [11,  2],
286       [12,  2],
287       [13,  2],
288       [14,  2],
289       [15,  2]]), num.array([[ 0,  0],
290       [ 1,  0],
291       [ 2,  0],
292       [ 4,  0],
293       [11,  2],
294       [12,  2]]), num.array([[0, 0],
295       [1, 0],
296       [2, 0],
297       [3, 0],
298       [5, 1],
299       [6, 1]])],  'ghost_quan': {'stage': [num.array([[-0.   , -0.125, -0.   ],
300       [-0.   , -0.125, -0.25 ],
301       [-0.25 , -0.125, -0.   ],
302       [-0.25 , -0.125, -0.25 ],
303       [-0.   , -0.125, -0.25 ],
304       [-0.25 , -0.125, -0.   ],
305       [-0.25 , -0.375, -0.25 ],
306       [-0.5  , -0.375, -0.25 ],
307       [-0.5  , -0.375, -0.5  ],
308       [-0.25 , -0.375, -0.5  ]]), num.array([[-0.25 , -0.125, -0.25 ],
309       [-0.25 , -0.375, -0.25 ],
310       [-0.5  , -0.375, -0.25 ],
311       [-0.25 , -0.375, -0.5  ],
312       [-0.25 , -0.125, -0.   ],
313       [-0.25 , -0.375, -0.25 ]]), num.array([[-0.25 , -0.125, -0.25 ],
314       [-0.25 , -0.375, -0.25 ],
315       [-0.5  , -0.375, -0.25 ],
316       [-0.5  , -0.375, -0.5  ],
317       [-0.   , -0.125, -0.   ],
318       [-0.   , -0.125, -0.25 ]])],  'elevation': [num.array([[-0.   , -0.125, -0.   ],
319       [-0.   , -0.125, -0.25 ],
320       [-0.25 , -0.125, -0.   ],
321       [-0.25 , -0.125, -0.25 ],
322       [-0.   , -0.125, -0.25 ],
323       [-0.25 , -0.125, -0.   ],
324       [-0.25 , -0.375, -0.25 ],
325       [-0.5  , -0.375, -0.25 ],
326       [-0.5  , -0.375, -0.5  ],
327       [-0.25 , -0.375, -0.5  ]]), num.array([[-0.25 , -0.125, -0.25 ],
328       [-0.25 , -0.375, -0.25 ],
329       [-0.5  , -0.375, -0.25 ],
330       [-0.25 , -0.375, -0.5  ],
331       [-0.25 , -0.125, -0.   ],
332       [-0.25 , -0.375, -0.25 ]]), num.array([[-0.25 , -0.125, -0.25 ],
333       [-0.25 , -0.375, -0.25 ],
334       [-0.5  , -0.375, -0.25 ],
335       [-0.5  , -0.375, -0.5  ],
336       [-0.   , -0.125, -0.   ],
337       [-0.   , -0.125, -0.25 ]])],  'ymomentum': [num.array([[ 0.  ,  0.25,  0.5 ],
338       [ 0.5 ,  0.25,  0.5 ],
339       [ 0.5 ,  0.75,  0.5 ],
340       [ 1.  ,  0.75,  0.5 ],
341       [ 1.  ,  0.75,  1.  ],
342       [ 0.  ,  0.25,  0.  ],
343       [ 0.  ,  0.25,  0.5 ],
344       [ 0.  ,  0.25,  0.  ],
345       [ 0.5 ,  0.25,  0.  ],
346       [ 0.5 ,  0.25,  0.5 ]]), num.array([[ 0.5 ,  0.25,  0.  ],
347       [ 0.5 ,  0.75,  1.  ],
348       [ 0.5 ,  0.75,  0.5 ],
349       [ 1.  ,  0.75,  1.  ],
350       [ 0.  ,  0.25,  0.  ],
351       [ 0.  ,  0.25,  0.5 ]]), num.array([[ 0.5 ,  0.25,  0.  ],
352       [ 0.5 ,  0.75,  1.  ],
353       [ 0.5 ,  0.75,  0.5 ],
354       [ 1.  ,  0.75,  0.5 ],
355       [ 0.  ,  0.25,  0.5 ],
356       [ 0.5 ,  0.25,  0.5 ]])],  'friction': [num.array([[ 0.,  0.,  0.],
357       [ 0.,  0.,  0.],
358       [ 0.,  0.,  0.],
359       [ 0.,  0.,  0.],
360       [ 0.,  0.,  0.],
361       [ 0.,  0.,  0.],
362       [ 0.,  0.,  0.],
363       [ 0.,  0.,  0.],
364       [ 0.,  0.,  0.],
365       [ 0.,  0.,  0.]]), num.array([[ 0.,  0.,  0.],
366       [ 0.,  0.,  0.],
367       [ 0.,  0.,  0.],
368       [ 0.,  0.,  0.],
369       [ 0.,  0.,  0.],
370       [ 0.,  0.,  0.]]), num.array([[ 0.,  0.,  0.],
371       [ 0.,  0.,  0.],
372       [ 0.,  0.,  0.],
373       [ 0.,  0.,  0.],
374       [ 0.,  0.,  0.],
375       [ 0.,  0.,  0.]])], 'xmomentum': [num.array([[ 2.,  2.,  2.],
376       [ 2.,  2.,  2.],
377       [ 2.,  2.,  2.],
378       [ 2.,  2.,  2.],
379       [ 2.,  2.,  2.],
380       [ 2.,  2.,  2.],
381       [ 2.,  2.,  2.],
382       [ 2.,  2.,  2.],
383       [ 2.,  2.,  2.],
384       [ 2.,  2.,  2.]]), num.array([[ 2.,  2.,  2.],
385       [ 2.,  2.,  2.],
386       [ 2.,  2.,  2.],
387       [ 2.,  2.,  2.],
388       [ 2.,  2.,  2.],
389       [ 2.,  2.,  2.]]), num.array([[ 2.,  2.,  2.],
390       [ 2.,  2.,  2.],
391       [ 2.,  2.,  2.],
392       [ 2.,  2.,  2.],
393       [ 2.,  2.,  2.],
394       [ 2.,  2.,  2.]])]},  'full_quan': {'stage': [num.array([[-0.25 , -0.125, -0.25 ],
395       [-0.25 , -0.375, -0.25 ],
396       [-0.5  , -0.375, -0.25 ],
397       [-0.5  , -0.375, -0.5  ],
398       [-0.25 , -0.375, -0.5  ]]), num.array([[-0.   , -0.125, -0.   ],
399       [-0.   , -0.125, -0.25 ],
400       [-0.   , -0.125, -0.   ],
401       [-0.25 , -0.125, -0.   ],
402       [-0.25 , -0.125, -0.25 ],
403       [-0.   , -0.125, -0.25 ]]), num.array([[-0.25 , -0.125, -0.   ],
404       [-0.25 , -0.375, -0.25 ],
405       [-0.5  , -0.375, -0.25 ],
406       [-0.5  , -0.375, -0.5  ],
407       [-0.25 , -0.375, -0.5  ]])],  'elevation': [num.array([[-0.25 , -0.125, -0.25 ],
408       [-0.25 , -0.375, -0.25 ],
409       [-0.5  , -0.375, -0.25 ],
410       [-0.5  , -0.375, -0.5  ],
411       [-0.25 , -0.375, -0.5  ]]), num.array([[-0.   , -0.125, -0.   ],
412       [-0.   , -0.125, -0.25 ],
413       [-0.   , -0.125, -0.   ],
414       [-0.25 , -0.125, -0.   ],
415       [-0.25 , -0.125, -0.25 ],
416       [-0.   , -0.125, -0.25 ]]), num.array([[-0.25 , -0.125, -0.   ],
417       [-0.25 , -0.375, -0.25 ],
418       [-0.5  , -0.375, -0.25 ],
419       [-0.5  , -0.375, -0.5  ],
420       [-0.25 , -0.375, -0.5  ]])],  'ymomentum': [num.array([[ 0.5 ,  0.25,  0.  ],
421       [ 0.5 ,  0.75,  1.  ],
422       [ 0.5 ,  0.75,  0.5 ],
423       [ 1.  ,  0.75,  0.5 ],
424       [ 1.  ,  0.75,  1.  ]]), num.array([[ 0.  ,  0.25,  0.5 ],
425       [ 0.5 ,  0.25,  0.5 ],
426       [ 0.5 ,  0.75,  1.  ],
427       [ 0.5 ,  0.75,  0.5 ],
428       [ 1.  ,  0.75,  0.5 ],
429       [ 1.  ,  0.75,  1.  ]]), num.array([[ 0.  ,  0.25,  0.  ],
430       [ 0.  ,  0.25,  0.5 ],
431       [ 0.  ,  0.25,  0.  ],
432       [ 0.5 ,  0.25,  0.  ],
433       [ 0.5 ,  0.25,  0.5 ]])],  'friction': [num.array([[ 0.,  0.,  0.],
434       [ 0.,  0.,  0.],
435       [ 0.,  0.,  0.],
436       [ 0.,  0.,  0.],
437       [ 0.,  0.,  0.]]), num.array([[ 0.,  0.,  0.],
438       [ 0.,  0.,  0.],
439       [ 0.,  0.,  0.],
440       [ 0.,  0.,  0.],
441       [ 0.,  0.,  0.],
442       [ 0.,  0.,  0.]]), num.array([[ 0.,  0.,  0.],
443       [ 0.,  0.,  0.],
444       [ 0.,  0.,  0.],
445       [ 0.,  0.,  0.],
446       [ 0.,  0.,  0.]])],  'xmomentum': [num.array([[ 2.,  2.,  2.],
447       [ 2.,  2.,  2.],
448       [ 2.,  2.,  2.],
449       [ 2.,  2.,  2.],
450       [ 2.,  2.,  2.]]), num.array([[ 2.,  2.,  2.],
451       [ 2.,  2.,  2.],
452       [ 2.,  2.,  2.],
453       [ 2.,  2.,  2.],
454       [ 2.,  2.,  2.],
455       [ 2.,  2.,  2.]]), num.array([[ 2.,  2.,  2.],
456       [ 2.,  2.,  2.],
457       [ 2.,  2.,  2.],
458       [ 2.,  2.,  2.],
459       [ 2.,  2.,  2.]])]}}
460                                 
461
462        from anuga.abstract_2d_finite_volumes.neighbour_mesh import Mesh
463       
464        mesh = Mesh(nodes, triangles)
465        boundary_polygon = mesh.get_boundary_polygon()
466
467
468        # Subdivide into non-overlapping partitions
469
470        submesh = submesh_full(nodes, triangles, edges, \
471                            triangles_per_proc)
472
473        #print submesh
474
475
476        for i in range(3):
477            assert num.allclose(true_submesh['full_triangles'][i],submesh['full_triangles'][i])
478            assert num.allclose(true_submesh['full_nodes'][i],submesh['full_nodes'][i])
479        assert true_submesh['full_boundary'] == submesh['full_boundary']
480
481        # Add any extra ghost boundary layer information
482
483        submesh = submesh_ghost(submesh, mesh, triangles_per_proc)
484
485        for i in range(3):
486            assert num.allclose(true_submesh['ghost_triangles'][i],submesh['ghost_triangles'][i])
487            assert num.allclose(true_submesh['ghost_nodes'][i],submesh['ghost_nodes'][i])
488            assert num.allclose(true_submesh['ghost_commun'][i],submesh['ghost_commun'][i])
489
490        assert true_submesh['full_commun'] == submesh['full_commun']
491
492
493        # Order the quantities information to be the same as the triangle
494        # information
495
496
497        submesh = submesh_quantities(submesh, quantities, \
498                                 triangles_per_proc)
499
500
501
502        for key, value in true_submesh['ghost_quan'].iteritems():
503            for i in range(3):
504                assert num.allclose(true_submesh['ghost_quan'][key][i],submesh['ghost_quan'][key][i])
505                assert num.allclose(true_submesh['full_quan'][key][i],submesh['full_quan'][key][i])
506       
507
508        submesh["boundary_polygon"] = boundary_polygon
509
510
511        #print submesh
512
513#-------------------------------------------------------------
514
515if __name__ == "__main__":
516    suite = unittest.makeSuite(Test_Distribute_Mesh,'test')
517    runner = unittest.TextTestRunner()
518    runner.run(suite)
Note: See TracBrowser for help on using the repository browser.