Changeset 7276 for anuga_core/source/anuga/pmesh
- Timestamp:
- Jun 30, 2009, 2:07:41 PM (15 years ago)
- Location:
- anuga_core/source/anuga/pmesh
- Files:
-
- 1 deleted
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/pmesh/icons/addVertex.lic
r5108 r7276 1 <?xml version="1.0" encoding="iso-8859-1"?> 2 3 <ga_license_file> 1 <?xml version='1.0' encoding='iso-8859-1'?> 2 <ga_license_file> 4 3 <metadata> 5 4 <author>Duncan Gray</author> … … 7 6 <datafile> 8 7 <filename>addVertex.gif</filename> 9 <checksum> -1521060556</checksum>8 <checksum>2773906740</checksum> 10 9 <publishable>Yes</publishable> 11 10 <accountable>Duncan Gray</accountable> -
anuga_core/source/anuga/pmesh/icons/autoSegGiveAlpha.lic
r5108 r7276 1 <?xml version="1.0" encoding="iso-8859-1"?> 2 3 <ga_license_file> 1 <?xml version='1.0' encoding='iso-8859-1'?> 2 <ga_license_file> 4 3 <metadata> 5 4 <author>Duncan Gray</author> … … 7 6 <datafile> 8 7 <filename>autoSegGiveAlpha.gif</filename> 9 <checksum> -283639999</checksum>8 <checksum>4011327297</checksum> 10 9 <publishable>Yes</publishable> 11 10 <accountable>Duncan Gray</accountable> -
anuga_core/source/anuga/pmesh/icons/default.lic
r5108 r7276 1 <?xml version="1.0" encoding="iso-8859-1"?> 2 3 <ga_license_file> 1 <?xml version='1.0' encoding='iso-8859-1'?> 2 <ga_license_file> 4 3 <metadata> 5 4 <author>Duncan Gray</author> -
anuga_core/source/anuga/pmesh/icons/edit.lic
r5108 r7276 1 <?xml version="1.0" encoding="iso-8859-1"?> 2 3 <ga_license_file> 1 <?xml version='1.0' encoding='iso-8859-1'?> 2 <ga_license_file> 4 3 <metadata> 5 4 <author>Duncan Gray</author> -
anuga_core/source/anuga/pmesh/icons/hole.lic
r5108 r7276 1 <?xml version="1.0" encoding="iso-8859-1"?> 2 3 <ga_license_file> 1 <?xml version='1.0' encoding='iso-8859-1'?> 2 <ga_license_file> 4 3 <metadata> 5 4 <author>Duncan Gray</author> -
anuga_core/source/anuga/pmesh/icons/joinVer.lic
r5108 r7276 1 <?xml version="1.0" encoding="iso-8859-1"?> 2 3 <ga_license_file> 1 <?xml version='1.0' encoding='iso-8859-1'?> 2 <ga_license_file> 4 3 <metadata> 5 4 <author>Duncan Gray</author> … … 7 6 <datafile> 8 7 <filename>joinVer.gif</filename> 9 <checksum> -1003484863</checksum>8 <checksum>3291482433</checksum> 10 9 <publishable>Yes</publishable> 11 10 <accountable>Duncan Gray</accountable> -
anuga_core/source/anuga/pmesh/icons/meshGen.lic
r5108 r7276 1 <?xml version="1.0" encoding="iso-8859-1"?> 2 3 <ga_license_file> 1 <?xml version='1.0' encoding='iso-8859-1'?> 2 <ga_license_file> 4 3 <metadata> 5 4 <author>Duncan Gray</author> … … 7 6 <datafile> 8 7 <filename>meshGen.gif</filename> 9 <checksum> -1239631320</checksum>8 <checksum>3055335976</checksum> 10 9 <publishable>Yes</publishable> 11 10 <accountable>Duncan Gray</accountable> -
anuga_core/source/anuga/pmesh/icons/no_see.lic
r5108 r7276 1 <?xml version="1.0" encoding="iso-8859-1"?> 2 3 <ga_license_file> 1 <?xml version='1.0' encoding='iso-8859-1'?> 2 <ga_license_file> 4 3 <metadata> 5 4 <author>Duncan Gray</author> … … 7 6 <datafile> 8 7 <filename>no_see.gif</filename> 9 <checksum> -33749560</checksum>8 <checksum>4261217736</checksum> 10 9 <publishable>Yes</publishable> 11 10 <accountable>Duncan Gray</accountable> -
anuga_core/source/anuga/pmesh/icons/pointer.lic
r5108 r7276 1 <?xml version="1.0" encoding="iso-8859-1"?> 2 3 <ga_license_file> 1 <?xml version='1.0' encoding='iso-8859-1'?> 2 <ga_license_file> 4 3 <metadata> 5 4 <author>Duncan Gray</author> -
anuga_core/source/anuga/pmesh/icons/region.lic
r5108 r7276 1 <?xml version="1.0" encoding="iso-8859-1"?> 2 3 <ga_license_file> 1 <?xml version='1.0' encoding='iso-8859-1'?> 2 <ga_license_file> 4 3 <metadata> 5 4 <author>Duncan Gray</author> … … 7 6 <datafile> 8 7 <filename>region.gif</filename> 9 <checksum> -599357628</checksum>8 <checksum>3695609668</checksum> 10 9 <publishable>Yes</publishable> 11 10 <accountable>Duncan Gray</accountable> -
anuga_core/source/anuga/pmesh/icons/see.lic
r5108 r7276 1 <?xml version="1.0" encoding="iso-8859-1"?> 2 3 <ga_license_file> 1 <?xml version='1.0' encoding='iso-8859-1'?> 2 <ga_license_file> 4 3 <metadata> 5 4 <author>Duncan Gray</author> -
anuga_core/source/anuga/pmesh/icons/segment.lic
r5108 r7276 1 <?xml version="1.0" encoding="iso-8859-1"?> 2 3 <ga_license_file> 1 <?xml version='1.0' encoding='iso-8859-1'?> 2 <ga_license_file> 4 3 <metadata> 5 4 <author>Duncan Gray</author> -
anuga_core/source/anuga/pmesh/icons/sep.lic
r5108 r7276 1 <?xml version="1.0" encoding="iso-8859-1"?> 2 3 <ga_license_file> 1 <?xml version='1.0' encoding='iso-8859-1'?> 2 <ga_license_file> 4 3 <metadata> 5 4 <author>Duncan Gray</author> … … 7 6 <datafile> 8 7 <filename>sep.gif</filename> 9 <checksum> -241021346</checksum>8 <checksum>4053945950</checksum> 10 9 <publishable>Yes</publishable> 11 10 <accountable>Duncan Gray</accountable> -
anuga_core/source/anuga/pmesh/icons/vertex.lic
r5108 r7276 1 <?xml version="1.0" encoding="iso-8859-1"?> 2 3 <ga_license_file> 1 <?xml version='1.0' encoding='iso-8859-1'?> 2 <ga_license_file> 4 3 <metadata> 5 4 <author>Duncan Gray</author> -
anuga_core/source/anuga/pmesh/icons/zoom0.5.lic
r5108 r7276 1 <?xml version="1.0" encoding="iso-8859-1"?> 2 3 <ga_license_file> 1 <?xml version='1.0' encoding='iso-8859-1'?> 2 <ga_license_file> 4 3 <metadata> 5 4 <author>Duncan Gray</author> -
anuga_core/source/anuga/pmesh/icons/zoom2.lic
r5108 r7276 1 <?xml version="1.0" encoding="iso-8859-1"?> 2 3 <ga_license_file> 1 <?xml version='1.0' encoding='iso-8859-1'?> 2 <ga_license_file> 4 3 <metadata> 5 4 <author>Duncan Gray</author> … … 7 6 <datafile> 8 7 <filename>zoom2.gif</filename> 9 <checksum> -556758766</checksum>8 <checksum>3738208530</checksum> 10 9 <publishable>Yes</publishable> 11 10 <accountable>Duncan Gray</accountable> -
anuga_core/source/anuga/pmesh/icons/zoomToMesh.lic
r5108 r7276 1 <?xml version="1.0" encoding="iso-8859-1"?> 2 3 <ga_license_file> 1 <?xml version='1.0' encoding='iso-8859-1'?> 2 <ga_license_file> 4 3 <metadata> 5 4 <author>Duncan Gray</author> -
anuga_core/source/anuga/pmesh/mesh.py
r6156 r7276 22 22 import types 23 23 import exceptions 24 25 import numpy as num 24 26 25 27 … … 37 39 except ImportError: 38 40 # Hand-built mockup of the things we need from the kinds package, since it 39 # was recently removed from the standard Numeric distro. Some users may41 # was recently removed from the standard numeric distro. Some users may 40 42 # not have it by default. 41 43 class _bunch: … … 117 119 118 120 class Vertex(Point): 119 """ 120 A point on the mesh. 121 """A point on the mesh. 121 122 Object attributes based on the Triangle program 122 123 """ 123 def __init__(self,X,Y, attributes = None): 124 125 VERTEXSQUARESIDELENGTH = 6 126 127 def __init__(self, X, Y, attributes=None): 124 128 __slots__ = ['x','y','attributes'] 125 126 assert (type(X) == types.FloatType or type(X) == types.IntType) 127 assert (type(Y) == types.FloatType or type(Y) == types.IntType) 128 self.x=X 129 self.y=Y 130 self.attributes=[] 131 132 if attributes is None: 133 self.attributes=[] 134 else: 135 self.attributes=attributes 136 137 129 130 # we don't care what we get, as long as we can get float *value* 131 self.x = float(X) 132 self.y = float(Y) 133 134 self.attributes = [] 135 if not attributes is None: 136 self.attributes = attributes 137 138 138 def setAttributes(self,attributes): 139 """ 140 attributes is a list. 141 """ 139 """attributes is a list. """ 140 142 141 self.attributes = attributes 143 142 144 VERTEXSQUARESIDELENGTH = 6145 143 def draw(self, canvas, tags, colour = 'black',scale = 1, xoffset = 0, 146 144 yoffset =0, ): … … 176 174 def __repr__(self): 177 175 return "[(%f,%f),%r]" % (self.x,self.y,self.attributes) 178 176 177 179 178 class Hole(Point): 180 """ 181 A region of the mesh were no triangles are generated. 179 """A region of the mesh were no triangles are generated. 182 180 Defined by a point in the hole enclosed by segments. 183 181 """ … … 201 199 202 200 class Region(Point): 203 """ 204 A region of the mesh, defined by a point in the region 205 enclosed by segments. Used to tag areas. 201 """A region of the mesh. 202 Defined by a point in the region enclosed by segments. Used to tag areas. 206 203 """ 204 207 205 CROSSLENGTH = 6 208 206 TAG = 0 209 207 MAXAREA = 1 210 208 211 def __init__(self,X,Y, tag = None, maxArea = None): 212 """Precondition: tag is a string and maxArea is a real 213 """ 214 # This didn't work. 215 #super(Region,self)._init_(self,X,Y) 209 def __init__(self, X, Y, tag=None, maxArea=None): 210 """Precondition: tag is a string and maxArea is a real""" 211 216 212 self.x=X 217 213 self.y=Y 218 self.attributes = [] # index 0 is the tag string219 #optoinal index 1 is the max triangle area220 #NOTE the size of this attribute is assumed221 # to be 1 or 2 in regionstrings2int214 self.attributes = [] # index 0 is the tag string 215 # optional index 1 is the max triangle area 216 # NOTE the size of this attribute is assumed 217 # to be 1 or 2 in regionstrings2int 222 218 if tag is None: 223 219 self.attributes.append("") -
anuga_core/source/anuga/pmesh/mesh_interface.py
r6637 r7276 3 3 from anuga.utilities.polygon import point_in_polygon ,populate_polygon 4 4 from anuga.utilities.numerical_tools import ensure_numeric 5 import Numericas num5 import numpy as num 6 6 from anuga.utilities.polygon import inside_polygon 7 7 … … 159 159 160 160 # Simple check 161 bounding_polygon = ensure_numeric(bounding_polygon, num. Float)161 bounding_polygon = ensure_numeric(bounding_polygon, num.float) 162 162 msg = 'Bounding polygon must be a list of points or an Nx2 array' 163 163 assert len(bounding_polygon.shape) == 2, msg -
anuga_core/source/anuga/pmesh/test_all.py
r4663 r7276 76 76 return unittest.TestSuite(map(load, modules)) 77 77 78 ################################################################################ 79 78 80 if __name__ == '__main__': 79 81 # Assume everything is compiled -
anuga_core/source/anuga/pmesh/test_mesh.py
r6172 r7276 15 15 from anuga.utilities.polygon import is_inside_polygon ### inside_polygon 16 16 17 import Numericas num17 import numpy as num 18 18 19 19 class meshTestCase(unittest.TestCase): … … 428 428 vert = m.getMeshVerticeAttributes() 429 429 430 self.failUnless(vert[0] == [12.0, 2.0] and 431 vert[1] == [9.0, 7.0] and 432 vert[2] == [14.0,3.0] and 433 vert[3] == [12.232233047033631, 4.4142135623730949] and 434 vert[4] == [13.0, 2.5] , 430 self.failUnless(num.all(vert[0] == [12.0, 2.0]) and 431 num.all(vert[1] == [9.0, 7.0]) and 432 num.all(vert[2] == [14.0,3.0]) and 433 num.all(vert[3] == [12.232233047033631, 434 4.4142135623730949]) and 435 num.all(vert[4] == [13.0, 2.5]) , 435 436 'vertex attributes are wrong!') 436 437 … … 1655 1656 #print "dict['vertices']",dict['vertices'] 1656 1657 1657 self.failUnless( dict['vertices'] == answer, 1658 'test_Mesh2IOTriangulationDict failed. test 2') 1659 1660 self.failUnless(num.alltrue(dict['vertices'].flat == verts.flat), 1658 self.failUnless(num.alltrue(dict['vertices'] == answer), 1659 'test_Mesh2IOTriangulationDict failed. test 2') 1660 1661 self.failUnless(num.alltrue(dict['vertices'].flatten() == 1662 verts.flatten()), 1661 1663 'test_Mesh2IOTriangulationDict failed. test vert') 1662 self.failUnless(num.alltrue(dict['vertex_attributes'].flat == vert_as.flat), 1664 self.failUnless(num.alltrue(dict['vertex_attributes'].flatten() == 1665 vert_as.flatten()), 1663 1666 'test_Mesh2IOTriangulationDict failed. test vert ats') 1664 1667 … … 1716 1719 #print "dict['vertices']",dict['vertices'] 1717 1720 1718 self.failUnless( dict['vertices'] == answer,1719 1720 1721 self.failUnless( dict['vertices'] == verts,1722 1723 self.failUnless( dict['vertex_attributes'] == vert_as,1724 1725 1726 self.failUnless( dict['segments'][0] == [0,1],1721 self.failUnless(num.alltrue(dict['vertices'] == answer), 1722 'test_Mesh2IOTriangulationDict failed. test 2') 1723 1724 self.failUnless(num.alltrue(dict['vertices'] == verts), 1725 'test_Mesh2IOTriangulationDict failed. test vert') 1726 self.failUnless(num.alltrue(dict['vertex_attributes'] == vert_as), 1727 'test_Mesh2IOTriangulationDict failed. test vert ats') 1728 1729 self.failUnless(num.alltrue(dict['segments'][0] == [0,1]), 1727 1730 'test_Mesh2IODict failed. test 3') 1728 1731 1729 self.failUnless( 1732 self.failUnless(dict['segment_tags'] == seg_tags, 1730 1733 'test_Mesh2IODict failed. test 3') 1731 1734 #print " dict['triangles'][0]", dict['triangles'][0] 1732 self.failUnless( dict['triangles'][0] == [3,2,4],1735 self.failUnless(num.alltrue(dict['triangles'][0] == [3,2,4]), 1733 1736 'test_Mesh2IODict failed. test 5') 1734 self.failUnless( dict['triangle_neighbors'][0] == [-1,2,3],1737 self.failUnless(num.alltrue(dict['triangle_neighbors'][0] == [-1,2,3]), 1735 1738 'test_Mesh2IODict failed. test 6') 1736 1739 #print "dict['triangle_tags'][0]", dict['triangle_tags'][0] 1737 self.failUnless( 1738 1740 self.failUnless(dict['triangle_tags'][0] == "1.3", 1741 'test_Mesh2IODict failed. test 7') 1739 1742 1740 1743 seg = m.getUserSegments() … … 2198 2201 vert = m.get_user_vertices(absolute=True) 2199 2202 2200 self.failUnless(num.alltrue(vert.flat == num.array(points).flat), 2203 self.failUnless(num.alltrue(vert.flatten() == 2204 num.array(points).flatten()), 2201 2205 'FAILED!') 2202 2206 … … 2307 2311 yes = False 2308 2312 return yes 2309 2310 #------------------------------------------------------------- 2313 2314 ################################################################################ 2315 2311 2316 if __name__ == "__main__": 2312 2317 suite = unittest.makeSuite(meshTestCase,'test') 2313 #suite = unittest.makeSuite(meshTestCase,'mode_string_float_problems')2314 #suite = unittest.makeSuite(meshTestCase,'test_import_mesh')2315 #suite = unittest.makeSuite(meshTestCase,'test_asciiFile')2316 #suite = unittest.makeSuite(meshTestCase,'test_mesh2IO')2317 #suite = unittest.makeSuite(meshTestCase,'test_add_points_and_segmentsII')2318 2318 runner = unittest.TextTestRunner() #verbosity=2) 2319 2319 runner.run(suite) -
anuga_core/source/anuga/pmesh/test_mesh_interface.py
r6973 r7276 1 1 #!/usr/bin/env python 2 # 2 3 3 import tempfile 4 4 import unittest … … 13 13 from anuga.coordinate_transforms.geo_reference import Geo_reference,DEFAULT_ZONE 14 14 15 15 16 class TestCase(unittest.TestCase): 16 17 def setUp(self): 17 18 pass 18 19 19 20 def tearDown(self): 20 21 pass … … 23 24 x=-500 24 25 y=-1000 25 mesh_geo = geo_reference=Geo_reference(56, x,y)26 27 # These are the absolute values 28 polygon_absolute = [[0,0], [100,0],[100,100],[0,100]]29 26 mesh_geo = geo_reference=Geo_reference(56, x, y) 27 28 # These are the absolute values 29 polygon_absolute = [[0,0], [100,0], [100,100], [0,100]] 30 30 31 x_p = -10 31 32 y_p = -40 … … 33 34 polygon = geo_ref_poly.change_points_geo_ref(polygon_absolute) 34 35 35 boundary_tags = {'walls':[0,1],'bom':[2,3]} 36 37 inner1_polygon_absolute = [[10,10],[20,10],[20,20],[10,20]] 38 inner1_polygon = geo_ref_poly. \ 39 change_points_geo_ref(inner1_polygon_absolute) 40 41 inner2_polygon_absolute = [[30,30],[40,30],[40,40],[30,40]] 42 inner2_polygon = geo_ref_poly. \ 43 change_points_geo_ref(inner2_polygon_absolute) 44 45 interior_regions = [(inner1_polygon, 5),(inner2_polygon, 10)] 46 47 #print polygon 48 #print boundary_tags 49 36 boundary_tags = {'walls': [0,1], 'bom': [2,3]} 37 38 inner1_polygon_absolute = [[10,10], [20,10], [20,20], [10,20]] 39 inner1_polygon = geo_ref_poly.\ 40 change_points_geo_ref(inner1_polygon_absolute) 41 42 inner2_polygon_absolute = [[30,30], [40,30], [40,40], [30,40]] 43 inner2_polygon = geo_ref_poly.\ 44 change_points_geo_ref(inner2_polygon_absolute) 45 46 interior_regions = [(inner1_polygon, 5), (inner2_polygon, 10)] 47 50 48 m = create_mesh_from_regions(polygon, 51 49 boundary_tags, … … 56 54 57 55 # Test the mesh instance 58 self.failUnless(len(m.regions)==3, 59 'FAILED!') 56 self.failUnless(len(m.regions)==3, 'FAILED!') 60 57 segs = m.getUserSegments() 61 self.failUnless(len(segs)==12, 62 'FAILED!') 63 self.failUnless(len(m.userVertices)==12, 64 'FAILED!') 65 self.failUnless(segs[0].tag=='walls', 66 'FAILED!') 67 self.failUnless(segs[1].tag=='walls', 68 'FAILED!') 69 70 self.failUnless(segs[2].tag=='bom', 71 'FAILED!') 72 self.failUnless(segs[3].tag=='bom', 73 'FAILED!') 58 self.failUnless(len(segs)==12, 'FAILED!') 59 self.failUnless(len(m.userVertices)==12, 'FAILED!') 60 self.failUnless(segs[0].tag=='walls', 'FAILED!') 61 self.failUnless(segs[1].tag=='walls', 'FAILED!') 62 self.failUnless(segs[2].tag=='bom', 'FAILED!') 63 self.failUnless(segs[3].tag=='bom', 'FAILED!') 74 64 75 65 # Assuming the order of the region points is known. … … 77 67 # a black box) 78 68 poly_point = m.getRegions()[0] 79 80 #print "poly_point", poly_point 81 #print "polygon_absolute",polygon_absolute 82 69 83 70 # poly_point values are relative to the mesh geo-ref 84 71 # make them absolute 85 self.failUnless(is_inside_polygon([poly_point.x+x,poly_point.y+y], 86 polygon_absolute, closed = False), 87 'FAILED!') 88 72 msg = ('Expected point (%s,%s) to be inside polygon %s' 73 % (str(poly_point.x+x), str(poly_point.y+y), 74 str(polygon_absolute))) 75 self.failUnless(is_inside_polygon([poly_point.x+x, poly_point.y+y], 76 polygon_absolute, closed=False), 77 msg) 78 89 79 # Assuming the order of the region points is known. 90 80 # (This isn't true, if you consider create_mesh_from_regions 91 81 # a black box) 92 82 poly_point = m.getRegions()[1] 93 94 #print "poly_point", poly_point 95 #print "polygon_absolute",polygon_absolute 96 83 97 84 # poly_point values are relative to the mesh geo-ref 98 85 # make them absolute 99 self.failUnless(is_inside_polygon([poly_point.x+x, poly_point.y+y],86 self.failUnless(is_inside_polygon([poly_point.x+x, poly_point.y+y], 100 87 inner1_polygon_absolute, 101 closed =False),88 closed=False), 102 89 'FAILED!') 103 90 104 91 # Assuming the order of the region points is known. 105 92 # (This isn't true, if you consider create_mesh_from_regions 106 93 # a black box) 107 94 poly_point = m.getRegions()[2] 108 109 #print "poly_point", poly_point 110 #print "polygon_absolute",polygon_absolute 111 95 112 96 # poly_point values are relative to the mesh geo-ref 113 97 # make them absolute 114 self.failUnless(is_inside_polygon([poly_point.x+x, poly_point.y+y],98 self.failUnless(is_inside_polygon([poly_point.x+x, poly_point.y+y], 115 99 inner2_polygon_absolute, 116 closed =False),100 closed=False), 117 101 'FAILED!') 118 119 102 120 103 def test_create_mesh_from_regions_with_caching(self): 121 104 x=-500 122 105 y=-1000 123 mesh_geo = geo_reference=Geo_reference(56, x,y)124 125 # These are the absolute values 126 polygon_absolute = [[0,0], [100,0],[100,100],[0,100]]127 106 mesh_geo = geo_reference=Geo_reference(56, x, y) 107 108 # These are the absolute values 109 polygon_absolute = [[0,0], [100,0], [100,100], [0,100]] 110 128 111 x_p = -10 129 112 y_p = -40 … … 131 114 polygon = geo_ref_poly.change_points_geo_ref(polygon_absolute) 132 115 133 boundary_tags = {'walls': [0,1],'bom':[2,3]}134 135 inner1_polygon_absolute = [[10,10], [20,10],[20,20],[10,20]]136 inner1_polygon = geo_ref_poly. 137 change_points_geo_ref(inner1_polygon_absolute)138 139 inner2_polygon_absolute = [[30,30], [40,30],[40,40],[30,40]]140 inner2_polygon = geo_ref_poly. 141 change_points_geo_ref(inner2_polygon_absolute)142 143 interior_regions = [(inner1_polygon, 5), (inner2_polygon, 10)]116 boundary_tags = {'walls': [0,1], 'bom': [2,3]} 117 118 inner1_polygon_absolute = [[10,10], [20,10], [20,20], [10,20]] 119 inner1_polygon = geo_ref_poly.\ 120 change_points_geo_ref(inner1_polygon_absolute) 121 122 inner2_polygon_absolute = [[30,30], [40,30], [40,40], [30,40]] 123 inner2_polygon = geo_ref_poly.\ 124 change_points_geo_ref(inner2_polygon_absolute) 125 126 interior_regions = [(inner1_polygon, 5), (inner2_polygon, 10)] 144 127 145 128 interior_holes = None … … 147 130 # Clear cache first 148 131 from anuga.caching import cache 132 149 133 cache(_create_mesh_from_regions, 150 134 (polygon, boundary_tags), … … 159 143 clear=1) 160 144 161 #print polygon162 #print boundary_tags163 164 145 m = create_mesh_from_regions(polygon, 165 146 boundary_tags, … … 173 154 174 155 # Test the mesh instance 175 self.failUnless(len(m.regions)==3, 176 'FAILED!') 156 self.failUnless(len(m.regions)==3, 'FAILED!') 177 157 segs = m.getUserSegments() 178 self.failUnless(len(segs)==12, 179 'FAILED!') 180 self.failUnless(len(m.userVertices)==12, 181 'FAILED!') 182 self.failUnless(segs[0].tag=='walls', 183 'FAILED!') 184 self.failUnless(segs[1].tag=='walls', 185 'FAILED!') 186 187 self.failUnless(segs[2].tag=='bom', 188 'FAILED!') 189 self.failUnless(segs[3].tag=='bom', 190 'FAILED!') 158 self.failUnless(len(segs)==12, 'FAILED!') 159 self.failUnless(len(m.userVertices)==12, 'FAILED!') 160 self.failUnless(segs[0].tag=='walls', 'FAILED!') 161 self.failUnless(segs[1].tag=='walls', 'FAILED!') 162 self.failUnless(segs[2].tag=='bom', 'FAILED!') 163 self.failUnless(segs[3].tag=='bom', 'FAILED!') 191 164 192 165 # Assuming the order of the region points is known. … … 194 167 # a black box) 195 168 poly_point = m.getRegions()[0] 196 197 #print "poly_point", poly_point 198 #print "polygon_absolute",polygon_absolute 199 169 200 170 # poly_point values are relative to the mesh geo-ref 201 171 # make them absolute 202 self.failUnless(is_inside_polygon([poly_point.x+x,poly_point.y+y], 203 polygon_absolute, closed = False), 172 self.failUnless(is_inside_polygon([poly_point.x+x, poly_point.y+y], 173 polygon_absolute, 174 closed=False), 204 175 'FAILED!') 205 176 206 177 # Assuming the order of the region points is known. 207 178 # (This isn't true, if you consider create_mesh_from_regions 208 179 # a black box) 209 180 poly_point = m.getRegions()[1] 210 211 #print "poly_point", poly_point 212 #print "polygon_absolute",polygon_absolute 213 181 214 182 # poly_point values are relative to the mesh geo-ref 215 183 # make them absolute 216 self.failUnless(is_inside_polygon([poly_point.x+x, poly_point.y+y],184 self.failUnless(is_inside_polygon([poly_point.x+x, poly_point.y+y], 217 185 inner1_polygon_absolute, 218 closed =False),186 closed=False), 219 187 'FAILED!') 220 188 221 189 # Assuming the order of the region points is known. 222 190 # (This isn't true, if you consider create_mesh_from_regions 223 191 # a black box) 224 192 poly_point = m.getRegions()[2] 225 226 #print "poly_point", poly_point 227 #print "polygon_absolute",polygon_absolute 228 193 229 194 # poly_point values are relative to the mesh geo-ref 230 195 # make them absolute 231 self.failUnless(is_inside_polygon([poly_point.x+x, poly_point.y+y],196 self.failUnless(is_inside_polygon([poly_point.x+x, poly_point.y+y], 232 197 inner2_polygon_absolute, 233 closed =False),198 closed=False), 234 199 'FAILED!') 235 236 200 237 201 # Now create m using cached values … … 245 209 use_cache=True) 246 210 247 248 249 250 211 def test_create_mesh_from_regions2(self): 251 252 # These are the absolute values 253 min_x = -10 212 # These are the absolute values 213 min_x = -10 254 214 min_y = -88 255 polygon_absolute = [[min_x,min_y], [1000,100],[1000,1000],[100,1000]]256 215 polygon_absolute = [[min_x,min_y], [1000,100], [1000,1000], [100,1000]] 216 257 217 x_p = -10 258 218 y_p = -40 … … 261 221 polygon = geo_ref_poly.change_points_geo_ref(polygon_absolute) 262 222 263 boundary_tags = {'walls': [0,1],'bom':[2,3]}264 265 inner1_polygon_absolute = [[10,10], [20,10],[20,20],[10,20]]266 inner1_polygon = geo_ref_poly. 267 change_points_geo_ref(inner1_polygon_absolute)268 269 inner2_polygon_absolute = [[30,30], [40,30],[40,40],[30,40]]270 inner2_polygon = geo_ref_poly. 271 change_points_geo_ref(inner2_polygon_absolute)272 273 interior_regions = [(inner1_polygon, 5), (inner2_polygon, 10)]223 boundary_tags = {'walls': [0,1], 'bom': [2,3]} 224 225 inner1_polygon_absolute = [[10,10], [20,10], [20,20], [10,20]] 226 inner1_polygon = geo_ref_poly.\ 227 change_points_geo_ref(inner1_polygon_absolute) 228 229 inner2_polygon_absolute = [[30,30], [40,30], [40,40], [30,40]] 230 inner2_polygon = geo_ref_poly.\ 231 change_points_geo_ref(inner2_polygon_absolute) 232 233 interior_regions = [(inner1_polygon, 5), (inner2_polygon, 10)] 274 234 m = create_mesh_from_regions(polygon, 275 235 boundary_tags, … … 277 237 interior_regions=interior_regions, 278 238 poly_geo_reference=geo_ref_poly) 279 280 239 281 240 # Test the mesh instance 282 self.failUnless(len(m.regions)==3, 283 'FAILED!') 241 self.failUnless(len(m.regions)==3, 'FAILED!') 284 242 segs = m.getUserSegments() 285 self.failUnless(len(segs)==12, 286 'FAILED!') 287 self.failUnless(len(m.userVertices)==12, 288 'FAILED!') 289 self.failUnless(segs[0].tag=='walls', 290 'FAILED!') 291 self.failUnless(segs[1].tag=='walls', 292 'FAILED!') 293 294 self.failUnless(segs[2].tag=='bom', 295 'FAILED!') 296 self.failUnless(segs[3].tag=='bom', 297 'FAILED!') 298 299 self.failUnless(m.geo_reference.get_zone()==zone, 300 'FAILED!') 301 self.failUnless(m.geo_reference.get_xllcorner()==min_x, 302 'FAILED!') 303 self.failUnless(m.geo_reference.get_yllcorner()==min_y, 304 'FAILED!') 305 306 243 self.failUnless(len(segs)==12, 'FAILED!') 244 self.failUnless(len(m.userVertices)==12, 'FAILED!') 245 self.failUnless(segs[0].tag=='walls', 'FAILED!') 246 self.failUnless(segs[1].tag=='walls', 'FAILED!') 247 self.failUnless(segs[2].tag=='bom', 'FAILED!') 248 self.failUnless(segs[3].tag=='bom', 'FAILED!') 249 self.failUnless(m.geo_reference.get_zone()==zone, 'FAILED!') 250 self.failUnless(m.geo_reference.get_xllcorner()==min_x, 'FAILED!') 251 self.failUnless(m.geo_reference.get_yllcorner()==min_y, 'FAILED!') 252 307 253 def test_create_mesh_from_regions3(self): 308 309 # These are the absolute values 310 min_x = -10 254 # These are the absolute values 255 min_x = -10 311 256 min_y = -88 312 polygon = [[min_x,min_y], [1000,100],[1000,1000],[100,1000]]313 257 polygon = [[min_x,min_y], [1000,100], [1000,1000], [100,1000]] 258 314 259 315 260 x_p = -10 316 261 y_p = -40 317 262 geo_ref_poly = Geo_reference(56, x_p, y_p) 318 319 boundary_tags = {'walls': [0,1],'bom':[2,3]}320 321 inner1_polygon_absolute = [[10,10], [20,10],[20,20],[10,20]]322 inner1_polygon = geo_ref_poly. 323 change_points_geo_ref(inner1_polygon_absolute)324 325 inner2_polygon_absolute = [[30,30], [40,30],[40,40],[30,40]]326 inner2_polygon = geo_ref_poly. 327 change_points_geo_ref(inner2_polygon_absolute)328 329 interior_regions = [(inner1_polygon, 5), (inner2_polygon, 10)]263 264 boundary_tags = {'walls': [0,1], 'bom': [2,3]} 265 266 inner1_polygon_absolute = [[10,10], [20,10], [20,20], [10,20]] 267 inner1_polygon = geo_ref_poly.\ 268 change_points_geo_ref(inner1_polygon_absolute) 269 270 inner2_polygon_absolute = [[30,30], [40,30], [40,40], [30,40]] 271 inner2_polygon = geo_ref_poly.\ 272 change_points_geo_ref(inner2_polygon_absolute) 273 274 interior_regions = [(inner1_polygon, 5), (inner2_polygon, 10)] 330 275 m = create_mesh_from_regions(polygon, 331 276 boundary_tags, 332 277 10000000, 333 278 interior_regions=interior_regions) 334 335 279 336 280 # Test the mesh instance 337 self.failUnless(len(m.regions)==3, 338 'FAILED!') 281 self.failUnless(len(m.regions) == 3, 'FAILED!') 339 282 segs = m.getUserSegments() 340 self.failUnless(len(segs)==12, 341 'FAILED!') 342 self.failUnless(len(m.userVertices)==12, 343 'FAILED!') 344 self.failUnless(segs[0].tag=='walls', 345 'FAILED!') 346 self.failUnless(segs[1].tag=='walls', 347 'FAILED!') 348 349 self.failUnless(segs[2].tag=='bom', 350 'FAILED!') 351 self.failUnless(segs[3].tag=='bom', 352 'FAILED!') 353 354 self.failUnless(m.geo_reference.get_zone()==DEFAULT_ZONE, 355 'FAILED!') 356 self.failUnless(m.geo_reference.get_xllcorner()==min_x, 357 'FAILED!') 358 self.failUnless(m.geo_reference.get_yllcorner()==min_y, 359 'FAILED!') 283 self.failUnless(len(segs) == 12, 'FAILED!') 284 self.failUnless(len(m.userVertices) == 12, 'FAILED!') 285 self.failUnless(segs[0].tag == 'walls', 'FAILED!') 286 self.failUnless(segs[1].tag == 'walls', 'FAILED!') 287 self.failUnless(segs[2].tag == 'bom', 'FAILED!') 288 self.failUnless(segs[3].tag == 'bom', 'FAILED!') 289 self.failUnless(m.geo_reference.get_zone() == DEFAULT_ZONE, 'FAILED!') 290 self.failUnless(m.geo_reference.get_xllcorner() == min_x, 'FAILED!') 291 self.failUnless(m.geo_reference.get_yllcorner() == min_y, 'FAILED!') 360 292 361 293 def test_create_mesh_from_regions4(self): 362 363 file_name = tempfile.mktemp(".tsh") 364 294 file_name = tempfile.mktemp('.tsh') 295 365 296 # These are the absolute values 366 297 density_outer = 1000 367 min_outer = 0 298 min_outer = 0 368 299 max_outer = 1000 369 polygon_outer = [[min_outer,min_outer], [max_outer,min_outer],370 [max_outer,max_outer],[min_outer,max_outer]]371 300 polygon_outer = [[min_outer,min_outer], [max_outer,min_outer], 301 [max_outer,max_outer], [min_outer,max_outer]] 302 372 303 density_inner1 = 10000000 373 304 inner_buffer = 100 374 305 min_inner1 = min_outer + inner_buffer 375 306 max_inner1 = max_outer - inner_buffer 376 inner1_polygon = [[min_inner1,min_inner1],[max_inner1,min_inner1], 377 [max_inner1,max_inner1],[min_inner1,max_inner1]] 378 379 380 boundary_tags = {'walls':[0,1],'bom':[2,3]} 381 307 inner1_polygon = [[min_inner1,min_inner1], [max_inner1,min_inner1], 308 [max_inner1,max_inner1], [min_inner1,max_inner1]] 309 310 boundary_tags = {'walls': [0,1], 'bom': [2,3]} 311 382 312 interior_regions = [(inner1_polygon, density_inner1)] 383 create_mesh_from_regions(polygon_outer 384 , boundary_tags 385 , density_outer 386 , interior_regions=interior_regions 387 ,filename=file_name 388 #,verbose=True 389 ,verbose=False 390 ) 391 313 create_mesh_from_regions(polygon_outer, 314 boundary_tags, 315 density_outer, 316 interior_regions=interior_regions, 317 filename=file_name, verbose=False) 318 392 319 m = importMeshFromFile(file_name) 393 394 #print "file_name",file_name 320 395 321 self.failUnless(len(m.getTriangulation()) <= 900, 396 322 'Test mesh interface failed!') 397 323 self.failUnless(len(m.getTriangulation()) >= 200, 398 324 'Test mesh interface failed!') 399 400 create_mesh_from_regions(polygon_outer 401 , boundary_tags 402 , interior_regions=interior_regions 403 ,filename=file_name 404 #,verbose=True 405 ,verbose=False 406 ) 407 325 326 create_mesh_from_regions(polygon_outer, 327 boundary_tags, 328 interior_regions=interior_regions, 329 filename=file_name, 330 verbose=False) 331 408 332 m = importMeshFromFile(file_name) 409 410 #print "len(m.meshTriangles)",len(m.meshTriangles) 333 411 334 self.failUnless(len(m.getTriangulation()) <= 100, 412 335 'Test mesh interface failed!') 413 336 414 337 os.remove(file_name) 415 338 416 339 def test_create_mesh_from_regions5(self): 417 418 file_name = tempfile.mktemp(".tsh") 419 420 # These are the absolute values 421 density_outer = 10000000 422 min_outer = 0 340 file_name = tempfile.mktemp('.tsh') 341 342 # These are the absolute values 343 density_outer = 10000000 344 min_outer = 0 423 345 max_outer = 1000 424 polygon_outer = [[min_outer,min_outer], [max_outer,min_outer],425 [max_outer,max_outer],[min_outer,max_outer]]426 346 polygon_outer = [[min_outer,min_outer], [max_outer,min_outer], 347 [max_outer,max_outer], [min_outer,max_outer]] 348 427 349 density_inner1 = 1000 428 350 inner_buffer = 100 429 351 min_inner1 = min_outer + inner_buffer 430 352 max_inner1 = max_outer - inner_buffer 431 inner1_polygon = [[min_inner1,min_inner1],[max_inner1,min_inner1], 432 [max_inner1,max_inner1],[min_inner1,max_inner1]] 433 434 435 boundary_tags = {'walls':[0,1],'bom':[2,3]} 436 353 inner1_polygon = [[min_inner1,min_inner1], [max_inner1,min_inner1], 354 [max_inner1,max_inner1], [min_inner1,max_inner1]] 355 356 boundary_tags = {'walls': [0,1], 'bom': [2,3]} 357 437 358 interior_regions = [(inner1_polygon, density_inner1)] 438 create_mesh_from_regions(polygon_outer 439 , boundary_tags 440 , density_outer 441 , interior_regions=interior_regions 442 ,filename=file_name 443 #,verbose=True 444 ,verbose=False 445 ) 446 359 create_mesh_from_regions(polygon_outer, 360 boundary_tags, 361 density_outer, 362 interior_regions=interior_regions, 363 filename=file_name, 364 verbose=False) 365 447 366 m = importMeshFromFile(file_name) 448 #print "file_name",file_name 449 #print "len(m.meshTriangles",len(m.meshTriangles) 450 self.failUnless(len(m.getTriangulation()) <= 2000, 367 self.failUnless(len(m.getTriangulation()) <= 2000, 451 368 'Test mesh interface failed!') 452 453 369 self.failUnless(len(m.getTriangulation()) >= 900, 454 370 'Test mesh interface failed!') 455 371 456 372 os.remove(file_name) 457 373 458 374 def test_create_mesh_from_regions6(self): 459 460 file_name = tempfile.mktemp(".tsh") 461 375 file_name = tempfile.mktemp('.tsh') 376 462 377 # These are the absolute values 463 378 density_outer = 1000 464 min_outer = 0 379 min_outer = 0 465 380 max_outer = 1000 466 polygon_outer = [[min_outer,min_outer], [max_outer,min_outer],467 [max_outer,max_outer], [min_outer,max_outer]]381 polygon_outer = [[min_outer,min_outer], [max_outer,min_outer], 382 [max_outer,max_outer], [min_outer,max_outer]] 468 383 469 384 delta = 10 … … 471 386 min_inner1 = min_outer + delta 472 387 max_inner1 = max_outer - delta 473 inner1_polygon = [[min_inner1,min_inner1],[max_inner1,min_inner1], 474 [max_inner1,max_inner1],[min_inner1,max_inner1]] 475 476 477 density_inner2 = 10000000 388 inner1_polygon = [[min_inner1,min_inner1], [max_inner1,min_inner1], 389 [max_inner1,max_inner1], [min_inner1,max_inner1]] 390 391 density_inner2 = 10000000 478 392 min_inner2 = min_outer + 2*delta 479 393 max_inner2 = max_outer - 2*delta 480 inner2_polygon = [[min_inner2,min_inner2], [max_inner2,min_inner2],481 [max_inner2,max_inner2], [min_inner2,max_inner2]]482 483 boundary_tags = {'walls': [0,1],'bom':[2,3]}484 394 inner2_polygon = [[min_inner2,min_inner2], [max_inner2,min_inner2], 395 [max_inner2,max_inner2], [min_inner2,max_inner2]] 396 397 boundary_tags = {'walls': [0,1], 'bom': [2,3]} 398 485 399 interior_regions = [(inner1_polygon, density_inner1), 486 400 (inner2_polygon, density_inner2)] … … 491 405 filename=file_name, 492 406 verbose=False) 493 407 494 408 m = importMeshFromFile(file_name) 495 #print "file_name",file_name 496 #print "len(m.meshTriangles",len(m.meshTriangles) 497 self.failUnless(len(m.getTriangulation()) <= 2000, 409 self.failUnless(len(m.getTriangulation()) <= 2000, 498 410 'Test mesh interface failed!') 499 500 411 self.failUnless(len(m.getTriangulation()) >= 900, 501 412 'Test mesh interface failed!') 502 413 503 414 os.remove(file_name) 504 415 505 416 def test_create_mesh_from_regions7(self): 506 507 file_name = tempfile.mktemp(".tsh") 508 417 file_name = tempfile.mktemp('.tsh') 418 509 419 # These are the absolute values 510 420 density_outer = 1001 511 min_outer = 0 421 min_outer = 0 512 422 max_outer = 1000 513 polygon_outer = [[min_outer,min_outer], [max_outer,min_outer],514 [max_outer,max_outer],[min_outer,max_outer]]423 polygon_outer = [[min_outer,min_outer], [max_outer,min_outer], 424 [max_outer,max_outer], [min_outer,max_outer]] 515 425 516 426 delta = 10 … … 518 428 min_inner1 = min_outer + delta 519 429 max_inner1 = max_outer - delta 520 inner1_polygon = [[min_inner1,min_inner1],[max_inner1,min_inner1], 521 [max_inner1,max_inner1],[min_inner1,max_inner1]] 522 523 524 density_inner2 = 1000 430 inner1_polygon = [[min_inner1,min_inner1], [max_inner1,min_inner1], 431 [max_inner1,max_inner1], [min_inner1,max_inner1]] 432 433 density_inner2 = 1000 525 434 min_inner2 = min_outer + 2*delta 526 435 max_inner2 = max_outer - 2*delta 527 inner2_polygon = [[min_inner2,min_inner2], [max_inner2,min_inner2],528 [max_inner2,max_inner2],[min_inner2,max_inner2]]529 530 boundary_tags = {'walls': [0,1],'bom':[2,3]}531 532 # Note the list order is important436 inner2_polygon = [[min_inner2,min_inner2], [max_inner2,min_inner2], 437 [max_inner2,max_inner2], [min_inner2,max_inner2]] 438 439 boundary_tags = {'walls': [0,1], 'bom': [2,3]} 440 441 # Note the list order is important 533 442 # The last region added will be the region triangle uses, 534 443 # if two regions points are in the same bounded area. 535 interior_regions = [(inner2_polygon, density_inner2),(inner1_polygon, density_inner1)] 444 interior_regions = [(inner2_polygon, density_inner2), 445 (inner1_polygon, density_inner1)] 536 446 create_mesh_from_regions(polygon_outer, 537 447 boundary_tags, … … 540 450 filename=file_name, 541 451 verbose=False) 542 452 543 453 m = importMeshFromFile(file_name) 544 #print "file_name",file_name 545 #print "len(m.meshTriangles",len(m.meshTriangles) 546 self.failUnless(len(m.getTriangulation()) <= 3000, 454 self.failUnless(len(m.getTriangulation()) <= 3000, 547 455 'Test mesh interface failed!') 548 549 456 self.failUnless(len(m.getTriangulation()) >= 2000, 550 457 'Test mesh interface failed!') … … 552 459 os.remove(file_name) 553 460 554 555 461 def test_create_mesh_from_regions_interior_regions(self): 556 """Test that create_mesh_from_regions fails when an interior region is557 outside bounding polygon. """558 559 560 # These are the absolute values 561 min_x = 10 462 '''Test that create_mesh_from_regions fails when an interior 463 region is outside bounding polygon. 464 ''' 465 466 # These are the absolute values 467 min_x = 10 562 468 min_y = 88 563 polygon = [[min_x,min_y], [1000,100],[1000,1000],[100,1000]]564 565 boundary_tags = {'walls': [0,1],'bom':[2,3]}566 # boundary_tags = {'walls':[0,1]} 469 polygon = [[min_x,min_y], [1000,100], [1000,1000], [100,1000]] 470 471 boundary_tags = {'walls': [0,1], 'bom': [2,3]} 472 567 473 # This one is inside bounding polygon - should pass 568 inner_polygon = [[800,400], [900,500],[800,600]]474 inner_polygon = [[800,400], [900,500], [800,600]] 569 475 570 476 interior_regions = [(inner_polygon, 5)] … … 574 480 interior_regions=interior_regions) 575 481 576 577 482 # This one sticks outside bounding polygon - should fail 578 inner_polygon = [[800,400], [900,500],[800,600], [200, 995]]579 inner_polygon1 = [[800,400], [1100,500],[800,600]]483 inner_polygon = [[800,400], [900,500], [800,600], [200, 995]] 484 inner_polygon1 = [[800,400], [1100,500], [800,600]] 580 485 interior_regions = [[inner_polygon, 50], [inner_polygon1, 50]] 581 486 582 583 584 487 try: 585 488 m = create_mesh_from_regions(polygon, … … 593 496 msg = 'Interior polygon sticking outside bounding polygon should ' 594 497 msg += 'cause an Exception to be raised' 595 raise msg498 raise Exception, msg 596 499 597 500 def test_create_mesh_from_regions_interior_regions1(self): 598 """Test that create_mesh_from_regions fails when an interior region is599 outside bounding polygon. """600 501 '''Test that create_mesh_from_regions fails 502 when an interior region is outside bounding polygon. 503 ''' 601 504 602 505 # These are the values 603 604 506 d0 = [310000, 7690000] 605 507 d1 = [280000, 7690000] … … 609 511 d5 = [300000, 7590000] 610 512 d6 = [340000, 7610000] 611 612 513 poly_all = [d0, d1, d2, d3, d4, d5, d6] 613 514 614 515 i0 = [304000, 7607000] 615 516 i1 = [302000, 7605000] … … 619 520 # i4 = [310000, 7580000] 620 521 i5 = [307000, 7606000] 621 622 522 poly_onslow = [i0, i1, i2, i3, i4, i5] 623 523 624 # Thevenard Island524 # Thevenard Island 625 525 j0 = [294000, 7629000] 626 526 j1 = [285000, 7625000] 627 527 j2 = [294000, 7621000] 628 528 j3 = [299000, 7625000] 629 630 529 poly_thevenard = [j0, j1, j2, j3] 631 530 632 # med res around onslow531 # med res around onslow 633 532 l0 = [300000, 7610000] 634 533 l1 = [285000, 7600000] 635 534 l2 = [300000, 7597500] 636 l3 = [310000, 7770000] # this one is outside637 # l3 = [310000, 7630000] # this one is NOT outside535 l3 = [310000, 7770000] # this one is outside 536 # l3 = [310000, 7630000] # this one is NOT outside 638 537 l4 = [315000, 7610000] 639 538 poly_coast = [l0, l1, l2, l3, l4] 640 539 641 # general coast and local area to onslow region540 # general coast and local area to onslow region 642 541 m0 = [270000, 7581000] 643 542 m1 = [300000, 7591000] … … 646 545 m4 = [290000, 7640000] 647 546 m5 = [260000, 7600000] 648 649 547 poly_region = [m0, m1, m2, m3, m4, m5] 650 548 651 549 # This one sticks outside bounding polygon - should fail 652 653 interior_regions = [[poly_onslow, 50000], [poly_region, 50000], [poly_coast,100000], [poly_thevenard, 100000]] 654 655 boundary_tags = {'walls':[0,1],'bom':[2]} 656 550 interior_regions = [[poly_onslow, 50000], [poly_region, 50000], 551 [poly_coast, 100000], [poly_thevenard, 100000]] 552 boundary_tags = {'walls': [0,1], 'bom': [2]} 553 657 554 try: 658 555 m = create_mesh_from_regions(poly_all, … … 666 563 msg = 'Interior polygon sticking outside bounding polygon should ' 667 564 msg += 'cause an Exception to be raised' 668 raise msg 669 670 565 raise Exception, msg 671 566 672 567 def FIXME_test_create_mesh_with_multiply_tagged_segments(self): 673 """Test that create_mesh_from_regions fails when segments are listed repeatedly in boundary_tags. 674 """ 675 676 # FIXME(Ole): Who wrote this and why doesn't it pass? 677 678 679 # These are the absolute values 680 min_x = 10 568 '''Test that create_mesh_from_regions fails when 569 segments are listed repeatedly in boundary_tags. 570 ''' 571 572 # These are the absolute values 573 min_x = 10 681 574 min_y = 88 682 polygon = [[min_x,min_y],[1000,100],[1000,1000],[100,1000]] 683 684 685 boundary_tags = {'walls':[0,1],'bom':[1,2]} 575 polygon = [[min_x,min_y], [1000,100], [1000,1000], [100,1000]] 576 boundary_tags = {'walls': [0,1], 'bom': [1,2]} 686 577 687 578 # This one is inside bounding polygon - should pass 688 inner_polygon = [[800,400],[900,500],[800,600]] 689 579 inner_polygon = [[800,400], [900,500], [800,600]] 690 580 interior_regions = [(inner_polygon, 5)] 691 581 m = create_mesh_from_regions(polygon, 692 582 boundary_tags, 693 583 10000000, 694 interior_regions=interior_regions, verbose=False)695 584 interior_regions=interior_regions, 585 verbose=False) 696 586 697 587 # This one sticks outside bounding polygon - should fail 698 inner_polygon = [[800,400], [900,500],[800,600]]588 inner_polygon = [[800,400], [900,500], [800,600]] 699 589 interior_regions = [(inner_polygon, 5)] 700 701 590 702 591 m = create_mesh_from_regions(polygon, … … 716 605 raise Exception, msg 717 606 718 719 607 720 608 def test_create_mesh_with_segments_out_of_bounds(self): … … 752 640 753 641 def test_create_mesh_from_regions_with_duplicate_verts(self): 754 755 # These are the absolute values 756 757 polygon_absolute = [[0.0,0.0], 758 [0,4.0], 759 [4.0,4.0], 760 [4.0,0.0], 761 [4.0,0.0]] 762 642 # These are the absolute values 643 polygon_absolute = [[0.0, 0.0], 644 [0, 4.0], 645 [4.0, 4.0], 646 [4.0, 0.0], 647 [4.0, 0.0]] 763 648 x_p = -10 764 649 y_p = -40 … … 766 651 geo_ref_poly = Geo_reference(zone, x_p, y_p) 767 652 polygon = geo_ref_poly.change_points_geo_ref(polygon_absolute) 768 769 boundary_tags = {'50':[0], 770 '40':[1], 771 '30':[2], 772 'no where seg':[3], 773 '20':[4] 774 } 775 653 boundary_tags = {'50': [0], 654 '40': [1], 655 '30': [2], 656 'no where seg': [3], 657 '20': [4]} 776 658 m = create_mesh_from_regions(polygon, 777 659 boundary_tags, 778 660 10000000, 779 poly_geo_reference=geo_ref_poly, verbose=False)780 781 782 fileName = "badmesh.tsh"661 poly_geo_reference=geo_ref_poly, 662 verbose=False) 663 664 fileName = 'badmesh.tsh' 783 665 #m.export_mesh_file(fileName) 784 785 666 786 667 def concept_create_mesh_from_regions_with_ungenerate(self): 787 668 x=0 788 669 y=0 789 mesh_geo = geo_reference=Geo_reference(56,x,y) 790 791 # These are the absolute values 792 polygon_absolute = [[0,0],[100,0],[100,100],[0,100]] 793 670 mesh_geo = geo_reference=Geo_reference(56, x, y) 671 672 # These are the absolute values 673 polygon_absolute = [[0,0], [100,0], [100,100], [0,100]] 794 674 x_p = -10 795 675 y_p = -40 … … 797 677 polygon = geo_ref_poly.change_points_geo_ref(polygon_absolute) 798 678 799 boundary_tags = {'walls': [0,1],'bom':[2]}800 801 inner1_polygon_absolute = [[10,10], [20,10],[20,20],[10,20]]802 inner1_polygon = geo_ref_poly. 803 change_points_geo_ref(inner1_polygon_absolute)804 805 inner2_polygon_absolute = [[30,30], [40,30],[40,40],[30,40]]806 inner2_polygon = geo_ref_poly. 807 change_points_geo_ref(inner2_polygon_absolute)808 679 boundary_tags = {'walls': [0,1], 'bom': [2]} 680 681 inner1_polygon_absolute = [[10,10], [20,10], [20,20], [10,20]] 682 inner1_polygon = geo_ref_poly.\ 683 change_points_geo_ref(inner1_polygon_absolute) 684 685 inner2_polygon_absolute = [[30,30], [40,30], [40,40], [30,40]] 686 inner2_polygon = geo_ref_poly.\ 687 change_points_geo_ref(inner2_polygon_absolute) 688 809 689 max_area = 10000000 810 interior_regions = [(inner1_polygon, 5), (inner2_polygon, 10)]690 interior_regions = [(inner1_polygon, 5), (inner2_polygon, 10)] 811 691 m = create_mesh_from_regions(polygon, 812 692 boundary_tags, … … 815 695 poly_geo_reference=geo_ref_poly, 816 696 mesh_geo_reference=mesh_geo) 817 818 m.export_mesh_file('a_test_mesh_iknterface.tsh') 819 820 fileName = tempfile.mktemp( ".txt")821 file = open(fileName, "w")822 file.write( "1 ?? ??\n\697 698 m.export_mesh_file('a_test_mesh_iknterface.tsh') 699 700 fileName = tempfile.mktemp('.txt') 701 file = open(fileName, 'w') 702 file.write(' 1 ?? ??\n\ 823 703 90.0 90.0\n\ 824 704 81.0 90.0\n\ … … 833 713 10.0 80.0\n\ 834 714 END\n\ 835 END\n ")836 file.close() 837 715 END\n') 716 file.close() 717 838 718 m.import_ungenerate_file(fileName, tag='wall') 839 719 os.remove(fileName) 840 m.generate_mesh(maximum_triangle_area=max_area, verbose=False)720 m.generate_mesh(maximum_triangle_area=max_area, verbose=False) 841 721 m.export_mesh_file('b_test_mesh_iknterface.tsh') 842 722 843 723 def concept_ungenerateII(self): 844 845 724 from anuga.shallow_water import Domain, Reflective_boundary, \ 846 725 Dirichlet_boundary 726 847 727 x=0 848 728 y=0 849 mesh_geo = geo_reference=Geo_reference(56,x,y) 850 851 # These are the absolute values 852 polygon_absolute = [[0,0],[100,0],[100,100],[0,100]] 853 729 mesh_geo = geo_reference=Geo_reference(56, x, y) 730 731 # These are the absolute values 732 polygon_absolute = [[0,0], [100,0], [100,100], [0,100]] 854 733 x_p = -10 855 734 y_p = -40 … … 857 736 polygon = geo_ref_poly.change_points_geo_ref(polygon_absolute) 858 737 859 boundary_tags = {'wall': [0,1,3],'wave':[2]}860 861 inner1_polygon_absolute = [[10,10], [20,10],[20,20],[10,20]]862 inner1_polygon = geo_ref_poly. 863 change_points_geo_ref(inner1_polygon_absolute)864 865 inner2_polygon_absolute = [[30,30], [40,30],[40,40],[30,40]]866 inner2_polygon = geo_ref_poly. 867 change_points_geo_ref(inner2_polygon_absolute)868 738 boundary_tags = {'wall': [0,1,3], 'wave': [2]} 739 740 inner1_polygon_absolute = [[10,10], [20,10], [20,20], [10,20]] 741 inner1_polygon = geo_ref_poly.\ 742 change_points_geo_ref(inner1_polygon_absolute) 743 744 inner2_polygon_absolute = [[30,30], [40,30], [40,40], [30,40]] 745 inner2_polygon = geo_ref_poly.\ 746 change_points_geo_ref(inner2_polygon_absolute) 747 869 748 max_area = 1 870 interior_regions = [(inner1_polygon, 5), (inner2_polygon, 10)]749 interior_regions = [(inner1_polygon, 5), (inner2_polygon, 10)] 871 750 m = create_mesh_from_regions(polygon, 872 751 boundary_tags, … … 875 754 poly_geo_reference=geo_ref_poly, 876 755 mesh_geo_reference=mesh_geo) 877 878 m.export_mesh_file('a_test_mesh_iknterface.tsh') 879 880 fileName = tempfile.mktemp( ".txt")881 file = open(fileName, "w")882 file.write( "1 ?? ??\n\756 757 m.export_mesh_file('a_test_mesh_iknterface.tsh') 758 759 fileName = tempfile.mktemp('.txt') 760 file = open(fileName, 'w') 761 file.write(' 1 ?? ??\n\ 883 762 90.0 90.0\n\ 884 763 81.0 90.0\n\ … … 893 772 10.0 80.0\n\ 894 773 END\n\ 895 END\n ")896 file.close() 897 898 m.import_ungenerate_file(fileName) #, tag='wall')774 END\n') 775 file.close() 776 777 m.import_ungenerate_file(fileName) #, tag='wall') 899 778 os.remove(fileName) 900 m.generate_mesh(maximum_triangle_area=max_area, verbose=False)901 mesh_filename = "bento_b.tsh"779 m.generate_mesh(maximum_triangle_area=max_area, verbose=False) 780 mesh_filename = 'bento_b.tsh' 902 781 m.export_mesh_file(mesh_filename) 903 782 904 783 domain = Domain(mesh_filename, use_cache = False) 905 784 906 785 Br = Reflective_boundary(domain) 907 Bd = Dirichlet_boundary([3, 0,0])908 domain.set_boundary( {'wall': Br, 'wave': Bd})786 Bd = Dirichlet_boundary([3, 0, 0]) 787 domain.set_boundary({'wall': Br, 'wave': Bd}) 909 788 yieldstep = 0.1 910 789 finaltime = 10 911 for t in domain.evolve(yieldstep, finaltime): 790 for t in domain.evolve(yieldstep, finaltime): 912 791 domain.write_time() 913 792 914 793 def concept_ungenerateIII(self): 915 916 794 from anuga.shallow_water import Domain, Reflective_boundary, \ 917 795 Dirichlet_boundary 918 919 796 from anuga.pmesh.mesh_interface import create_mesh_from_regions 920 921 # These are the absolute values 922 polygon = [[0,0],[100,0],[100,100],[0,100]] 923 924 boundary_tags = {'wall':[0,1,3],'wave':[2]} 925 926 inner1_polygon = [[10,10],[20,10],[20,20],[10,20]] 927 928 929 inner2_polygon = [[30,30],[40,30],[40,40],[30,40]] 930 931 797 798 # These are the absolute values 799 polygon = [[0,0], [100,0], [100,100], [0,100]] 800 801 boundary_tags = {'wall': [0,1,3], 'wave': [2]} 802 inner1_polygon = [[10,10], [20,10], [20,20], [10,20]] 803 inner2_polygon = [[30,30], [40,30], [40,40], [30,40]] 804 932 805 max_area = 1 933 interior_regions = [(inner1_polygon, 5), (inner2_polygon, 10)]806 interior_regions = [(inner1_polygon, 5), (inner2_polygon, 10)] 934 807 m = create_mesh_from_regions(polygon, 935 808 boundary_tags, 936 809 max_area, 937 810 interior_regions=interior_regions) 938 939 fileName = tempfile.mktemp( ".txt")940 file = open(fileName, "w")941 file.write( "1 ?? ??\n\811 812 fileName = tempfile.mktemp('.txt') 813 file = open(fileName, 'w') 814 file.write(' 1 ?? ??\n\ 942 815 90.0 90.0\n\ 943 816 81.0 90.0\n\ … … 952 825 10.0 80.0\n\ 953 826 END\n\ 954 END\n ")955 file.close() 956 957 m.import_ungenerate_file(fileName) 827 END\n') 828 file.close() 829 830 m.import_ungenerate_file(fileName) 958 831 os.remove(fileName) 959 m.generate_mesh(maximum_triangle_area=max_area, verbose=False)960 mesh_filename = "mesh.tsh"832 m.generate_mesh(maximum_triangle_area=max_area, verbose=False) 833 mesh_filename = 'mesh.tsh' 961 834 m.export_mesh_file(mesh_filename) 962 835 963 domain = Domain(mesh_filename, use_cache =False)964 836 domain = Domain(mesh_filename, use_cache=False) 837 965 838 Br = Reflective_boundary(domain) 966 Bd = Dirichlet_boundary([3, 0,0])967 domain.set_boundary( {'wall': Br, 'wave': Bd})839 Bd = Dirichlet_boundary([3, 0, 0]) 840 domain.set_boundary({'wall': Br, 'wave': Bd}) 968 841 yieldstep = 0.1 969 842 finaltime = 10 970 for t in domain.evolve(yieldstep, finaltime): 843 for t in domain.evolve(yieldstep, finaltime): 971 844 domain.write_time() 972 845 973 974 975 846 def test_create_mesh_from_regions_check_segs(self): 976 """Test that create_mesh_from_regions fails when an interior region is977 outside bounding polygon. """978 979 980 # These are the absolute values 981 min_x = 10 847 '''Test that create_mesh_from_regions fails 848 when an interior region is outside bounding polygon. 849 ''' 850 851 # These are the absolute values 852 min_x = 10 982 853 min_y = 88 983 polygon = [[min_x,min_y],[1000,100],[1000,1000],[100,1000]] 984 985 boundary_tags = {'walls':[0,1,3],'bom':[2]} 986 # boundary_tags = {'walls':[0,1]} 854 polygon = [[min_x,min_y], [1000,100], [1000,1000], [100,1000]] 855 boundary_tags = {'walls': [0,1,3], 'bom': [2]} 856 987 857 # This one is inside bounding polygon - should pass 988 inner_polygon = [[800,400],[900,500],[800,600]] 989 858 inner_polygon = [[800,400], [900,500], [800,600]] 990 859 interior_regions = [(inner_polygon, 5)] 991 860 m = create_mesh_from_regions(polygon, … … 994 863 interior_regions=interior_regions) 995 864 996 boundary_tags = {'walls':[0,1,3,4],'bom':[2]} 997 865 boundary_tags = {'walls': [0,1,3,4], 'bom': [2]} 998 866 try: 999 867 m = create_mesh_from_regions(polygon, … … 1004 872 pass 1005 873 else: 1006 msg = ' segment out of bounds not caught '1007 raise msg1008 1009 1010 #------------------------------------------------------------- 874 msg = 'Segment out of bounds not caught ' 875 raise Exception, msg 876 877 ################################################################################ 878 1011 879 if __name__ == "__main__": 1012 suite = unittest.makeSuite(TestCase, 'test') 1013 #suite = unittest.makeSuite(TestCase,'test_create_mesh_from_regions_check_segs') 880 suite = unittest.makeSuite(TestCase,'test') 1014 881 runner = unittest.TextTestRunner() #verbosity=2) 1015 882 runner.run(suite) 1016 883
Note: See TracChangeset
for help on using the changeset viewer.