Changeset 1751
- Timestamp:
- Aug 24, 2005, 11:57:09 AM (19 years ago)
- Location:
- inundation/pyvolution
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/pyvolution/combine_pts.py
r1423 r1751 148 148 #print "extent",extent 149 149 150 #get a list of in point ind exes150 #get a list of in point indices 151 151 #FIXME closed doesn't seems to work here. 152 152 inside_indices = inside_polygon(points['pointlist'], -
inundation/pyvolution/domain.py
r1697 r1751 144 144 X, 145 145 location='vertices', 146 ind exes = None):146 indices = None): 147 147 """Set values for named quantity 148 148 … … 156 156 of elements. Otherwise it must be of dimension Nx3. 157 157 158 Ind exes is the set of element ids that the operation applies to158 Indices is the set of element ids that the operation applies to 159 159 160 160 The values will be stored in elements following their … … 197 197 self.quantities[name].set_values(X, 198 198 location, 199 ind exes = indexes)200 201 202 203 def get_quantity(self, name, location='vertices', ind exes = None):199 indices = indices) 200 201 202 203 def get_quantity(self, name, location='vertices', indices = None): 204 204 """Get values for named quantity 205 205 … … 210 210 of elements. Otherwise it must be of dimension Nx3. 211 211 212 Ind exes is the set of element ids that the operation applies to.212 Indices is the set of element ids that the operation applies to. 213 213 214 214 The values will be stored in elements following their … … 216 216 """ 217 217 218 return self.quantities[name].get_values( location, ind exes = indexes)218 return self.quantities[name].get_values( location, indices = indices) 219 219 220 220 -
inundation/pyvolution/general_mesh.py
r1680 r1751 226 226 return vertex_coordinates 227 227 228 def get_vertices(self, ind exes=None):228 def get_vertices(self, indices=None): 229 229 """Get connectivity 230 ind exes is the set of element ids of interest230 indices is the set of element ids of interest 231 231 """ 232 232 233 233 from Numeric import take 234 234 235 if (ind exes == None):236 ind exes = range(len(self)) #len(self)=number of elements237 238 return take(self.triangles, ind exes)235 if (indices == None): 236 indices = range(len(self)) #len(self)=number of elements 237 238 return take(self.triangles, indices) 239 239 240 240 #FIXME - merge these two … … 260 260 261 261 262 def get_unique_vertices(self, ind exes=None):263 triangles = self.get_vertices(ind exes=indexes)262 def get_unique_vertices(self, indices=None): 263 triangles = self.get_vertices(indices=indices) 264 264 unique_verts = {} 265 265 for triangle in triangles: -
inundation/pyvolution/netherlands.py
r1697 r1751 169 169 for t in domain.evolve(yieldstep = 0.02, finaltime = 15.0): 170 170 domain.write_time() 171 print domain.quantities['stage'].get_values(location='centroids',indexes=[0]) 171 print domain.quantities['stage'].get_values(location='centroids', 172 indices=[0]) 172 173 #V.update_quantity('stage') 173 174 #rpdb.set_active() -
inundation/pyvolution/quantity.py
r1750 r1751 236 236 from Numeric import take 237 237 238 if (ind exes is None):239 ind exes = range(len(self))238 if (indices is None): 239 indices = range(len(self)) 240 240 is_subset = False 241 241 else: 242 242 is_subset = True 243 243 if location == 'centroids': 244 P = take(self.domain.centroid_coordinates,ind exes)244 P = take(self.domain.centroid_coordinates,indices) 245 245 if is_subset: 246 self.set_values(f(P[:,0], P[:,1]), location, ind exes = indexes)246 self.set_values(f(P[:,0], P[:,1]), location, indices = indices) 247 247 else: 248 248 self.set_values(f(P[:,0], P[:,1]), location) … … 251 251 if is_subset: 252 252 #Brute force 253 for e in ind exes:253 for e in indices: 254 254 for i in range(3): 255 255 self.vertex_values[e,i] = f(P[e,2*i], P[e,2*i+1]) … … 261 261 262 262 263 def set_array_values(self, values, location='vertices', ind exes = None):263 def set_array_values(self, values, location='vertices', indices = None): 264 264 """Set values for quantity 265 265 … … 269 269 Default is "vertices" 270 270 271 ind exes - if this action is carried out on a subset of271 indices - if this action is carried out on a subset of 272 272 elements or unique vertices 273 The element/unique vertex ind exes are specified here.273 The element/unique vertex indices are specified here. 274 274 275 275 In case of location == 'centroid' the dimension values must … … 292 292 values = array(values).astype(Float) 293 293 294 if (ind exes <> None):295 ind exes = array(indexes).astype(Int)296 msg = 'Number of values must match number of ind exes'297 assert values.shape[0] == ind exes.shape[0], msg294 if (indices <> None): 295 indices = array(indices).astype(Int) 296 msg = 'Number of values must match number of indices' 297 assert values.shape[0] == indices.shape[0], msg 298 298 299 299 N = self.centroid_values.shape[0] … … 302 302 assert len(values.shape) == 1, 'Values array must be 1d' 303 303 304 if ind exes == None:304 if indices == None: 305 305 msg = 'Number of values must match number of elements' 306 306 assert values.shape[0] == N, msg … … 308 308 self.centroid_values = values 309 309 else: 310 msg = 'Number of values must match number of ind exes'311 assert values.shape[0] == ind exes.shape[0], msg310 msg = 'Number of values must match number of indices' 311 assert values.shape[0] == indices.shape[0], msg 312 312 313 313 #Brute force 314 for i in range(len(ind exes)):315 self.centroid_values[ind exes[i]] = values[i]314 for i in range(len(indices)): 315 self.centroid_values[indices[i]] = values[i] 316 316 317 317 elif location == 'edges': … … 330 330 'Values array must be 1d' 331 331 332 self.set_vertex_values(values.flat, ind exes = indexes)332 self.set_vertex_values(values.flat, indices = indices) 333 333 else: 334 334 if len(values.shape) == 1: 335 self.set_vertex_values(values, ind exes = indexes)336 #if ind exes == None:335 self.set_vertex_values(values, indices = indices) 336 #if indices == None: 337 337 #Values are being specified once for each unique vertex 338 338 # msg = 'Number of values must match number of vertices' … … 340 340 # self.set_vertex_values(values) 341 341 #else: 342 # for element_index, value in map(None, ind exes, values):342 # for element_index, value in map(None, indices, values): 343 343 # self.vertex_values[element_index, :] = value 344 344 … … 349 349 assert values.shape[1] == 3, msg 350 350 351 if ind exes == None:351 if indices == None: 352 352 self.vertex_values = values 353 353 else: 354 for element_index, value in map(None, ind exes, values):354 for element_index, value in map(None, indices, values): 355 355 self.vertex_values[element_index] = value 356 356 else: … … 446 446 def set_values(self, X, 447 447 location='vertices', 448 ind exes = None):448 indices = None): 449 449 """Set values for quantity 450 450 … … 464 464 specified points 465 465 466 If indexex is not 'unique vertices' Ind exes is the set of element ids466 If indexex is not 'unique vertices' Indices is the set of element ids 467 467 that the operation applies to. 468 If indexex is 'unique vertices' Ind exes is the set of vertex ids468 If indexex is 'unique vertices' Indices is the set of vertex ids 469 469 that the operation applies to. 470 470 … … 487 487 488 488 import types, Numeric 489 assert type(ind exes) in [types.ListType, types.NoneType,489 assert type(indices) in [types.ListType, types.NoneType, 490 490 Numeric.ArrayType],\ 491 491 'Indices must be a list or None' … … 494 494 if callable(X): 495 495 #Use function specific method 496 self.set_function_values(X, location, ind exes = indexes)496 self.set_function_values(X, location, indices = indices) 497 497 elif type(X) in [types.FloatType, types.IntType, types.LongType]: 498 498 if location == 'centroids': 499 if (ind exes == None):499 if (indices == None): 500 500 self.centroid_values[:] = X 501 501 else: 502 502 #Brute force 503 for i in ind exes:503 for i in indices: 504 504 self.centroid_values[i,:] = X 505 505 506 506 elif location == 'edges': 507 if (ind exes == None):507 if (indices == None): 508 508 self.edge_values[:] = X 509 509 else: 510 510 #Brute force 511 for i in ind exes:511 for i in indices: 512 512 self.edge_values[i,:] = X 513 513 514 514 elif location == 'unique vertices': 515 if (ind exes == None):515 if (indices == None): 516 516 self.edge_values[:] = X 517 517 else: 518 518 519 519 #Go through list of unique vertices 520 for unique_vert_id in ind exes:520 for unique_vert_id in indices: 521 521 triangles = self.domain.vertexlist[unique_vert_id] 522 522 … … 532 532 self.interpolate() 533 533 else: 534 if (ind exes == None):534 if (indices == None): 535 535 self.vertex_values[:] = X 536 536 else: 537 537 #Brute force 538 for i_vertex in ind exes:538 for i_vertex in indices: 539 539 self.vertex_values[i_vertex,:] = X 540 540 541 541 elif type(X) in [Numeric.ArrayType, types.ListType]: 542 542 #Use array specific method 543 self.set_array_values(X, location, ind exes = indexes)543 self.set_array_values(X, location, indices = indices) 544 544 elif type(X) == types.StringType: 545 545 #Assume X is a filename … … 557 557 558 558 559 def get_values(self, location='vertices', ind exes = None):559 def get_values(self, location='vertices', indices = None): 560 560 """get values for quantity 561 561 … … 569 569 of elements. Otherwise it must be of dimension Nx3 570 570 571 The returned values with be a list the length of ind exes572 (N if ind exes = None). Each value will be a list of the three571 The returned values with be a list the length of indices 572 (N if indices = None). Each value will be a list of the three 573 573 vertex values for this quantity. 574 574 575 Ind exes is the set of element ids that the operation applies to.575 Indices is the set of element ids that the operation applies to. 576 576 577 577 """ … … 583 583 584 584 import types, Numeric 585 assert type(ind exes) in [types.ListType, types.NoneType,585 assert type(indices) in [types.ListType, types.NoneType, 586 586 Numeric.ArrayType],\ 587 587 'Indices must be a list or None' 588 588 589 589 if location == 'centroids': 590 if (ind exes == None):591 ind exes = range(len(self))592 return take(self.centroid_values,ind exes)590 if (indices == None): 591 indices = range(len(self)) 592 return take(self.centroid_values,indices) 593 593 elif location == 'edges': 594 if (ind exes == None):595 ind exes = range(len(self))596 return take(self.edge_values,ind exes)594 if (indices == None): 595 indices = range(len(self)) 596 return take(self.edge_values,indices) 597 597 elif location == 'unique vertices': 598 if (ind exes == None):599 ind exes=range(self.domain.coordinates.shape[0])598 if (indices == None): 599 indices=range(self.domain.coordinates.shape[0]) 600 600 vert_values = [] 601 601 #Go through list of unique vertices 602 for unique_vert_id in ind exes:602 for unique_vert_id in indices: 603 603 triangles = self.domain.vertexlist[unique_vert_id] 604 604 … … 616 616 return Numeric.array(vert_values) 617 617 else: 618 if (ind exes == None):619 ind exes = range(len(self))620 return take(self.vertex_values,ind exes)621 622 623 def set_function_values(self, f, location='vertices', ind exes = None):618 if (indices == None): 619 indices = range(len(self)) 620 return take(self.vertex_values,indices) 621 622 623 def set_function_values(self, f, location='vertices', indices = None): 624 624 """Set values for quantity using specified function 625 625 … … 635 635 from Numeric import take 636 636 637 if (ind exes == None):638 ind exes = range(len(self))637 if (indices == None): 638 indices = range(len(self)) 639 639 is_subset = False 640 640 else: 641 641 is_subset = True 642 642 if location == 'centroids': 643 P = take(self.domain.centroid_coordinates,ind exes)643 P = take(self.domain.centroid_coordinates,indices) 644 644 if is_subset: 645 self.set_values(f(P[:,0], P[:,1]), location, ind exes = indexes)645 self.set_values(f(P[:,0], P[:,1]), location, indices = indices) 646 646 else: 647 647 self.set_values(f(P[:,0], P[:,1]), location) … … 650 650 if is_subset: 651 651 #Brute force 652 for e in ind exes:652 for e in indices: 653 653 for i in range(3): 654 654 self.vertex_values[e,i] = f(P[e,2*i], P[e,2*i+1]) … … 660 660 661 661 662 def set_array_values(self, values, location='vertices', ind exes = None):662 def set_array_values(self, values, location='vertices', indices = None): 663 663 """Set values for quantity 664 664 … … 668 668 Default is "vertices" 669 669 670 ind exes - if this action is carried out on a subset of670 indices - if this action is carried out on a subset of 671 671 elements or unique vertices 672 The element/unique vertex ind exes are specified here.672 The element/unique vertex indices are specified here. 673 673 674 674 In case of location == 'centroid' the dimension values must … … 691 691 values = array(values).astype(Float) 692 692 693 if (ind exes <> None):694 ind exes = array(indexes).astype(Int)695 msg = 'Number of values must match number of ind exes'696 assert values.shape[0] == ind exes.shape[0], msg693 if (indices <> None): 694 indices = array(indices).astype(Int) 695 msg = 'Number of values must match number of indices' 696 assert values.shape[0] == indices.shape[0], msg 697 697 698 698 N = self.centroid_values.shape[0] … … 701 701 assert len(values.shape) == 1, 'Values array must be 1d' 702 702 703 if ind exes == None:703 if indices == None: 704 704 msg = 'Number of values must match number of elements' 705 705 assert values.shape[0] == N, msg … … 707 707 self.centroid_values = values 708 708 else: 709 msg = 'Number of values must match number of ind exes'710 assert values.shape[0] == ind exes.shape[0], msg709 msg = 'Number of values must match number of indices' 710 assert values.shape[0] == indices.shape[0], msg 711 711 712 712 #Brute force 713 for i in range(len(ind exes)):714 self.centroid_values[ind exes[i]] = values[i]713 for i in range(len(indices)): 714 self.centroid_values[indices[i]] = values[i] 715 715 716 716 elif location == 'edges': … … 729 729 'Values array must be 1d' 730 730 731 self.set_vertex_values(values.flat, ind exes = indexes)731 self.set_vertex_values(values.flat, indices = indices) 732 732 else: 733 733 if len(values.shape) == 1: 734 self.set_vertex_values(values, ind exes = indexes)735 #if ind exes == None:734 self.set_vertex_values(values, indices = indices) 735 #if indices == None: 736 736 #Values are being specified once for each unique vertex 737 737 # msg = 'Number of values must match number of vertices' … … 739 739 # self.set_vertex_values(values) 740 740 #else: 741 # for element_index, value in map(None, ind exes, values):741 # for element_index, value in map(None, indices, values): 742 742 # self.vertex_values[element_index, :] = value 743 743 … … 748 748 assert values.shape[1] == 3, msg 749 749 750 if ind exes == None:750 if indices == None: 751 751 self.vertex_values = values 752 752 else: 753 for element_index, value in map(None, ind exes, values):753 for element_index, value in map(None, indices, values): 754 754 self.vertex_values[element_index] = value 755 755 else: … … 765 765 # FIXME have a get_vertex_values as well, so the 'stage' quantity can be 766 766 # set, based on the elevation 767 def set_vertex_values(self, A, ind exes = None):767 def set_vertex_values(self, A, indices = None): 768 768 """Set vertex values for all unique vertices based on input array A 769 769 which has one entry per unique vertex, i.e. … … 771 771 one value for each row in vertexlist. 772 772 773 ind exes is the list of vertex_id's that will be set.773 indices is the list of vertex_id's that will be set. 774 774 775 775 Note: Functions not allowed … … 784 784 assert len(A.shape) == 1 785 785 786 if ind exes == None:786 if indices == None: 787 787 assert A.shape[0] == self.domain.coordinates.shape[0] 788 788 vertex_list = range(A.shape[0]) 789 789 else: 790 assert A.shape[0] == len(ind exes)791 vertex_list = ind exes790 assert A.shape[0] == len(indices) 791 vertex_list = indices 792 792 793 793 #Go through list of unique vertices -
inundation/pyvolution/region.py
r1219 r1751 20 20 21 21 22 def build_ind exes(self, elements, domain):22 def build_indices(self, elements, domain): 23 23 """ 24 24 Return a list of triangle_id or vertex_id, depending on the location … … 55 55 self.X, 56 56 location=self.location, 57 ind exes=self.build_indexes(elements, domain))57 indices=self.build_indices(elements, domain)) 58 58 59 59 … … 85 85 if tag == self.tag: 86 86 new_values = domain.get_quantity(self.quantity_initial_value, 87 ind exes=self.build_indexes(elements, domain),87 indices=self.build_indices(elements, domain), 88 88 location=self.location) + self.X 89 89 domain.set_quantity(self.quantity_answer, new_values, 90 ind exes=self.build_indexes(elements, domain),90 indices=self.build_indices(elements, domain), 91 91 location=self.location) 92 92 … … 113 113 114 114 new_values = domain.get_quantity(self.quantity_answer, 115 ind exes=self.build_indexes(elements, domain),115 indices=self.build_indices(elements, domain), 116 116 location=self.location) \ 117 117 + domain.get_quantity(self.adding_quantity, 118 ind exes=self.build_indexes(elements, domain),118 indices=self.build_indices(elements, domain), 119 119 location=self.location) 120 120 domain.set_quantity(self.quantity_answer, new_values, 121 ind exes=self.build_indexes(elements, domain),121 indices=self.build_indices(elements, domain), 122 122 location=self.location) 123 123 -
inundation/pyvolution/test_domain.py
r1158 r1751 16 16 def set_bottom_friction(tag, elements, domain): 17 17 if tag == "bottom": 18 #print 'bottom - ind exes',elements19 domain.set_quantity('friction', 0.09, ind exes = elements)18 #print 'bottom - indices',elements 19 domain.set_quantity('friction', 0.09, indices = elements) 20 20 21 21 def set_top_friction(tag, elements, domain): 22 22 if tag == "top": 23 #print 'top - ind exes',elements24 domain.set_quantity('friction', 1., ind exes = elements)23 #print 'top - indices',elements 24 domain.set_quantity('friction', 1., indices = elements) 25 25 26 26 27 27 def set_all_friction(tag, elements, domain): 28 28 if tag == "all": 29 new_values = domain.get_quantity('friction', ind exes = elements) + 10.030 31 domain.set_quantity('friction', new_values, ind exes = elements)29 new_values = domain.get_quantity('friction', indices = elements) + 10.0 30 31 domain.set_quantity('friction', new_values, indices = elements) 32 32 33 33 -
inundation/pyvolution/test_general_mesh.py
r1018 r1751 30 30 31 31 value = [7] 32 indexes = [1]32 #indexes = [1] #FIXME (Ole): Should this be used 33 33 assert domain.get_vertices() == domain.triangles 34 34 assert domain.get_vertices([0,4]) == [domain.triangles[0], -
inundation/pyvolution/test_quantity.py
r1750 r1751 249 249 quantity = Quantity(self.mesh4) 250 250 quantity.set_vertex_values([0,1,2,3,4,5]) 251 quantity.set_vertex_values([0,20,30,50], ind exes = [0,2,3,5])251 quantity.set_vertex_values([0,20,30,50], indices = [0,2,3,5]) 252 252 253 253 assert allclose(quantity.vertex_values, … … 798 798 quantity = Quantity(domain,[[1,1,1],[2,2,2]]) 799 799 value = [7] 800 ind exes = [1]800 indices = [1] 801 801 quantity.set_array_values_by_index(value, 802 802 location = 'centroids', 803 ind exes = indexes)803 indices = indices) 804 804 #print "quantity.centroid_values",quantity.centroid_values 805 805 806 806 assert allclose(quantity.centroid_values, [1,7]) 807 807 808 quantity.set_array_values([15,20,25], ind exes = indexes)808 quantity.set_array_values([15,20,25], indices = indices) 809 809 assert allclose(quantity.centroid_values, [1,20]) 810 810 811 quantity.set_array_values([15,20,25], ind exes = indexes)811 quantity.set_array_values([15,20,25], indices = indices) 812 812 assert allclose(quantity.centroid_values, [1,20]) 813 813 … … 829 829 [4,4,4],[5,5,5],[6,6,6]]) 830 830 value = [7] 831 ind exes = [1]831 indices = [1] 832 832 quantity.set_values(value, 833 833 location = 'centroids', 834 ind exes = indexes)834 indices = indices) 835 835 #print "quantity.centroid_values",quantity.centroid_values 836 836 assert allclose(quantity.centroid_values, [1,7,3,4,5,6]) 837 837 838 838 value = [[15,20,25]] 839 quantity.set_values(value, ind exes = indexes)839 quantity.set_values(value, indices = indices) 840 840 #print "1 quantity.vertex_values",quantity.vertex_values 841 841 assert allclose(quantity.vertex_values[1], value[0]) … … 844 844 #print "quantity",quantity.vertex_values 845 845 values = [10,100,50] 846 quantity.set_values(values, ind exes = [0,1,5], location = 'centroids')846 quantity.set_values(values, indices = [0,1,5], location = 'centroids') 847 847 #print "2 quantity.vertex_values",quantity.vertex_values 848 848 assert allclose(quantity.vertex_values[0], [10,10,10]) … … 858 858 #this will be per unique vertex, indexing the vertices 859 859 #print "quantity.vertex_values",quantity.vertex_values 860 quantity.set_values(values, ind exes = [0,1,5])860 quantity.set_values(values, indices = [0,1,5]) 861 861 #print "quantity.vertex_values",quantity.vertex_values 862 862 assert allclose(quantity.vertex_values[0], [1,50,10]) … … 867 867 [4,4,4],[5,5,5],[6,6,6]]) 868 868 values = [[31,30,29],[400,400,400],[1000,999,998]] 869 quantity.set_values(values, ind exes = [3,3,5])869 quantity.set_values(values, indices = [3,3,5]) 870 870 quantity.interpolate() 871 871 assert allclose(quantity.centroid_values, [1,2,3,400,5,999]) … … 905 905 [4,4,4],[5,5,5]]) 906 906 value = 7 907 ind exes = [1,5]907 indices = [1,5] 908 908 quantity.set_values(value, 909 909 location = 'unique vertices', 910 ind exes = indexes)910 indices = indices) 911 911 #print "quantity.centroid_values",quantity.centroid_values 912 912 assert allclose(quantity.vertex_values[0], [0,7,0]) … … 940 940 941 941 #print "quantity.get_values(location = 'unique vertices')", \ 942 # quantity.get_values(ind exes=[0,1,2,3,4,5,6,7], \942 # quantity.get_values(indices=[0,1,2,3,4,5,6,7], \ 943 943 # location = 'unique vertices') 944 944 … … 947 947 quantity.get_values(location = 'unique vertices')) 948 948 949 ind exes = [0,5,3]949 indices = [0,5,3] 950 950 answer = [0.5,1,5] 951 951 assert allclose(answer, 952 quantity.get_values(ind exes=indexes, \952 quantity.get_values(indices=indices, \ 953 953 location = 'unique vertices')) 954 954 #print "quantity.centroid_values",quantity.centroid_values … … 977 977 [4,4,4],[5,5,5],[6,6,6]]) 978 978 value = [7] 979 ind exes = [1]979 indices = [1] 980 980 quantity.set_values(value, 981 981 location = 'centroids', 982 ind exes = indexes)982 indices = indices) 983 983 #print "quantity.centroid_values",quantity.centroid_values 984 984 #print "quantity.get_values(location = 'centroids') ",\ … … 989 989 990 990 value = [[15,20,25]] 991 quantity.set_values(value, ind exes = indexes)991 quantity.set_values(value, indices = indices) 992 992 #print "1 quantity.vertex_values",quantity.vertex_values 993 993 assert allclose(quantity.vertex_values, quantity.get_values()) … … 997 997 998 998 # get a subset of elements 999 subset = quantity.get_values(location='centroids', ind exes=[0,5])999 subset = quantity.get_values(location='centroids', indices=[0,5]) 1000 1000 answer = [quantity.centroid_values[0],quantity.centroid_values[5]] 1001 1001 assert allclose(subset, answer) 1002 1002 1003 1003 1004 subset = quantity.get_values(location='edges', ind exes=[0,5])1004 subset = quantity.get_values(location='edges', indices=[0,5]) 1005 1005 answer = [quantity.edge_values[0],quantity.edge_values[5]] 1006 1006 #print "subset",subset … … 1008 1008 assert allclose(subset, answer) 1009 1009 1010 subset = quantity.get_values( ind exes=[1,5])1010 subset = quantity.get_values( indices=[1,5]) 1011 1011 answer = [quantity.vertex_values[1],quantity.vertex_values[5]] 1012 1012 #print "subset",subset
Note: See TracChangeset
for help on using the changeset viewer.