Changeset 7459 for anuga_core/source/anuga_parallel/test_distribute_mesh.py
- Timestamp:
- Sep 1, 2009, 6:22:08 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga_parallel/test_distribute_mesh.py
r7449 r7459 40 40 41 41 def test_pmesh_1(self): 42 42 """ 43 test distributing with just one processor 44 """ 45 43 46 points, vertices, boundary = rectangular_cross(2,2) 44 47 … … 81 84 82 85 def test_pmesh_2(self): 83 86 """ 87 Test 2 way pmesh 88 """ 84 89 points, vertices, boundary = rectangular_cross(2,2) 85 90 … … 121 126 122 127 123 def test_distibute_3(self):124 """125 Do a parallel test of distributing a rectangle onto 3 processors126 """127 128 import pypar129 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 elevation143 domain.set_quantity('friction', 0.0) # Constant friction144 domain.set_quantity('stage', expression='elevation') # Dry initial stage145 domain.set_quantity('xmomentum', expression='friction + 2.0') #146 domain.set_quantity('ymomentum', ycoord) #147 148 #----------------------------------------------------------------------------------149 # Test pmesh_divide_metis150 #----------------------------------------------------------------------------------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_submesh167 #----------------------------------------------------------------------------------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_submesh268 #----------------------------------------------------------------------------------269 for p in range(1, numprocs):270 send_submesh(submesh, triangles_per_proc, p, verbose=False)271 272 #----------------------------------------------------------------------------------273 # Test extract_hostmesh274 #----------------------------------------------------------------------------------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_proc297 298 else:299 #----------------------------------------------------------------------------------300 # Test rec_submesh301 #----------------------------------------------------------------------------------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 128 344 129 def test_build_submesh_3(self): 345 130 """ 131 Test 3 way build_submesh 132 """ 346 133 347 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]]
Note: See TracChangeset
for help on using the changeset viewer.