Changeset 3715
- Timestamp:
- Oct 9, 2006, 4:46:39 PM (18 years ago)
- Location:
- anuga_core/source/anuga
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/caching/caching.py
r3514 r3715 308 308 # FIXME: os.remove doesn't work under windows 309 309 os.system('del '+fn) 310 if verbose :310 if verbose is True: 311 311 print 'MESSAGE (caching): File %s deleted' %fn 312 312 ##else: -
anuga_core/source/anuga/caching/test_caching.py
r2263 r3715 133 133 """Test that 'clear' works 134 134 """ 135 135 136 N = 5000 #Make N fairly small here 136 137 … … 145 146 146 147 147 cache(f, (a,b,c,N), {'x':x, 'y':y}, clear = 1)148 cache(f, (a,b,c,N), {'x':x, 'y':y}, clear = 1) 148 149 149 150 … … 151 152 152 153 153 T4 = cache(f,(a,b,c,N), {'x':x, 'y':y}, test=1) 154 T4 = cache(f, (a,b,c,N), {'x':x, 'y':y}, test=1) 155 #print 'T4', T4 154 156 assert T4 is None, "Option 'test' when cache absent failed" 155 157 -
anuga_core/source/anuga/pmesh/mesh_interface.py
r3689 r3715 62 62 unintended resolutions. 63 63 64 """ 65 66 # Build arguments and keyword arguments for use with caching or apply. 67 args = (bounding_polygon, 68 boundary_tags) 69 70 kwargs = {'maximum_triangle_area': maximum_triangle_area, 71 'filename': filename, 72 'interior_regions': interior_regions, 73 'poly_geo_reference': poly_geo_reference, 74 'mesh_geo_reference': mesh_geo_reference, 75 'minimum_triangle_angle': minimum_triangle_angle, 76 'verbose': verbose} # FIXME (Ole): Should be bypassed one day 77 78 79 #print 'kwargs', kwargs 80 81 # Call underlying engine with or without caching 82 if use_cache is True: 83 try: 84 from caching import cache 85 except: 86 msg = 'Caching was requested, but caching module'+\ 87 'could not be imported' 88 raise msg 89 90 91 res = cache(_create_mesh_from_regions, 92 args, kwargs, 93 verbose=verbose, 94 compression=False) 95 else: 96 res = apply(_create_mesh_from_regions, 97 args, kwargs) 98 99 return res 100 101 102 103 def _create_mesh_from_regions(bounding_polygon, 104 boundary_tags, 105 maximum_triangle_area=None, 106 filename=None, 107 interior_regions=None, 108 poly_geo_reference=None, 109 mesh_geo_reference=None, 110 minimum_triangle_angle=28.0, 111 verbose=True): 112 """_create_mesh_from_regions - internal function. 113 114 See create_mesh_from_regions for documentation. 64 115 """ 65 116 #FIXME (OLE-DSG) … … 164 215 m.export_mesh_file(filename) 165 216 166 -
anuga_core/source/anuga/pmesh/test_mesh_interface.py
r3514 r3715 5 5 import os 6 6 from anuga.pmesh.mesh import importMeshFromFile 7 from mesh_interface import * 7 from anuga.pmesh.mesh_interface import create_mesh_from_regions 8 from anuga.pmesh.mesh_interface import _create_mesh_from_regions 8 9 from load_mesh.loadASCII import * 9 10 from anuga.utilities.polygon import is_inside_polygon … … 21 22 y=-1000 22 23 mesh_geo = geo_reference=Geo_reference(56,x,y) 23 24 24 25 # These are the absolute values 25 26 polygon_absolute = [[0,0],[100,0],[100,100],[0,100]] … … 109 110 closed = False), 110 111 'FAILED!') 112 113 114 def test_create_mesh_from_regions_with_caching(self): 115 x=-500 116 y=-1000 117 mesh_geo = geo_reference=Geo_reference(56,x,y) 118 119 # These are the absolute values 120 polygon_absolute = [[0,0],[100,0],[100,100],[0,100]] 121 122 x_p = -10 123 y_p = -40 124 geo_ref_poly = Geo_reference(56, x_p, y_p) 125 polygon = geo_ref_poly.change_points_geo_ref(polygon_absolute) 126 127 boundary_tags = {'walls':[0,1],'bom':[2]} 128 129 inner1_polygon_absolute = [[10,10],[20,10],[20,20],[10,20]] 130 inner1_polygon = geo_ref_poly. \ 131 change_points_geo_ref(inner1_polygon_absolute) 132 133 inner2_polygon_absolute = [[30,30],[40,30],[40,40],[30,40]] 134 inner2_polygon = geo_ref_poly. \ 135 change_points_geo_ref(inner2_polygon_absolute) 136 137 interior_regions = [(inner1_polygon, 5),(inner2_polygon, 0.2)] 138 139 140 141 # Clear cache first 142 from anuga.caching import cache 143 cache(_create_mesh_from_regions, 144 (polygon, boundary_tags), 145 {'minimum_triangle_angle': 28.0, 146 'maximum_triangle_area': 10000000, 147 'filename': None, 148 'interior_regions': interior_regions, 149 'poly_geo_reference': geo_ref_poly, 150 'mesh_geo_reference': mesh_geo, 151 'verbose': False}, 152 verbose=False, 153 clear=1) 154 155 156 m = create_mesh_from_regions(polygon, 157 boundary_tags, 158 maximum_triangle_area=10000000, 159 interior_regions=interior_regions, 160 poly_geo_reference=geo_ref_poly, 161 mesh_geo_reference=mesh_geo, 162 verbose=False, 163 use_cache=True) 164 165 166 # Test the mesh instance 167 self.failUnless(len(m.regions)==3, 168 'FAILED!') 169 segs = m.getUserSegments() 170 self.failUnless(len(segs)==12, 171 'FAILED!') 172 self.failUnless(len(m.userVertices)==12, 173 'FAILED!') 174 self.failUnless(segs[0].tag=='walls', 175 'FAILED!') 176 self.failUnless(segs[1].tag=='walls', 177 'FAILED!') 178 179 self.failUnless(segs[2].tag=='bom', 180 'FAILED!') 181 self.failUnless(segs[3].tag=='', 182 'FAILED!') 183 184 # Assuming the order of the region points is known. 185 # (This isn't true, if you consider create_mesh_from_regions 186 # a black box) 187 poly_point = m.getRegions()[0] 188 189 #print "poly_point", poly_point 190 #print "polygon_absolute",polygon_absolute 191 192 # poly_point values are relative to the mesh geo-ref 193 # make them absolute 194 self.failUnless(is_inside_polygon([poly_point.x+x,poly_point.y+y], 195 polygon_absolute, closed = False), 196 'FAILED!') 197 198 # Assuming the order of the region points is known. 199 # (This isn't true, if you consider create_mesh_from_regions 200 # a black box) 201 poly_point = m.getRegions()[1] 202 203 #print "poly_point", poly_point 204 #print "polygon_absolute",polygon_absolute 205 206 # poly_point values are relative to the mesh geo-ref 207 # make them absolute 208 self.failUnless(is_inside_polygon([poly_point.x+x,poly_point.y+y], 209 inner1_polygon_absolute, 210 closed = False), 211 'FAILED!') 212 213 # Assuming the order of the region points is known. 214 # (This isn't true, if you consider create_mesh_from_regions 215 # a black box) 216 poly_point = m.getRegions()[2] 217 218 #print "poly_point", poly_point 219 #print "polygon_absolute",polygon_absolute 220 221 # poly_point values are relative to the mesh geo-ref 222 # make them absolute 223 self.failUnless(is_inside_polygon([poly_point.x+x,poly_point.y+y], 224 inner2_polygon_absolute, 225 closed = False), 226 'FAILED!') 227 228 229 # Now create m using cached values 230 m_cache = create_mesh_from_regions(polygon, 231 boundary_tags, 232 10000000, 233 interior_regions=interior_regions, 234 poly_geo_reference=geo_ref_poly, 235 mesh_geo_reference=mesh_geo, 236 verbose=False, 237 use_cache=True) 238 111 239 112 240 … … 329 457 max_outer = 1000 330 458 polygon_outer = [[min_outer,min_outer],[max_outer,min_outer], 331 [max_outer,max_outer],[min_outer,max_outer]]459 [max_outer,max_outer],[min_outer,max_outer]] 332 460 333 461 delta = 10 … … 336 464 max_inner1 = max_outer - delta 337 465 inner1_polygon = [[min_inner1,min_inner1],[max_inner1,min_inner1], 338 [max_inner1,max_inner1],[min_inner1,max_inner1]]466 [max_inner1,max_inner1],[min_inner1,max_inner1]] 339 467 340 468 … … 343 471 max_inner2 = max_outer - 2*delta 344 472 inner2_polygon = [[min_inner2,min_inner2],[max_inner2,min_inner2], 345 [max_inner2,max_inner2],[min_inner2,max_inner2]] 346 347 boundary_tags = {'walls':[0,1],'bom':[2]} 348 349 interior_regions = [(inner1_polygon, density_inner1),(inner2_polygon, density_inner2)] 350 create_mesh_from_regions(polygon_outer 351 , boundary_tags 352 , density_outer 353 , interior_regions=interior_regions 354 ,filename=file_name 355 #,verbose=True 356 ,verbose=False 357 ) 473 [max_inner2,max_inner2],[min_inner2,max_inner2]] 474 475 boundary_tags = {'walls':[0,1],'bom':[2]} 476 477 interior_regions = [(inner1_polygon, density_inner1), 478 (inner2_polygon, density_inner2)] 479 create_mesh_from_regions(polygon_outer, 480 boundary_tags, 481 density_outer, 482 interior_regions=interior_regions, 483 filename=file_name, 484 verbose=False) 358 485 359 486 m = importMeshFromFile(file_name) … … 399 526 # if two regions points are in the same bounded area. 400 527 interior_regions = [(inner2_polygon, density_inner2),(inner1_polygon, density_inner1)] 401 create_mesh_from_regions(polygon_outer 402 , boundary_tags 403 , density_outer 404 , interior_regions=interior_regions 405 ,filename=file_name 406 #,verbose=True 407 ,verbose=False 408 ) 528 create_mesh_from_regions(polygon_outer, 529 boundary_tags, 530 density_outer, 531 interior_regions=interior_regions, 532 filename=file_name, 533 verbose=False) 409 534 410 535 m = importMeshFromFile(file_name) … … 453 578 boundary_tags, 454 579 10000000, 455 interior_regions=interior_regions,verbose=False) 580 interior_regions=interior_regions, 581 verbose=False) 456 582 except: 457 583 pass
Note: See TracChangeset
for help on using the changeset viewer.