Changeset 1424
- Timestamp:
- May 18, 2005, 5:36:32 PM (20 years ago)
- Location:
- inundation/ga/storm_surge
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/parallel/advection.py
r1407 r1424 33 33 34 34 35 Generic_domain.__init__(self, coordinates, vertices, boundary, 36 ['stage']) 35 Generic_domain.__init__(self, coordinates, vertices, boundary,['stage']) 37 36 38 37 if velocity is None: -
inundation/ga/storm_surge/parallel/parallel_advection.py
r1414 r1424 16 16 from advection import * 17 17 Advection_Domain = Domain 18 from Numeric import zeros, Float, Int, ones, allclose, 18 from Numeric import zeros, Float, Int, ones, allclose, array 19 19 import pypar 20 20 … … 22 22 class Parallel_Domain(Advection_Domain): 23 23 24 def __init__(self, coordinates, vertices, boundary = None, ghosts = None, 24 def __init__(self, coordinates, vertices, boundary = None, 25 full_send_dict = None, ghost_recv_dict = None, 25 26 velocity = None): 26 27 Advection_Domain.__init__(self, coordinates, vertices, boundary, velocity)28 29 N = self.number_of_elements30 27 31 28 self.processor = pypar.rank() 32 29 self.numproc = pypar.size() 33 34 if ghosts == None: 35 self.ghosts = None 36 self.full = ones( N, Float) 37 else: 38 self.ghosts = ghosts 39 self.full = ones( N, Int) 40 keys = self.ghosts.keys() 41 for key in keys: 42 self.full[key] = -1 43 44 45 30 print 'Processor %d'%self.processor 31 velocity = [(self.processor+1),0.0] 32 33 print 'velocity',velocity 34 35 Advection_Domain.__init__(self, coordinates, vertices, boundary, velocity) 36 37 N = self.number_of_elements 38 39 self.processor = pypar.rank() 40 self.numproc = pypar.size() 41 42 self.full_send_dict = full_send_dict 43 self.ghost_recv_dict = ghost_recv_dict 44 45 #print self.full_send_dict 46 #print self.ghost_recv_dict 46 47 47 48 def check_integrity(self): … … 67 68 pypar.raw_reduce(ltimestep, gtimestep, pypar.MIN, 0) 68 69 pypar.broadcast(gtimestep,0) 69 pypar.Barrier()70 #pypar.Barrier() 70 71 71 72 self.timestep = gtimestep[0] … … 82 83 stage_cv = self.quantities['stage'].centroid_values 83 84 84 # for iproc in full_send_dict: 85 # Ids = full_send_dict[iproc][0] 86 # X = full_send_dict[iproc][1] 87 # for i _ in enumerate(X): 88 # X[i] = stage_cv[Ids[i]] 89 # pypar.send(X,iproc) 85 # update of non-local ghost cells 86 # for iproc in range(self.numproc): 90 87 # 91 # for iproc in ghost_recv_dict: 92 # Ids = ghost_recv_dict[iproc][0] 93 # X = ghost_recv_dict[iproc][1] 94 # X = pypar.receive(iproc,X) 95 # for i _ in enumerate(X): 96 # stage_cv[Ids[i]] = X[i] 97 98 99 if self.ghosts is not None: 100 stage_cv = self.quantities['stage'].centroid_values 101 for triangle in self.ghosts: 102 stage_cv[triangle] = stage_cv[self.ghosts[triangle]] 88 # if iproc == self.processor: 89 # #Send data from iproc processor to other processors 90 # for send_proc in full_send_dict: 91 # if send_proc != iproc: 92 # Idf = full_send_dict[iproc][0] 93 # Xout = full_send_dict[iproc][1] 94 # for i _ in enumerate(X): 95 # Xout[i] = stage_cv[Idf[i]] 96 # pypar.send(Xout,send_proc) 97 # else: 98 # #Receive data from the iproc processor 99 # if ghost_recv_dict.has_key(iproc): 100 # Idg = ghost_recv_dict[iproc][0] 101 # X = ghost_recv_dict[iproc][1] 102 # X = pypar.receive(iproc,X) 103 # for i _ in enumerate(X): 104 # stage_cv[Idg[i]] = X[i] 105 106 #local update of ghost cells 107 iproc = self.processor 108 if self.full_send_dict.has_key(iproc): 109 Idf = self.full_send_dict[iproc][0] 110 #print Idf 111 Idg = self.ghost_recv_dict[iproc][0] 112 #print Idg 113 for i, _ in enumerate(Idf): 114 #print i,Idg[i],Idf[i] 115 stage_cv[Idg[i]] = stage_cv[Idf[i]] 116 117 118 # if self.ghosts is not None: 119 # stage_cv = self.quantities['stage'].centroid_values 120 # for triangle in self.ghosts: 121 # stage_cv[triangle] = stage_cv[self.ghosts[triangle]] 103 122 104 123 … … 137 156 138 157 139 def Parallel_rectangular(m, n, len1=1.0, len2=1.0, origin = (0.0, 0.0)):158 def parallel_rectangular(m, n, len1=1.0, len2=1.0, origin = (0.0, 0.0)): 140 159 141 160 … … 149 168 len2: y direction (bottom to top) 150 169 170 """ 171 172 from config import epsilon 173 from Numeric import zeros, Float, Int 174 175 processor = pypar.rank() 176 numproc = pypar.size() 177 178 179 180 delta1 = float(len1)/m 181 delta2 = float(len2)/n 182 183 #Calculate number of points 184 Np = (m+1)*(n+1) 185 186 class VIndex: 187 188 def __init__(self, n,m): 189 self.n = n 190 self.m = m 191 192 def __call__(self, i,j): 193 return j+i*(self.n+1) 194 195 class EIndex: 196 197 def __init__(self, n,m): 198 self.n = n 199 self.m = m 200 201 def __call__(self, i,j): 202 return 2*(j+i*self.n) 203 204 205 I = VIndex(n,m) 206 E = EIndex(n,m) 207 208 points = zeros( (Np,2), Float) 209 210 for i in range(m+1): 211 for j in range(n+1): 212 213 points[I(i,j),:] = [i*delta1 + origin[0], j*delta2 + origin[1]] 214 215 #Construct 2 triangles per rectangular element and assign tags to boundary 216 #Calculate number of triangles 217 Nt = 2*m*n 218 219 220 elements = zeros( (Nt,3), Int) 221 boundary = {} 222 Idg = [] 223 Xg = [] 224 Idf = [] 225 Xf = [] 226 227 full_send_dict = {} 228 ghost_recv_dict = {} 229 nt = -1 230 for i in range(m): 231 for j in range(n): 232 233 i1 = I(i,j+1) 234 i2 = I(i,j) 235 i3 = I(i+1,j+1) 236 i4 = I(i+1,j) 237 238 #Lower Element 239 nt = E(i,j) 240 if i == m-1: 241 #print 'nt =',nt 242 Idg.append(nt) 243 Idf.append(E(1,j)) 244 if i == 0: 245 Idg.append(nt) 246 Idf.append(E(m-2,j)) 247 248 if i == m-1: 249 boundary[nt, 2] = 'right' 250 if j == 0: 251 boundary[nt, 1] = 'bottom' 252 elements[nt,:] = [i4,i3,i2] 253 254 #Upper Element 255 nt = E(i,j)+1 256 if i == m-1: 257 Idg.append(nt) 258 Idf.append(E(1,j)+1) 259 if i == 0: 260 Idg.append(nt) 261 Idf.append(E(m-2,j)+1) 262 263 if i == 0: 264 boundary[nt, 2] = 'left' 265 if j == n-1: 266 boundary[nt, 1] = 'top' 267 elements[nt,:] = [i1,i2,i3] 268 269 Idf = array(Idf,Int) 270 Idg = array(Idg,Int) 271 Xf = zeros(Idf.shape,Float) 272 Xg = zeros(Idg.shape,Float) 273 274 #print Idf 275 #print Idg 276 full_send_dict[processor] = [Idf, Xf] 277 ghost_recv_dict[processor] = [Idg, Xg] 278 279 return points, elements, boundary, full_send_dict, ghost_recv_dict 280 281 282 283 def rectangular_periodic(m, n, len1=1.0, len2=1.0, origin = (0.0, 0.0)): 284 285 286 """Setup a rectangular grid of triangles 287 with m+1 by n+1 grid points 288 and side lengths len1, len2. If side lengths are omitted 289 the mesh defaults to the unit square. 290 291 len1: x direction (left to right) 292 len2: y direction (bottom to top) 293 294 Return to lists: points and elements suitable for creating a Mesh or 295 FVMesh object, e.g. Mesh(points, elements) 151 296 """ 152 297 … … 213 358 ghosts[nt] = E(m-2,j) 214 359 360 if j == n-1: 361 ghosts[nt] = E(i,1) 362 363 if j == 0: 364 ghosts[nt] = E(i,n-2) 365 215 366 if i == m-1: 216 367 boundary[nt, 2] = 'right' … … 226 377 ghosts[nt] = E(m-2,j)+1 227 378 379 if j == n-1: 380 ghosts[nt] = E(i,1)+1 381 382 if j == 0: 383 ghosts[nt] = E(i,n-2)+1 384 228 385 if i == 0: 229 386 boundary[nt, 2] = 'left' … … 232 389 elements[nt,:] = [i1,i2,i3] 233 390 391 #bottom left 392 nt = E(0,0) 393 nf = E(m-2,n-2) 394 ghosts[nt] = nf 395 ghosts[nt+1] = nf+1 396 397 #bottom right 398 nt = E(m-1,0) 399 nf = E(1,n-2) 400 ghosts[nt] = nf 401 ghosts[nt+1] = nf+1 402 403 #top left 404 nt = E(0,n-1) 405 nf = E(m-2,1) 406 ghosts[nt] = nf 407 ghosts[nt+1] = nf+1 408 409 #top right 410 nt = E(m-1,n-1) 411 nf = E(1,1) 412 ghosts[nt] = nf 413 ghosts[nt+1] = nf+1 234 414 235 415 return points, elements, boundary, ghosts 236 416 237 def rectangular_periodic (m, n, len1=1.0, len2=1.0, origin = (0.0, 0.0)):417 def rectangular_periodic_lr(m, n, len1=1.0, len2=1.0, origin = (0.0, 0.0)): 238 418 239 419 … … 247 427 248 428 Return to lists: points and elements suitable for creating a Mesh or 249 FVMeshobject, e.g. Mesh(points, elements)429 Domain object, e.g. Mesh(points, elements) 250 430 """ 251 431 … … 312 492 ghosts[nt] = E(m-2,j) 313 493 314 if j == n-1:315 ghosts[nt] = E(i,1)316 317 if j == 0:318 ghosts[nt] = E(i,n-2)319 320 494 if i == m-1: 321 495 boundary[nt, 2] = 'right' … … 331 505 ghosts[nt] = E(m-2,j)+1 332 506 333 if j == n-1:334 ghosts[nt] = E(i,1)+1335 336 if j == 0:337 ghosts[nt] = E(i,n-2)+1338 339 507 if i == 0: 340 508 boundary[nt, 2] = 'left' … … 343 511 elements[nt,:] = [i1,i2,i3] 344 512 345 #bottom left346 nt = E(0,0)347 nf = E(m-2,n-2)348 ghosts[nt] = nf349 ghosts[nt+1] = nf+1350 351 #bottom right352 nt = E(m-1,0)353 nf = E(1,n-2)354 ghosts[nt] = nf355 ghosts[nt+1] = nf+1356 357 #top left358 nt = E(0,n-1)359 nf = E(m-2,1)360 ghosts[nt] = nf361 ghosts[nt+1] = nf+1362 363 #top right364 nt = E(m-1,n-1)365 nf = E(1,1)366 ghosts[nt] = nf367 ghosts[nt+1] = nf+1368 513 369 514 return points, elements, boundary, ghosts 370 371 def rectangular_periodic_lr(m, n, len1=1.0, len2=1.0, origin = (0.0, 0.0)):372 373 374 """Setup a rectangular grid of triangles375 with m+1 by n+1 grid points376 and side lengths len1, len2. If side lengths are omitted377 the mesh defaults to the unit square.378 379 len1: x direction (left to right)380 len2: y direction (bottom to top)381 382 Return to lists: points and elements suitable for creating a Mesh or383 Domain object, e.g. Mesh(points, elements)384 """385 386 from config import epsilon387 from Numeric import zeros, Float, Int388 389 delta1 = float(len1)/m390 delta2 = float(len2)/n391 392 #Calculate number of points393 Np = (m+1)*(n+1)394 395 class VIndex:396 397 def __init__(self, n,m):398 self.n = n399 self.m = m400 401 def __call__(self, i,j):402 return j+i*(self.n+1)403 404 class EIndex:405 406 def __init__(self, n,m):407 self.n = n408 self.m = m409 410 def __call__(self, i,j):411 return 2*(j+i*self.n)412 413 414 I = VIndex(n,m)415 E = EIndex(n,m)416 417 points = zeros( (Np,2), Float)418 419 for i in range(m+1):420 for j in range(n+1):421 422 points[I(i,j),:] = [i*delta1 + origin[0], j*delta2 + origin[1]]423 424 #Construct 2 triangles per rectangular element and assign tags to boundary425 #Calculate number of triangles426 Nt = 2*m*n427 428 429 elements = zeros( (Nt,3), Int)430 boundary = {}431 ghosts = {}432 nt = -1433 for i in range(m):434 for j in range(n):435 436 i1 = I(i,j+1)437 i2 = I(i,j)438 i3 = I(i+1,j+1)439 i4 = I(i+1,j)440 441 #Lower Element442 nt = E(i,j)443 if i == m-1:444 ghosts[nt] = E(1,j)445 if i == 0:446 ghosts[nt] = E(m-2,j)447 448 if i == m-1:449 boundary[nt, 2] = 'right'450 if j == 0:451 boundary[nt, 1] = 'bottom'452 elements[nt,:] = [i4,i3,i2]453 454 #Upper Element455 nt = E(i,j)+1456 if i == m-1:457 ghosts[nt] = E(1,j)+1458 if i == 0:459 ghosts[nt] = E(m-2,j)+1460 461 if i == 0:462 boundary[nt, 2] = 'left'463 if j == n-1:464 boundary[nt, 1] = 'top'465 elements[nt,:] = [i1,i2,i3]466 467 468 return points, elements, boundary, ghosts -
inundation/ga/storm_surge/parallel/run_parallel_advection.py
r1414 r1424 20 20 M = 30 21 21 22 points, vertices, boundary, ghosts = rectangular_periodic(N, M)22 points, vertices, boundary, full_send_dict, ghost_recv_dict = parallel_rectangular(N, M) 23 23 24 24 #Create advection domain with direction (1,-1) 25 domain = Parallel_Domain(points, vertices, boundary, ghosts, velocity=[1.0, 0.0]) 25 domain = Parallel_Domain(points, vertices, boundary, 26 full_send_dict, ghost_recv_dict, velocity=[1.0, 0.0]) 26 27 27 28 # Initial condition is zero by default
Note: See TracChangeset
for help on using the changeset viewer.