Changeset 6221 for anuga_core/source
- Timestamp:
- Jan 21, 2009, 4:32:32 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/quantity.py
r6197 r6221 22 22 from anuga.config import points_file_block_line_size as default_block_line_size 23 23 from anuga.config import epsilon 24 24 from anuga.caching import cache 25 25 26 26 … … 424 424 425 425 if smooth: 426 self.smooth_vertex_values() 426 self.smooth_vertex_values(use_cache=use_cache, 427 verbose=verbose) 427 428 428 429 … … 464 465 elif type(numeric) in [num.ArrayType, ListType]: 465 466 self.set_values_from_array(numeric, 466 location, indices, verbose) 467 location, indices, 468 use_cache=use_cache, 469 verbose=verbose) 467 470 elif callable(numeric): 468 471 self.set_values_from_function(numeric, 469 location, indices, verbose) 472 location, indices, 473 use_cache=use_cache, 474 verbose=verbose) 470 475 elif isinstance(numeric, Quantity): 471 476 self.set_values_from_quantity(numeric, 472 location, indices, verbose) 477 location, indices, 478 verbose=verbose) 473 479 elif isinstance(numeric, Geospatial_data): 474 480 self.set_values_from_geospatial_data(numeric, … … 488 494 assert callable(function), msg 489 495 self.set_values_from_function(function, 490 location, indices, verbose) 496 location, 497 indices, 498 use_cache=use_cache, 499 verbose=verbose) 491 500 elif geospatial_data is not None: 492 501 self.set_values_from_geospatial_data(geospatial_data, … … 587 596 location='vertices', 588 597 indices=None, 598 use_cache=False, 589 599 verbose=False): 590 600 """Set values for quantity … … 645 655 'Values array must be 1d' 646 656 647 self.set_vertex_values(values.flat, indices=indices) 657 self.set_vertex_values(values.flat, 658 indices=indices, 659 use_cache=use_cache, 660 verbose=verbose) 648 661 649 662 else: 650 663 # Location vertices 651 664 if len(values.shape) == 1: 652 self.set_vertex_values(values, indices=indices) 665 # This is the common case arising from fitted 666 # values (e.g. from pts file). 667 self.set_vertex_values(values, 668 indices=indices, 669 use_cache=use_cache, 670 verbose=verbose) 653 671 654 672 elif len(values.shape) == 2: … … 691 709 location='vertices', 692 710 indices=None, 711 use_cache=False, 693 712 verbose=False): 694 713 """Set values for quantity using specified function … … 718 737 719 738 V = num.take(self.domain.get_centroid_coordinates(), indices) 720 self.set_values(f(V[:,0], V[:,1]), 739 740 x = V[:,0]; y = V[:,1] 741 if use_cache is True: 742 res = cache(f, (x, y), 743 verbose=verbose) 744 else: 745 res = f(x, y) 746 747 self.set_values(res, 721 748 location=location, 722 749 indices=indices) 723 750 724 751 elif location == 'vertices': 725 752 # This is the default branch taken by set_quantity 753 726 754 M = self.domain.number_of_triangles 727 755 V = self.domain.get_vertex_coordinates() 728 756 729 x = V[:,0]; y = V[:,1]; 730 values = f(x, y) 731 757 x = V[:,0]; y = V[:,1] 758 if use_cache is True: 759 #print 'Caching function' 760 values = cache(f, (x, y), 761 verbose=verbose) 762 else: 763 if verbose is True: 764 print 'Evaluating function in set_values' 765 values = f(x, y) 766 767 #print 'value', min(x), max(x), min(y), max(y), max(values), len(values) 768 732 769 733 770 # FIXME (Ole): This code should replace all the … … 818 855 # Call underlying method using array values 819 856 self.set_values_from_array(vertex_attributes, 820 location, indices, verbose) 857 location, indices, 858 use_cache=use_cache, 859 verbose=verbose) 821 860 822 861 … … 886 925 887 926 # Call underlying method using array values 927 if verbose: 928 print 'Applying fitted data to domain' 888 929 self.set_values_from_array(vertex_attributes, 889 location, indices, verbose) 930 location, indices, 931 use_cache=use_cache, 932 verbose=verbose) 890 933 891 934 … … 1186 1229 1187 1230 1188 def set_vertex_values(self, A, indices = None): 1231 def set_vertex_values(self, A, 1232 indices=None, 1233 use_cache=False, 1234 verbose=False): 1189 1235 """Set vertex values for all unique vertices based on input array A 1190 1236 which has one entry per unique vertex, i.e. … … 1210 1256 vertex_list = indices 1211 1257 1212 # Go through list of unique vertices 1258 1259 #FIXME(Ole): This function ought to be faster. 1260 # We need to get the triangles_and_vertices list 1261 # from domain in one hit, then cache the computation of the 1262 # Nx3 array of vertex values that can then be assigned using 1263 # set_values_from_array. 1264 # 1265 # Alternatively, some C code would be handy 1266 # 1267 self._set_vertex_values(vertex_list, A) 1268 1269 1270 def _set_vertex_values(self, vertex_list, A): 1271 """Go through list of unique vertices 1272 This is the common case e.g. when values 1273 are obtained from a pts file through fitting 1274 """ 1275 1213 1276 for i_index, unique_vert_id in enumerate(vertex_list): 1214 1215 1277 1216 1278 triangles = self.domain.get_triangles_and_vertices_per_node(node=unique_vert_id) … … 1228 1290 1229 1291 1230 def smooth_vertex_values(self): 1292 def smooth_vertex_values(self, 1293 use_cache=False, 1294 verbose=False): 1231 1295 """ Smooths vertex values. 1232 1296 """ 1233 1297 1234 1298 A,V = self.get_vertex_values(xy=False, smooth=True) 1235 self.set_vertex_values(A) 1299 self.set_vertex_values(A, 1300 use_cache=use_cache, 1301 verbose=verbose) 1302 1236 1303 1237 1304
Note: See TracChangeset
for help on using the changeset viewer.