Changeset 275
- Timestamp:
- Sep 6, 2004, 5:49:21 PM (20 years ago)
- Location:
- inundation/ga/storm_surge/pyvolution
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/mesh.py
r274 r275 60 60 from Numeric import array, zeros, Int, Float, maximum, sqrt, sum 61 61 62 #Only one of them63 62 self.vertices = array(vertices).astype(Int) 64 63 self.coordinates = array(coordinates) 65 66 64 67 65 #Input checks … … 270 268 c = self.vertices[i, 2] 271 269 272 #Register the vertices as keys mapping to273 #(triangle , edge) tuples associated with them270 #Register the vertices v as lists of 271 #(triangle_id, vertex_id) tuples associated with them 274 272 #This is used for smoothing 275 273 for vertex_id, v in enumerate([a,b,c]): … … 526 524 """ 527 525 526 #FIXME: Perhaps they should be ordered as in obj files?? 527 #See quantity.get_vertex_values 528 528 529 from Numeric import zeros, Float 529 530 -
inundation/ga/storm_surge/pyvolution/quantity.py
r274 r275 54 54 self.interpolate() 55 55 56 56 def __len__(self): 57 return self.centroid_values.shape[0] 58 57 59 def interpolate(self): 58 60 """Compute interpolated values at edges and centroid … … 206 208 TODO: be able to smooth individual fields 207 209 NOTE: This function does not have a test. 210 FIXME: NOT DONE 208 211 """ 209 212 … … 276 279 277 280 if smooth == True: 278 M = len(self.domain.vertexlist) #Number of unique vertices 279 280 A = zeros((M,N), precision) 281 V = zeros((len(self),3), Int) 282 283 #Rebuild triangle structure 284 for k, v in enumerate(self.vertexdict.keys()): 285 for volume_id, vertex_id in self.vertexdict[v]: 286 V[volume_id, vertex_id] = k 287 288 281 282 N = len(self.domain.vertexlist) 283 A = zeros(N, precision) 284 V = self.domain.vertices 285 289 286 #Smoothing loop 290 for j, i in enumerate(indices): 291 #For each quantity 292 # 293 #j is an index into returned quantities (0 <= j < N) 294 #i the given index into internal quantities 295 #(e.g. 0: bed elevation or 1: friction) 296 297 for k, v in enumerate(self.vertexdict.keys()): 298 #Go through all contributions to vertex v 299 #k is an index into returned vertices (0 <= k < M) 300 #v is an index into internal vertices 301 302 L = len(self.vertexdict[v]) 303 304 ulist = [] 305 for volume_id, vertex_id in self.vertexdict[v]: 306 #For all contributing triange, vertex pairs 307 308 cmd = 'u = Volume.%s_vertex%d[%d,%d]'\ 309 %(value_array, vertex_id, volume_id, i) 310 exec(cmd) 311 ulist.append(u) 312 313 A[k,j] = reduction(ulist) 287 for k in range(N): 288 L = self.domain.vertexlist[k] 289 290 #Go through all triangle, vertex pairs 291 #contributing to vertex k and register vertex value 292 contributions = [] 293 for volume_id, vertex_id in L: 294 295 v = self.vertex_values[volume_id, vertex_id] 296 contributions.append(v) 297 298 A[k] = reduction(contributions) 314 299 315 300 316 301 if xy is True: 317 X = zeros(M, precision) 318 Y = zeros(M, precision) 319 320 for k, v in enumerate(self.vertexdict.keys()): 321 X[k], Y[k] = Point.coordinates[v].astype(precision) 322 302 X = self.domain.coordinates[:,0] 303 Y = self.domain.coordinates[:,1] 323 304 return X, Y, A, V 324 305 else: … … 338 319 #Do vertex coordinates 339 320 if xy is True: 340 V= self.domain.get_vertex_coordinates()341 X = concatenate((V[:,0], V[:,2], V[:,4]), axis=0).\ 342 astype(precision)343 Y = concatenate((V[:,1], V[:,3], V[:,5]), axis=0).\344 astype(precision) 321 C = self.domain.get_vertex_coordinates() 322 323 X = C[:,0:6:2].copy() 324 Y = C[:,1:6:2].copy() 325 345 326 346 return X , Y, A, V327 return X.flat, Y.flat, A, V 347 328 else: 348 329 return A, V -
inundation/ga/storm_surge/pyvolution/test_quantity.py
r274 r275 407 407 408 408 409 410 411 #Test smoothing 412 def test_smoothing(self): 413 414 from mesh_factory import rectangular 415 from shallow_water import Domain, Transmissive_boundary 416 from Numeric import zeros, Float 417 from util import mean 418 419 #Create basic mesh 420 points, vertices, boundary = rectangular(2, 2) 421 422 #Create shallow water domain 423 domain = Domain(points, vertices, boundary) 424 domain.default_order=2 425 domain.reduction = mean 426 427 428 #Set some field values 429 domain.set_quantity('elevation', lambda x,y: x) 430 domain.set_quantity('friction', 0.03) 431 432 433 ###################### 434 # Boundary conditions 435 B = Transmissive_boundary(domain) 436 domain.set_boundary( {'left': B, 'right': B, 'top': B, 'bottom': B}) 437 438 439 ###################### 440 #Initial condition - with jumps 441 442 bed = domain.quantities['elevation'].vertex_values 443 level = zeros(bed.shape, Float) 444 445 h = 0.03 446 for i in range(level.shape[0]): 447 if i % 2 == 0: 448 level[i,:] = bed[i,:] + h 449 else: 450 level[i,:] = bed[i,:] 451 452 domain.set_quantity('level', level) 453 454 level = domain.quantities['level'] 455 456 #Get smoothed level 457 A, V = level.get_vertex_values(xy=False, smooth=True) 458 Q = level.vertex_values 459 460 #First four points 461 assert allclose(A[0], (Q[0,2] + Q[1,1])/2) 462 assert allclose(A[1], (Q[1,0] + Q[3,1] + Q[2,2])/3) 463 assert allclose(A[2], Q[3,0]) 464 assert allclose(A[3], (Q[0,0] + Q[5,1] + Q[4,2])/3) 465 466 #Center point 467 assert allclose(A[4], (Q[0,1] + Q[1,2] + Q[2,0] +\ 468 Q[5,0] + Q[6,2] + Q[7,1])/6) 469 470 471 #Check V 472 assert allclose(V[0,:], [3,4,0]) 473 assert allclose(V[1,:], [1,0,4]) 474 assert allclose(V[2,:], [4,5,1]) 475 assert allclose(V[3,:], [2,1,5]) 476 assert allclose(V[4,:], [6,7,3]) 477 assert allclose(V[5,:], [4,3,7]) 478 assert allclose(V[6,:], [7,8,4]) 479 assert allclose(V[7,:], [5,4,8]) 480 481 #Get smoothed level with XY 482 X, Y, A1, V1 = level.get_vertex_values(xy=True, smooth=True) 483 484 assert allclose(A, A1) 485 assert allclose(V, V1) 486 487 #Check XY 488 assert allclose(X[4], 0.5) 489 assert allclose(Y[4], 0.5) 490 491 assert allclose(X[7], 1.0) 492 assert allclose(Y[7], 0.5) 493 494 495 496 497 def test_vertex_values_no_smoothing(self): 498 499 from mesh_factory import rectangular 500 from shallow_water import Domain, Transmissive_boundary 501 from Numeric import zeros, Float 502 from util import mean 503 504 505 #Create basic mesh 506 points, vertices, boundary = rectangular(2, 2) 507 508 #Create shallow water domain 509 domain = Domain(points, vertices, boundary) 510 domain.default_order=2 511 domain.reduction = mean 512 513 514 #Set some field values 515 domain.set_quantity('elevation', lambda x,y: x) 516 domain.set_quantity('friction', 0.03) 517 518 #Get level 519 level = domain.quantities['level'] 520 A, V = level.get_vertex_values(xy=False, smooth=False) 521 Q = level.vertex_values 522 523 for k in range(8): 524 assert allclose(A[k], Q[k]) 525 526 X, Y, A1, V1 = level.get_vertex_values(xy=True, smooth=False) 527 528 529 assert allclose(A, A1) 530 assert allclose(V, V1) 531 532 #Check XY 533 assert allclose(X[1], 0.5) 534 assert allclose(Y[1], 0.5) 535 536 assert allclose(X[4], 0.0) 537 assert allclose(Y[4], 0.0) 538 539 assert allclose(X[12], 1.0) 540 assert allclose(Y[12], 0.0) 541 542 543 544 409 545 410 546 #-------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.