Changeset 2055
- Timestamp:
- Nov 24, 2005, 10:21:05 AM (19 years ago)
- Location:
- inundation/parallel
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/parallel/pmesh_divide.py
r1585 r2055 20 20 21 21 from math import floor 22 from Numeric import zeros, Float, Int 22 from Numeric import zeros, Float, Int, reshape 23 23 24 24 ######################################################### … … 151 151 for i in range(N): 152 152 q_reord[k][index[i]]=quantities[k].vertex_values[i] 153 154 153 del index 155 154 … … 268 267 tri_index = {} 269 268 N = domain.number_of_elements 270 269 271 270 #sort by x coordinate of centroid 272 271 from Numeric import argsort … … 286 285 287 286 #print tri_list 288 289 287 #print tri_index 290 288 … … 321 319 322 320 return nodes, triangles, boundary, triangles_per_proc, quantities 321 322 323 from os import sep 324 from sys import path 325 326 path.append('..' + sep + 'pymetis') 327 328 from metis import partMeshNodal 329 330 def pmesh_divide_metis(domain, n_procs): 331 # initialise the lists 332 triangles_per_proc = [] 333 tri_list = [] 334 proc_sum = [] 335 for i in range(n_procs): 336 tri_list.append([]) 337 triangles_per_proc.append(0) 338 proc_sum.append([]) 339 340 # Prepare variables for the metis call 341 n_tri = len(domain.triangles) 342 n_vert = len(domain.coordinates) 343 t_list = domain.triangles.copy() 344 t_list = reshape(t_list, (-1,)) 345 346 # The 1 here is for triangular mesh elements. 347 edgecut, epart, npart = partMeshNodal(n_tri, n_vert, t_list, 1, n_procs) 348 349 # print edgecut 350 # print epart 351 # print npart 352 353 del edgecut 354 del npart 355 356 # Assign triangles to processes, according to what metis told us. 357 358 tri_index = {} 359 triangles = [] 360 for i in range(n_tri): 361 triangles_per_proc[epart[i]] = triangles_per_proc[epart[i]] + 1 362 tri_list[epart[i]].append(domain.triangles[i]) 363 tri_index[i] = ([epart[i], len(tri_list[epart[i]]) - 1]) 364 365 # print tri_list 366 # print triangles_per_proc 367 368 # order the triangle list so that all of the triangles belonging 369 # to processor i are listed before those belonging to processor 370 # i+1 371 372 for i in range(n_procs): 373 for t in tri_list[i]: 374 triangles.append(t) 375 376 # the boundary labels have to changed in accoradance with the 377 # new triangle ordering, proc_sum and tri_index help with this 378 379 proc_sum[0] = 0 380 for i in range(n_procs - 1): 381 proc_sum[i+1]=proc_sum[i]+triangles_per_proc[i] 382 383 # relabel the boundary elements to fit in with the new triangle 384 # ordering 385 386 boundary = {} 387 for b in domain.boundary: 388 t = tri_index[b[0]] 389 boundary[proc_sum[t[0]]+t[1], b[1]] = domain.boundary[b] 390 391 quantities = reorder(domain.quantities, tri_index, proc_sum) 392 393 # extract the node list 394 nodes = domain.coordinates.copy() 395 396 return nodes, triangles, boundary, triangles_per_proc, quantities
Note: See TracChangeset
for help on using the changeset viewer.