Changeset 3956
- Timestamp:
- Nov 9, 2006, 12:51:08 PM (18 years ago)
- Location:
- anuga_core/source/anuga/abstract_2d_finite_volumes
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/general_mesh.py
r3954 r3956 273 273 Default is False as many parts of ANUGA expects relative coordinates. 274 274 """ 275 276 277 278 V = self.vertex_coordinates #[:3*M,:] 275 276 V = self.vertex_coordinates 279 277 if absolute is True: 280 278 if not self.geo_reference.is_absolute(): -
anuga_core/source/anuga/abstract_2d_finite_volumes/quantity.py
r3954 r3956 16 16 17 17 from Numeric import array, zeros, Float, less, concatenate, NewAxis,\ 18 argmax, allclose 18 argmax, allclose, take, reshape 19 19 from anuga.utilities.numerical_tools import ensure_numeric, is_scalar 20 20 … … 169 169 quantity = None, # Another quantity 170 170 function = None, # Callable object: f(x,y) 171 geospatial_data = None, # Arbitrary dataset171 geospatial_data = None, # Arbitrary dataset 172 172 points = None, values = None, data_georef = None, #Input 173 173 # for fit (obsoleted by use of geo_spatial object) … … 207 207 values corresponding to 208 208 each data point must be present. 209 (Obsoleted by geospatial_data) 209 210 210 211 values: 211 212 If points is specified, values is an array of length N containing 212 213 attribute values for each point. 214 (Obsoleted by geospatial_data) 213 215 214 216 data_georef: 215 217 If points is specified, geo_reference applies to each point. 218 (Obsoleted by geospatial_data) 216 219 217 220 filename: … … 355 358 use_cache = use_cache) 356 359 else: 357 raise 'This can\'t happen :-)' 358 359 360 #Update all locations in triangles 360 raise Exception, 'This can\'t happen :-)' 361 362 363 364 # Update all locations in triangles 361 365 if location == 'vertices' or location == 'unique vertices': 362 # Intialise centroid and edge_values366 # Intialise centroid and edge_values 363 367 self.interpolate() 364 368 365 369 if location == 'centroids': 366 # Extrapolate 1st order - to capture notion of area being specified370 # Extrapolate 1st order - to capture notion of area being specified 367 371 self.extrapolate_first_order() 368 372 … … 377 381 378 382 if location == 'centroids': 379 if (indices == None):383 if indices is None: 380 384 self.centroid_values[:] = X 381 385 else: 382 386 #Brute force 383 387 for i in indices: 384 self.centroid_values[i ,:] = X388 self.centroid_values[i] = X 385 389 386 390 elif location == 'edges': 387 if (indices == None):391 if indices is None: 388 392 self.edge_values[:] = X 389 393 else: 390 394 #Brute force 391 395 for i in indices: 392 self.edge_values[i ,:] = X396 self.edge_values[i] = X 393 397 394 398 elif location == 'unique vertices': 395 if (indices == None):399 if indices is None: 396 400 self.edge_values[:] = X 397 401 else: … … 412 416 self.interpolate() 413 417 else: 414 if (indices == None):418 if indices is None: 415 419 self.vertex_values[:] = X 416 420 else: 417 421 #Brute force 418 422 for i_vertex in indices: 419 self.vertex_values[i_vertex,:] = X 420 421 423 self.vertex_values[i_vertex] = X 422 424 423 425 … … 425 427 426 428 def set_values_from_array(self, values, 427 location, indices, verbose): 429 location='vertices', 430 indices=None, 431 verbose=False): 428 432 """Set values for quantity 429 433 … … 480 484 481 485 elif location == 'edges': 486 # FIXME (Ole): No mention of indices here. However, I don't 487 # think we ever need to set values at edges anyway 482 488 assert len(values.shape) == 2, 'Values array must be 2d' 483 489 … … 495 501 496 502 self.set_vertex_values(values.flat, indices=indices) 503 497 504 else: 505 # Location vertices 498 506 if len(values.shape) == 1: 499 507 self.set_vertex_values(values, indices=indices) … … 505 513 assert values.shape[1] == 3, msg 506 514 507 if indices ==None:515 if indices is None: 508 516 self.vertex_values = values 509 517 else: … … 513 521 msg = 'Values array must be 1d or 2d' 514 522 raise msg 523 515 524 516 525 def set_values_from_quantity(self, q, … … 518 527 """Set quantity values from specified quantity instance q 519 528 520 Location is ignored 529 Location is ignored - vertices will always be used here. 521 530 """ 522 531 … … 536 545 537 546 def set_values_from_function(self, f, 538 location, indices, verbose): 547 location='vertices', 548 indices=None, 549 verbose=False): 539 550 """Set values for quantity using specified function 540 551 552 Input 553 541 554 f: x, y -> z Function where x, y and z are arrays 542 555 location: Where values are to be stored. … … 544 557 unique vertices 545 558 Default is "vertices" 559 indices: 560 561 546 562 """ 547 563 … … 551 567 #FIXME: Should supply absolute coordinates 552 568 553 from Numeric import take 554 555 if (indices is None): 556 indices = range(len(self)) 557 is_subset = False 558 else: 559 is_subset = True 560 561 562 # FIXME (Ole): Now we can compute the arrays once and for all 563 # for both centroids and vertices and the use set_values_from_array 564 569 570 # Compute the function values and call set_values again 565 571 if location == 'centroids': 566 V = take(self.domain.centroid_coordinates, indices) 567 if is_subset: 568 self.set_values(f(V[:,0], V[:,1]), 569 location = location, 570 indices = indices) 571 else: 572 self.set_values(f(V[:,0], V[:,1]), location = location) 572 if indices is None: 573 indices = range(len(self)) 574 575 V = take(self.domain.get_centroid_coordinates(), indices) 576 self.set_values(f(V[:,0], V[:,1]), 577 location=location, 578 indices=indices) 579 573 580 elif location == 'vertices': 581 582 M = self.domain.number_of_triangles 574 583 V = self.domain.get_vertex_coordinates() 575 584 … … 577 586 values = f(x, y) 578 587 588 589 # FIXME (Ole): This code should replace all the 590 # rest of this function and it would work, except 591 # one unit test in test_region fails. 592 # If that could be resolved this one will be 593 # more robust and simple. 594 595 #values = reshape(values, (M,3)) 596 #self.set_values(values, 597 # location='vertices', 598 # indices=indices) 599 600 601 # This should be removed 579 602 if is_scalar(values): 580 603 # Function returned a constant value … … 582 605 location, indices, verbose) 583 606 return 584 585 586 if is_subset: 607 608 # This should be removed 609 if indices is None: 610 for j in range(3): 611 self.vertex_values[:,j] = values[j::3] 612 else: 587 613 #Brute force 588 614 for i in indices: 589 615 for j in range(3): 590 616 self.vertex_values[i,j] = values[3*i+j] 591 else: 592 for j in range(3): 593 self.vertex_values[:,j] = values[j::3] 617 618 594 619 else: 595 620 raise 'Not implemented: %s' %location … … 973 998 assert len(A.shape) == 1 974 999 975 if indices ==None:1000 if indices is None: 976 1001 assert A.shape[0] == self.domain.get_nodes().shape[0] 977 1002 vertex_list = range(A.shape[0]) -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_quantity.py
r3945 r3956 1348 1348 quantity = Quantity(domain,[[1,1,1],[2,2,2],[3,3,3], 1349 1349 [4,4,4],[5,5,5],[6,6,6]]) 1350 1351 1352 # Check that constants work 1353 value = 7 1354 indices = [1] 1355 quantity.set_values(value, 1356 location = 'centroids', 1357 indices = indices) 1358 #print "quantity.centroid_values",quantity.centroid_values 1359 assert allclose(quantity.centroid_values, [1,7,3,4,5,6]) 1360 1350 1361 value = [7] 1351 1362 indices = [1]
Note: See TracChangeset
for help on using the changeset viewer.