Changeset 3193
- Timestamp:
- Jun 21, 2006, 3:33:49 PM (18 years ago)
- Location:
- inundation/pmesh
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/pmesh/mesh.py
r3180 r3193 31 31 from geospatial_data.geospatial_data import Geospatial_data, ensure_geospatial 32 32 33 try: 34 import kinds 35 except ImportError: 36 # Hand-built mockup of the things we need from the kinds package, since it 37 # was recently removed from the standard Numeric distro. Some users may 38 # not have it by default. 39 class _bunch: 40 pass 41 42 class _kinds(_bunch): 43 default_float_kind = _bunch() 44 default_float_kind.MIN = 2.2250738585072014e-308 #smallest +ve number 45 default_float_kind.MAX = 1.7976931348623157e+308 46 47 kinds = _kinds() 48 33 49 SET_COLOUR='red' 34 50 … … 225 241 226 242 def setMaxArea(self,MaxArea): 227 if self.isMaxArea(): 228 self.attributes[self.MAXAREA] = float(MaxArea) 229 else: 230 self.attributes.append( float(MaxArea) ) 243 if MaxArea is not None: 244 if self.isMaxArea(): 245 self.attributes[self.MAXAREA] = float(MaxArea) 246 else: 247 self.attributes.append( float(MaxArea) ) 231 248 232 249 def deleteMaxArea(self): … … 940 957 941 958 def generate_mesh(self, 942 maximum_triangle_area= None,959 maximum_triangle_area="", 943 960 minimum_triangle_angle=28.0, 944 verbose= False):961 verbose=True): 945 962 if verbose is True: 946 963 silent = '' … … 990 1007 if maxArea != None: 991 1008 self.mode += 'a' + str(maxArea) 992 #FIXME (DSG-DSG) This isn't explained. I don't think it works 993 # well with maxArea = None as well. 1009 #FIXME (DSG-DSG) This isn't explained. 994 1010 if isRegionalMaxAreas: 995 1011 self.mode += 'a' 996 1012 #print "mesh#generateMesh# self.mode",self.mode 997 1013 meshDict = self.Mesh2triangList() 998 1014 #print "*************************!@!@ This is going to triangle !@!@" … … 1783 1799 Structure: list of verts 1784 1800 """ 1785 # FIXME dsg!!! large is a hack 1786 #You want the kinds package, part of Numeric: 1787 #In [2]: import kinds 1788 1789 #In [3]: kinds.default_float_kind.M 1790 #kinds.default_float_kind.MAX kinds.default_float_kind.MIN 1791 #kinds.default_float_kind.MAX_10_EXP kinds.default_float_kind.MIN_10_EXP 1792 #kinds.default_float_kind.MAX_EXP kinds.default_float_kind.MIN_EXP 1793 1794 #In [3]: kinds.default_float_kind.MIN 1795 #Out[3]: 2.2250738585072014e-308 1796 1797 large = 1e100 1801 1802 large = kinds.default_float_kind.MAX 1798 1803 xmin= large 1799 1804 xmax=-large … … 1827 1832 Structure: [xmin, ymin, xmax, ymax] 1828 1833 """ 1829 # FIXME dsg!!! large is a hack 1830 #You want the kinds package, part of Numeric: 1831 #In [2]: import kinds 1832 1833 #In [3]: kinds.default_float_kind.M 1834 #kinds.default_float_kind.MAX kinds.default_float_kind.MIN 1835 #kinds.default_float_kind.MAX_10_EXP kinds.default_fltesting oat_kind.MIN_10_EXP 1836 #kinds.default_float_kind.MAX_EXP kinds.default_float_kind.MIN_EXP 1837 1838 #In [3]: kinds.default_float_kind.MIN 1839 #Out[3]: 2.2250738585072014e-308 1840 1841 large = 1e100 1834 1835 large = kinds.default_float_kind.MAX 1842 1836 xmin= large 1843 1837 xmax=-large … … 1862 1856 Structure: [xmin, ymin, xmax, ymax] 1863 1857 """ 1864 # FIXME dsg!!! large is a hacktesting 1865 #You want the kinds package, part of Numeric: 1866 #In [2]: import kinds 1867 1868 #In [3]: kinds.default_float_kind.M 1869 #kinds.default_float_kind.MAX kinds.default_float_kind.MIN 1870 #kinds.default_float_kind.MAX_10_EXP kinds.default_float_kind.MIN_10_EXP 1871 #kinds.default_float_kind.MAX_EXP kinds.default_float_kind.MIN_EXP 1872 1873 #In [3]: kinds.default_float_kind.MIN 1874 #Out[3]: 2.2250738585072014e-308 1875 1876 large = 1e100 1858 1859 large = kinds.default_float_kind.MAX 1877 1860 min= large 1878 1861 max=-large -
inundation/pmesh/mesh_interface.py
r3183 r3193 22 22 def create_mesh_from_regions(bounding_polygon, 23 23 boundary_tags, 24 maximum_triangle_area ,24 maximum_triangle_area=None, 25 25 filename=None, 26 26 interior_regions=None, 27 27 poly_geo_reference=None, 28 28 mesh_geo_reference=None, 29 minimum_triangle_angle=28.0): 29 minimum_triangle_angle=28.0, 30 verbose=True): 30 31 """Create mesh from bounding polygons, and resolutions. 31 32 … … 36 37 is a list of indices referring to segments associated with that tag 37 38 38 Resolution is the maximal area per triangle for the bounding polygon39 (excluding interior regions, see later)39 maximum_triangle_area is the maximal area per triangle 40 for the bounding polygon, excluding the interior regions. 40 41 41 42 Interior_regions is a list of tuples consisting of (polygon, resolution) … … 45 46 pmesh functionality for that 46 47 47 poly_geo_reference is the geo_reference of the polygons.48 The bounding polygon and the interior polygons48 poly_geo_reference is the geo_reference of the bounding polygon and 49 the interior polygons. 49 50 If none, assume absolute. Please pass one though, since absolute 50 51 references have a zone. … … 62 63 """ 63 64 #FIXME (OLE-DSG) 64 # To do make maximum_triangle_area optional?65 65 # check the segment indexes - throw an error if they are out of bounds 66 66 #(DSG) Yes! … … 117 117 excluded_polygons = None 118 118 119 from Numeric import array120 121 122 119 # Convert bounding poly to absolute values 123 120 # this sort of thing can be fixed with the geo_points class … … 157 154 else: 158 155 m.generate_mesh(minimum_triangle_angle=minimum_triangle_angle, 159 maximum_triangle_area=maximum_triangle_area)156 verbose=verbose) 160 157 m.export_mesh_file(filename) 161 158 -
inundation/pmesh/test_all.py
r2307 r3193 89 89 90 90 #FIXME: Temporary measure 91 os.chdir('..' + sep + ' triangle')91 os.chdir('..' + sep + 'mesh_engine') 92 92 execfile('compile.py') 93 93 os.chdir('..' + sep + 'pmesh') -
inundation/pmesh/test_mesh.py
r3177 r3193 176 176 self.failUnless(len(m.meshTriangles) == 2, 177 177 'test_regionalMaxArea 5:generated mesh is wrong!') 178 179 ## Another test case 180 r1 = Region(3, 1,tag = 1.3, maxArea = 8) 181 r2 = Region(1, 3,tag = 1.3, maxArea = 8) 182 m = Mesh(userVertices=[v0,v1,v2,v3], userSegments=[s1,s2,s3,s4,s5], 183 regions=[r1,r2] ) 184 m.generateMesh("Q",isRegionalMaxAreas = False ) 185 self.failUnless(len(m.meshTriangles) == 2, 186 'test_regionalMaxArea 5:generated mesh is wrong!') 187 188 def test_generate_mesh(self): 189 v0 = Vertex (0.0, 0.0) 190 v1 = Vertex (6.0, 0.0) 191 v2 = Vertex (6.0,6.0) 192 v3 = Vertex (0.0,6.0) 193 194 s1 = Segment(v0,v1) 195 s2 = Segment(v1,v2) 196 s3 = Segment(v3,v2) 197 s4 = Segment(v3,v0) 198 s5 = Segment(v2,v0) 199 200 r1 = Region(3, 1,tag = 1.3) 201 #print r1 202 m = Mesh(userVertices=[v0,v1,v2,v3], userSegments=[s1,s2,s3,s4,s5], 203 regions=[r1] ) 204 205 m.generate_mesh(maximum_triangle_area=36,verbose=False) 206 207 self.failUnless(len(m.meshTriangles) == 2, 208 'test_regionalMaxArea 1:generated mesh is wrong!') 209 210 ## Another test case 211 r1 = Region(3, 1,tag = 1.3) 212 r2 = Region(1, 3,tag = 1.3, maxArea = 8) 213 m = Mesh(userVertices=[v0,v1,v2,v3], userSegments=[s1,s2,s3,s4,s5], 214 regions=[r1,r2] ) 215 m.generate_mesh(maximum_triangle_area=36,verbose=False) 216 217 self.failUnless(len(m.meshTriangles) >= 6, 218 'testregion_with_maxarea 2: # of tris is wrong!') 219 220 ## Another test case 221 r1 = Region(3, 1, tag = 1.3, maxArea = 8) 222 r2 = Region(1, 3, tag = 1.3, maxArea = 8) 223 m = Mesh(userVertices=[v0,v1,v2,v3], userSegments=[s1,s2,s3,s4,s5], 224 regions=[r1,r2] ) 225 m.generate_mesh(maximum_triangle_area=36,verbose=False) 226 #print "len(m.meshTriangles)",len(m.meshTriangles) 227 228 self.failUnless(len(m.meshTriangles) >= 8, 229 'testregion_with_maxarea 3: # of tris is wrong!') 230 231 ## Another test case 232 r1 = Region(3, 1, tag = 1.3 ) 233 r2 = Region(1, 3, tag = 1.3, maxArea = 8) 234 m = Mesh(userVertices=[v0,v1,v2,v3], userSegments=[s1,s2,s3,s4,s5], 235 regions=[r1,r2] ) 236 m.generate_mesh(maximum_triangle_area=8,verbose=False) 237 self.failUnless(len(m.meshTriangles) >= 8, 238 'testregion_with_maxarea 4: # of tris is wrong!') 239 240 ## Another test case r1 = Region(3, 1,tag = 1.3, maxArea = 8) 241 r2 = Region(1, 3,tag = 1.3, maxArea = 8) 242 m = Mesh(userVertices=[v0,v1,v2,v3], 243 userSegments=[s1,s2,s3,s4,s5], regions=[r1,r2] ) 244 m.generate_mesh(verbose=False) 245 #print "en(m.meshTriangles)", len(m.meshTriangles) 246 self.failUnless(len(m.meshTriangles) >= 8, 247 'You have issues!') 178 248 179 249 def testdeleteUserVertex(self): -
inundation/pmesh/test_mesh_interface.py
r3126 r3193 3 3 import tempfile 4 4 import unittest 5 import os 6 from mesh import importMeshFromFile 5 7 from mesh_interface import * 6 8 from load_mesh.loadASCII import * … … 221 223 'FAILED!') 222 224 225 def test_create_mesh_from_regions4(self): 226 227 file_name = tempfile.mktemp(".tsh") 228 229 # These are the absolute values 230 density_outer = 1000 231 min_outer = 0 232 max_outer = 1000 233 polygon_outer = [[min_outer,min_outer],[max_outer,min_outer], 234 [max_outer,max_outer],[min_outer,max_outer]] 235 236 density_inner1 = 10000000 237 inner_buffer = 100 238 min_inner1 = min_outer + inner_buffer 239 max_inner1 = max_outer - inner_buffer 240 inner1_polygon = [[min_inner1,min_inner1],[max_inner1,min_inner1], 241 [max_inner1,max_inner1],[min_inner1,max_inner1]] 242 243 244 boundary_tags = {'walls':[0,1],'bom':[2]} 245 246 interior_regions = [(inner1_polygon, density_inner1)] 247 create_mesh_from_regions(polygon_outer 248 , boundary_tags 249 , density_outer 250 , interior_regions=interior_regions 251 ,filename=file_name 252 #,verbose=True 253 ,verbose=False 254 ) 255 256 m = importMeshFromFile(file_name) 257 258 #print "file_name",file_name 259 self.failUnless(len(m.meshTriangles) <= 900, 260 'Test mesh interface failed!') 261 self.failUnless(len(m.meshTriangles) >= 200, 262 'Test mesh interface failed!') 263 264 create_mesh_from_regions(polygon_outer 265 , boundary_tags 266 , interior_regions=interior_regions 267 ,filename=file_name 268 #,verbose=True 269 ,verbose=False 270 ) 271 272 m = importMeshFromFile(file_name) 273 274 #print "len(m.meshTriangles)",len(m.meshTriangles) 275 self.failUnless(len(m.meshTriangles) <= 100, 276 'Test mesh interface failed!') 277 278 os.remove(file_name) 279 280 def test_create_mesh_from_regions5(self): 281 282 file_name = tempfile.mktemp(".tsh") 283 284 # These are the absolute values 285 density_outer = 10000000 286 min_outer = 0 287 max_outer = 1000 288 polygon_outer = [[min_outer,min_outer],[max_outer,min_outer], 289 [max_outer,max_outer],[min_outer,max_outer]] 290 291 density_inner1 = 1000 292 inner_buffer = 100 293 min_inner1 = min_outer + inner_buffer 294 max_inner1 = max_outer - inner_buffer 295 inner1_polygon = [[min_inner1,min_inner1],[max_inner1,min_inner1], 296 [max_inner1,max_inner1],[min_inner1,max_inner1]] 297 298 299 boundary_tags = {'walls':[0,1],'bom':[2]} 300 301 interior_regions = [(inner1_polygon, density_inner1)] 302 create_mesh_from_regions(polygon_outer 303 , boundary_tags 304 , density_outer 305 , interior_regions=interior_regions 306 ,filename=file_name 307 #,verbose=True 308 ,verbose=False 309 ) 310 311 m = importMeshFromFile(file_name) 312 #print "file_name",file_name 313 #print "len(m.meshTriangles",len(m.meshTriangles) 314 self.failUnless(len(m.meshTriangles) <= 2000, 315 'Test mesh interface failed!') 316 317 self.failUnless(len(m.meshTriangles) >= 900, 318 'Test mesh interface failed!') 319 320 os.remove(file_name) 321 223 322 def test_create_mesh_from_regions_interior_regions(self): 224 323 """Test that create_mesh_from_regions fails when an interior region is … … 254 353 boundary_tags, 255 354 10000000, 256 interior_regions=interior_regions )355 interior_regions=interior_regions,verbose=False) 257 356 except: 258 357 pass … … 287 386 boundary_tags, 288 387 10000000, 289 interior_regions=interior_regions )388 interior_regions=interior_regions,verbose=False) 290 389 291 390 … … 337 436 boundary_tags, 338 437 10000000, 339 poly_geo_reference=geo_ref_poly )438 poly_geo_reference=geo_ref_poly,verbose=False) 340 439 341 440
Note: See TracChangeset
for help on using the changeset viewer.