Changeset 984
- Timestamp:
- Mar 1, 2005, 6:26:00 PM (20 years ago)
- Location:
- inundation/ga/storm_surge/pyvolution
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/least_squares.py
r981 r984 395 395 396 396 397 #Remove points falling outside mesh boundary 398 #from util import inside_polygon 399 #P = self.mesh.get_boundary_polygon() 400 #FIXME: TODO 401 402 397 403 398 404 -
inundation/ga/storm_surge/pyvolution/mesh.py
r849 r984 48 48 Mesh takes the optional third argument boundary which is a 49 49 dictionary mapping from (element_id, edge_id) to boundary tag. 50 The default value is None which will assign the def ualt_boundary_tag50 The default value is None which will assign the default_boundary_tag 51 51 as specified in config.py to all boundary edges. 52 52 """ … … 346 346 return tags.keys() 347 347 348 348 349 def get_boundary_polygon(self): 350 """Return bounding polygon as a list of points 351 """ 352 from Numeric import allclose 353 354 355 V = self.get_vertex_coordinates() 356 segments = {} 357 358 pmin = (min(self.coordinates[:,0]), min(self.coordinates[:,1])) 359 for i, edge_id in self.boundary.keys(): 360 #Find vertex ids for boundary segment 361 if edge_id == 0: a = 1; b = 2 362 if edge_id == 1: a = 2; b = 0 363 if edge_id == 2: a = 0; b = 1 364 365 A = tuple(self.get_vertex_coordinate(i, a)) 366 B = tuple(self.get_vertex_coordinate(i, b)) 367 368 #Find minimal point 369 if allclose(A, pmin): p0 = A 370 if allclose(B, pmin): p0 = B 371 372 segments[A] = B 373 374 375 #Start with smallest point and follow boundary (counter clock wise) 376 polygon = [p0] 377 while len(polygon) < len(self.boundary): 378 p1 = segments[p0] 379 polygon.append(p1) 380 p0 = p1 381 382 return polygon 383 384 385 386 349 387 350 388 def check_integrity(self): -
inundation/ga/storm_surge/pyvolution/test_mesh.py
r648 r984 649 649 650 650 651 651 def test_boundary_polygon(self): 652 from mesh_factory import rectangular 653 from mesh import Mesh 654 from Numeric import zeros, Float 655 from util import inside_polygon 656 657 #Create basic mesh 658 points, vertices, boundary = rectangular(2, 2) 659 mesh = Mesh(points, vertices, boundary) 660 661 662 P = mesh.get_boundary_polygon() 663 664 assert len(P) == 8 665 assert allclose(P, [[0.0, 0.0], [0.5, 0.0], [1.0, 0.0], 666 [1.0, 0.5], [1.0, 1.0], [0.5, 1.0], 667 [0.0, 1.0], [0.0, 0.5]]) 668 for p in points: 669 #print p, P 670 assert inside_polygon(p, P) 671 672 673 def test_boundary_polygon_II(self): 674 from mesh import Mesh 675 from Numeric import zeros, Float 676 from util import inside_polygon 677 678 #Points 679 a = [0.0, 0.0] #0 680 b = [0.0, 0.5] #1 681 c = [0.0, 1.0] #2 682 d = [0.5, 0.0] #3 683 e = [0.5, 0.5] #4 684 f = [1.0, 0.0] #5 685 g = [1.0, 0.5] #6 686 h = [1.0, 1.0] #7 687 i = [1.5, 0.5] #8 688 689 points = [a, b, c, d, e, f, g, h, i] 690 691 #dea, bae, bec, fgd, 692 #edg, ghe, gfi, gih 693 vertices = [ [3,4,0], [1,0,4], [1,4,2], [5,6,3], 694 [4,3,6], [6,7,4], [6,5,8], [6,8,7]] 695 696 mesh = Mesh(points, vertices) 697 698 mesh.check_integrity() 699 700 P = mesh.get_boundary_polygon() 701 702 assert len(P) == 8 703 assert allclose(P, [a, d, f, i, h, e, c, b]) 704 705 for p in points: 706 #print p, P 707 assert inside_polygon(p, P) 708 709 710 def test_boundary_polygon_III(self): 711 """Same as II but vertices ordered differently 712 """ 713 714 from mesh import Mesh 715 from Numeric import zeros, Float 716 from util import inside_polygon 717 718 #Points 719 a = [0.0, 0.0] #0 720 b = [0.0, 0.5] #1 721 c = [0.0, 1.0] #2 722 d = [0.5, 0.0] #3 723 e = [0.5, 0.5] #4 724 f = [1.0, 0.0] #5 725 g = [1.0, 0.5] #6 726 h = [1.0, 1.0] #7 727 i = [1.5, 0.5] #8 728 729 points = [a, b, c, d, e, f, g, h, i] 730 731 #edg, ghe, gfi, gih 732 #dea, bae, bec, fgd, 733 vertices = [[4,3,6], [6,7,4], [6,5,8], [6,8,7], 734 [3,4,0], [1,0,4], [1,4,2], [5,6,3]] 735 736 737 mesh = Mesh(points, vertices) 738 mesh.check_integrity() 739 740 741 P = mesh.get_boundary_polygon() 742 743 assert len(P) == 8 744 assert allclose(P, [a, d, f, i, h, e, c, b]) 745 746 for p in points: 747 assert inside_polygon(p, P) 748 749 652 750 653 751 #------------------------------------------------------------- -
inundation/ga/storm_surge/pyvolution/test_util.py
r955 r984 866 866 assert not inside_polygon( (0.5, -0.5), polygon ) 867 867 868 #Now try the vector formulation returning indices869 points = [ [0.5, 0.5], [1, -0.5], [1.5, 0], [0.5, 1.5], [0.5, -0.5]]870 res = inside_polygon( points, polygon )871 872 assert allclose( res, [0,1,2] )873 868 874 869 #Very convoluted polygon … … 913 908 assert inside_polygon( (0, -0.5), polygon ) 914 909 assert not inside_polygon( (0.5, 0.5), polygon ) 915 910 911 def test_inside_polygon_vector_version(self): 912 #Now try the vector formulation returning indices 913 polygon = [[0,0], [1,0], [0.5,-1], [2, -1], [2,1], [0,1]] 914 points = [ [0.5, 0.5], [1, -0.5], [1.5, 0], [0.5, 1.5], [0.5, -0.5]] 915 res = inside_polygon( points, polygon ) 916 917 assert allclose( res, [0,1,2] ) 918 916 919 917 920 def test_populate_polygon(self):
Note: See TracChangeset
for help on using the changeset viewer.