Changeset 3541
- Timestamp:
- Aug 29, 2006, 5:12:03 PM (18 years ago)
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/pmesh/mesh.py
r3514 r3541 29 29 import load_mesh.loadASCII 30 30 import anuga.alpha_shape.alpha_shape 31 from anuga.geospatial_data.geospatial_data import Geospatial_data, ensure_geospatial 31 from anuga.geospatial_data.geospatial_data import Geospatial_data, ensure_geospatial, ensure_absolute 32 32 33 33 try: … … 743 743 segments.append( [lo, hi] ) 744 744 region_dict['segments'] = segments 745 746 747 #Create tags 748 #E.g. ['wall', 'wall', 'ocean', 'wall'] 749 # from a dic 750 #{'wall':[0,1,3],'ocean':[2]} 751 segment_tags = ['']*N 752 if tags is not None: 753 for key in tags: 754 indices = tags[key] 755 for i in indices: 756 segment_tags[i] = key 757 region_dict['segment_tags'] = segment_tags 745 region_dict['segment_tags'] = self._tag_dict2list(tags, N) 746 758 747 759 748 self.addVertsSegs(region_dict) #this is passing absolute values … … 774 763 return inner 775 764 765 def _tag_dict2list(self, tags, number_of_segs): 766 """ 767 Convert a tag dictionary from this sort of format; 768 #{'wall':[0,3],'ocean':[2]} 769 770 To a list format 771 # ['wall', '', 'ocean', 'wall'] 772 773 Note: '' is a default value of nothing 774 """ 775 # FIXME (DSG-DSG): Using '' as a default isn't good. 776 #Try None. 777 # Due to this default this method is too connected to 778 # _add_area_from_polygon 779 780 segment_tags = ['']*number_of_segs 781 if tags is not None: 782 for key in tags: 783 indices = tags[key] 784 for i in indices: 785 segment_tags[i] = key 786 return segment_tags 787 776 788 def add_circle(self, center, radius, segment_count=100, 777 789 center_geo_reference=None, tag = None, … … 788 800 789 801 """ 790 pass791 802 # convert center and radius to a polygon 792 ### pi = math.pi793 ### num_of_cuts = 100794 803 cuts = [] 795 804 factor = 2* math.pi/segment_count … … 845 854 #not a list of lists. 846 855 # add a method to the points class to fix this up. 856 857 def add_segment(self, v1, v2, tag): 858 """ 859 Don't do this function. 860 what will the v's be objects? How is the user suppost to get them? 861 862 Indexes? If add vertstosegs or add_region_from_polygon is called 863 more than once then the actual index is not obvious. Making this 864 function confusing. 865 """ 866 pass 867 868 869 def add_points_and_segments(self, points, 870 segments, segment_tags = None): 871 """ 872 Add an outline of the mesh. 873 Vertices is a list of points/ a standard representation of points. 874 Segments is a list of tuples of integers. Each tuple defines the 875 start and end of the segment by it's vertex index, in relation to 876 the list of vertices. 877 segment_tags is an optional dictionary which is used to add tags to 878 the segments. The key is the tag name, value is the list of segment 879 indexes the tag will apply to. 880 eg. {'wall':[0,3],'ocean':[2]} 881 882 """ 883 #make sure the points are absolute 884 points = ensure_absolute(points) 885 886 #create points, segs and tags 887 region_dict = {} 888 region_dict['points'] = points 889 region_dict['segments'] = segments 890 region_dict['segment_tags'] = self._tag_dict2list(segment_tags, 891 len(segments)) 892 self.addVertsSegs(region_dict) 847 893 848 894 def addVertsSegs(self, outlineDict): … … 864 910 #print "outlineDict['segments']",outlineDict['segments'] 865 911 866 localUserVertices = [] 867 #index = 0 912 i_offset = len(self.userVertices) 913 #print "self.userVertices",self.userVertices 914 #print "index_offset",index_offset 868 915 for point in outlineDict['points']: 869 916 v=Vertex(point[0]-self.geo_reference.xllcorner, 870 917 point[1]-self.geo_reference.yllcorner) 871 #v.index = index872 #index +=1873 918 self.userVertices.append(v) 874 localUserVertices.append(v)875 919 876 #index = 0877 920 for seg,seg_tag in map(None,outlineDict['segments'], 878 921 outlineDict['segment_tags']): 879 segObject = Segment( localUserVertices[int(seg[0])],880 localUserVertices[int(seg[1])] )922 segObject = Segment(self.userVertices[int(seg[0])+i_offset], 923 self.userVertices[int(seg[1])+i_offset] ) 881 924 if not seg_tag == '': 882 925 segObject.set_tag(seg_tag) 883 #segObject.index = index884 #index +=1885 926 self.userSegments.append(segObject) 886 #DSG!!!927 887 928 888 929 def get_triangle_count(self): -
anuga_core/source/anuga/pmesh/mesh_interface.py
r3514 r3541 69 69 #(DSG) Yes! 70 70 71 # First check that interior polygons are fully contained in bounding polygon 71 # First check that interior polygons are fully contained in bounding 72 # polygon 72 73 #Note, Both poly's have the same geo_ref, therefore don't take into account 73 74 # geo_ref -
anuga_core/source/anuga/pmesh/test_mesh.py
r3514 r3541 1354 1354 m.addVertsSegs(dict) 1355 1355 1356 def test_addVertsSegs_done_twice(self): 1357 m = Mesh() 1358 dict = {} 1359 dict['points'] = [[0.0, 0.0], [5.0, 0.0], [5.0, 5.0]] 1360 dict['segments'] = [[0, 1], [1, 2], [2,0]] 1361 dict['segment_tags'] = ['0','1','2'] 1362 m.addVertsSegs(dict) 1363 1364 dict = {} 1365 dict['points'] = [[2.0, 1.0], [4.0, 1.0], [4.0, 3.0]] 1366 dict['segments'] = [[0, 1], [1, 2], [2,0]] 1367 dict['segment_tags'] = ['3','4','5'] 1368 m.addVertsSegs(dict) 1369 1370 1371 self.failUnless(m.userSegments[5].vertices[0].y == 3, 1372 'Wrong vertex connected.') 1373 self.failUnless(m.userSegments[5].vertices[1].y == 1, 1374 'Wrong vertex connected.') 1375 1376 def test_add_points_and_segments(self): 1377 m = Mesh() 1378 Segment.set_default_tag("food") 1379 dict = {} 1380 points = [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0]] 1381 segments = [[0, 1], [1, 2]] 1382 segment_tags = {'do-op':[1]} 1383 m.add_points_and_segments(points, 1384 segments, segment_tags) 1385 # have to reset this , since it's a class attribute 1386 Segment.set_default_tag("") 1387 1388 1389 self.failUnless(len(m.userSegments) ==2, 1390 'Wrong segment list length.') 1391 self.failUnless(len(m.userVertices) == 3, 1392 'Wrong vertex list length.') 1393 self.failUnless(m.userSegments[0].tag =='food', 1394 'Wrong segment tag length.') 1395 self.failUnless(m.userSegments[1].tag =='do-op', 1396 'Wrong segment tag.') 1397 1356 1398 def test_exportASCIImeshfile(self): 1357 1399 … … 2234 2276 if __name__ == "__main__": 2235 2277 suite = unittest.makeSuite(meshTestCase,'test') 2236 #suite = unittest.makeSuite(meshTestCase,'test_ generate_mesh')2278 #suite = unittest.makeSuite(meshTestCase,'test_add_points_and_segments') 2237 2279 runner = unittest.TextTestRunner() #verbosity=2) 2238 2280 runner.run(suite) -
development/dam_2006/create_mesh.py
r3535 r3541 29 29 30 30 #Boundary 31 # FIXME (DSG-DSG): Update this to use new interface. 32 dict = {} 33 dict['points'] = [point_sw, #se 34 point_nw, 35 point_dam_top, 36 point_ne, 37 point_se, 38 point_dam_bottom 39 ] 40 #if False: 31 points = [point_sw, #se 32 point_nw, 33 point_dam_top, 34 point_ne, 35 point_se, 36 point_dam_bottom 37 ] 41 38 42 dict['segments']= [[0,1], [1,2], [2,3],39 segments = [[0,1], [1,2], [2,3], 43 40 [3,4 ],[4,5], [5,0], #The outer border 44 41 [2,5]] #dam Separator 45 42 46 dict['segment_tags'] = ['wall', 47 'wall', 48 'wall', 49 'edge', 50 'wall', 51 'wall', 52 ''] #Interior 53 43 segment_tags = {'wall':[0,1,2,4,5],'edge':[3]} # '':[6] 54 44 55 m.add VertsSegs(dict)45 m.add_points_and_segments(points, segments, segment_tags) 56 46 57 47 dam = m.add_region(-0.0000001,(ytop - ybottom)/2) -
documentation/user_manual/anuga_user_manual.tex
r3533 r3541 1211 1211 \end{methoddesc} 1212 1212 1213 1214 \begin{methoddesc} {add\_points_and_segments}{self, points, segments, 1215 segment\_tags=None} 1216 Module: \module{pmesh.mesh}, Class: \class{Mesh} 1217 1218 This method is used to build the mesh outline. It adds some points and 1219 segments connecting some points. A tag for each point can optionally 1220 be added. 1221 1222 \end{methoddesc} 1213 1223 1214 1224 \begin{methoddesc} {add\_region}{x,y, geo_reference=None}
Note: See TracChangeset
for help on using the changeset viewer.