1 | #!/usr/bin/env python |
---|
2 | # |
---|
3 | import tempfile |
---|
4 | import unittest |
---|
5 | import os |
---|
6 | from anuga.pmesh.mesh import importMeshFromFile |
---|
7 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
8 | |
---|
9 | from anuga.pmesh.mesh_interface import _create_mesh_from_regions |
---|
10 | |
---|
11 | from load_mesh.loadASCII import * |
---|
12 | from anuga.utilities.polygon import is_inside_polygon |
---|
13 | from anuga.coordinate_transforms.geo_reference import Geo_reference,DEFAULT_ZONE |
---|
14 | |
---|
15 | class TestCase(unittest.TestCase): |
---|
16 | def setUp(self): |
---|
17 | pass |
---|
18 | |
---|
19 | def tearDown(self): |
---|
20 | pass |
---|
21 | |
---|
22 | def test_create_mesh_from_regions(self): |
---|
23 | x=-500 |
---|
24 | 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 | |
---|
30 | x_p = -10 |
---|
31 | y_p = -40 |
---|
32 | geo_ref_poly = Geo_reference(56, x_p, y_p) |
---|
33 | polygon = geo_ref_poly.change_points_geo_ref(polygon_absolute) |
---|
34 | |
---|
35 | boundary_tags = {'walls':[0,1],'bom':[2]} |
---|
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, 0.2)] |
---|
46 | m = create_mesh_from_regions(polygon, |
---|
47 | boundary_tags, |
---|
48 | 10000000, |
---|
49 | interior_regions=interior_regions, |
---|
50 | poly_geo_reference=geo_ref_poly, |
---|
51 | mesh_geo_reference=mesh_geo) |
---|
52 | |
---|
53 | # Test the mesh instance |
---|
54 | self.failUnless(len(m.regions)==3, |
---|
55 | 'FAILED!') |
---|
56 | segs = m.getUserSegments() |
---|
57 | self.failUnless(len(segs)==12, |
---|
58 | 'FAILED!') |
---|
59 | self.failUnless(len(m.userVertices)==12, |
---|
60 | 'FAILED!') |
---|
61 | self.failUnless(segs[0].tag=='walls', |
---|
62 | 'FAILED!') |
---|
63 | self.failUnless(segs[1].tag=='walls', |
---|
64 | 'FAILED!') |
---|
65 | |
---|
66 | self.failUnless(segs[2].tag=='bom', |
---|
67 | 'FAILED!') |
---|
68 | self.failUnless(segs[3].tag=='', |
---|
69 | 'FAILED!') |
---|
70 | |
---|
71 | # Assuming the order of the region points is known. |
---|
72 | # (This isn't true, if you consider create_mesh_from_regions |
---|
73 | # a black box) |
---|
74 | poly_point = m.getRegions()[0] |
---|
75 | |
---|
76 | #print "poly_point", poly_point |
---|
77 | #print "polygon_absolute",polygon_absolute |
---|
78 | |
---|
79 | # poly_point values are relative to the mesh geo-ref |
---|
80 | # make them absolute |
---|
81 | self.failUnless(is_inside_polygon([poly_point.x+x,poly_point.y+y], |
---|
82 | polygon_absolute, closed = False), |
---|
83 | 'FAILED!') |
---|
84 | |
---|
85 | # Assuming the order of the region points is known. |
---|
86 | # (This isn't true, if you consider create_mesh_from_regions |
---|
87 | # a black box) |
---|
88 | poly_point = m.getRegions()[1] |
---|
89 | |
---|
90 | #print "poly_point", poly_point |
---|
91 | #print "polygon_absolute",polygon_absolute |
---|
92 | |
---|
93 | # poly_point values are relative to the mesh geo-ref |
---|
94 | # make them absolute |
---|
95 | self.failUnless(is_inside_polygon([poly_point.x+x,poly_point.y+y], |
---|
96 | inner1_polygon_absolute, |
---|
97 | closed = False), |
---|
98 | 'FAILED!') |
---|
99 | |
---|
100 | # Assuming the order of the region points is known. |
---|
101 | # (This isn't true, if you consider create_mesh_from_regions |
---|
102 | # a black box) |
---|
103 | poly_point = m.getRegions()[2] |
---|
104 | |
---|
105 | #print "poly_point", poly_point |
---|
106 | #print "polygon_absolute",polygon_absolute |
---|
107 | |
---|
108 | # poly_point values are relative to the mesh geo-ref |
---|
109 | # make them absolute |
---|
110 | self.failUnless(is_inside_polygon([poly_point.x+x,poly_point.y+y], |
---|
111 | inner2_polygon_absolute, |
---|
112 | closed = False), |
---|
113 | 'FAILED!') |
---|
114 | |
---|
115 | |
---|
116 | def test_create_mesh_from_regions_with_caching(self): |
---|
117 | x=-500 |
---|
118 | y=-1000 |
---|
119 | mesh_geo = geo_reference=Geo_reference(56,x,y) |
---|
120 | |
---|
121 | # These are the absolute values |
---|
122 | polygon_absolute = [[0,0],[100,0],[100,100],[0,100]] |
---|
123 | |
---|
124 | x_p = -10 |
---|
125 | y_p = -40 |
---|
126 | geo_ref_poly = Geo_reference(56, x_p, y_p) |
---|
127 | polygon = geo_ref_poly.change_points_geo_ref(polygon_absolute) |
---|
128 | |
---|
129 | boundary_tags = {'walls':[0,1],'bom':[2]} |
---|
130 | |
---|
131 | inner1_polygon_absolute = [[10,10],[20,10],[20,20],[10,20]] |
---|
132 | inner1_polygon = geo_ref_poly. \ |
---|
133 | change_points_geo_ref(inner1_polygon_absolute) |
---|
134 | |
---|
135 | inner2_polygon_absolute = [[30,30],[40,30],[40,40],[30,40]] |
---|
136 | inner2_polygon = geo_ref_poly. \ |
---|
137 | change_points_geo_ref(inner2_polygon_absolute) |
---|
138 | |
---|
139 | interior_regions = [(inner1_polygon, 5),(inner2_polygon, 0.2)] |
---|
140 | |
---|
141 | interior_holes = None |
---|
142 | |
---|
143 | # Clear cache first |
---|
144 | from anuga.caching import cache |
---|
145 | cache(_create_mesh_from_regions, |
---|
146 | (polygon, boundary_tags), |
---|
147 | {'minimum_triangle_angle': 28.0, |
---|
148 | 'maximum_triangle_area': 10000000, |
---|
149 | 'interior_regions': interior_regions, |
---|
150 | 'interior_holes': interior_holes, |
---|
151 | 'poly_geo_reference': geo_ref_poly, |
---|
152 | 'mesh_geo_reference': mesh_geo, |
---|
153 | 'verbose': False}, |
---|
154 | verbose=False, |
---|
155 | clear=1) |
---|
156 | |
---|
157 | |
---|
158 | m = create_mesh_from_regions(polygon, |
---|
159 | boundary_tags, |
---|
160 | maximum_triangle_area=10000000, |
---|
161 | interior_regions=interior_regions, |
---|
162 | poly_geo_reference=geo_ref_poly, |
---|
163 | mesh_geo_reference=mesh_geo, |
---|
164 | verbose=False, |
---|
165 | use_cache=True) |
---|
166 | |
---|
167 | |
---|
168 | # Test the mesh instance |
---|
169 | self.failUnless(len(m.regions)==3, |
---|
170 | 'FAILED!') |
---|
171 | segs = m.getUserSegments() |
---|
172 | self.failUnless(len(segs)==12, |
---|
173 | 'FAILED!') |
---|
174 | self.failUnless(len(m.userVertices)==12, |
---|
175 | 'FAILED!') |
---|
176 | self.failUnless(segs[0].tag=='walls', |
---|
177 | 'FAILED!') |
---|
178 | self.failUnless(segs[1].tag=='walls', |
---|
179 | 'FAILED!') |
---|
180 | |
---|
181 | self.failUnless(segs[2].tag=='bom', |
---|
182 | 'FAILED!') |
---|
183 | self.failUnless(segs[3].tag=='', |
---|
184 | 'FAILED!') |
---|
185 | |
---|
186 | # Assuming the order of the region points is known. |
---|
187 | # (This isn't true, if you consider create_mesh_from_regions |
---|
188 | # a black box) |
---|
189 | poly_point = m.getRegions()[0] |
---|
190 | |
---|
191 | #print "poly_point", poly_point |
---|
192 | #print "polygon_absolute",polygon_absolute |
---|
193 | |
---|
194 | # poly_point values are relative to the mesh geo-ref |
---|
195 | # make them absolute |
---|
196 | self.failUnless(is_inside_polygon([poly_point.x+x,poly_point.y+y], |
---|
197 | polygon_absolute, closed = False), |
---|
198 | 'FAILED!') |
---|
199 | |
---|
200 | # Assuming the order of the region points is known. |
---|
201 | # (This isn't true, if you consider create_mesh_from_regions |
---|
202 | # a black box) |
---|
203 | poly_point = m.getRegions()[1] |
---|
204 | |
---|
205 | #print "poly_point", poly_point |
---|
206 | #print "polygon_absolute",polygon_absolute |
---|
207 | |
---|
208 | # poly_point values are relative to the mesh geo-ref |
---|
209 | # make them absolute |
---|
210 | self.failUnless(is_inside_polygon([poly_point.x+x,poly_point.y+y], |
---|
211 | inner1_polygon_absolute, |
---|
212 | closed = False), |
---|
213 | 'FAILED!') |
---|
214 | |
---|
215 | # Assuming the order of the region points is known. |
---|
216 | # (This isn't true, if you consider create_mesh_from_regions |
---|
217 | # a black box) |
---|
218 | poly_point = m.getRegions()[2] |
---|
219 | |
---|
220 | #print "poly_point", poly_point |
---|
221 | #print "polygon_absolute",polygon_absolute |
---|
222 | |
---|
223 | # poly_point values are relative to the mesh geo-ref |
---|
224 | # make them absolute |
---|
225 | self.failUnless(is_inside_polygon([poly_point.x+x,poly_point.y+y], |
---|
226 | inner2_polygon_absolute, |
---|
227 | closed = False), |
---|
228 | 'FAILED!') |
---|
229 | |
---|
230 | |
---|
231 | # Now create m using cached values |
---|
232 | m_cache = create_mesh_from_regions(polygon, |
---|
233 | boundary_tags, |
---|
234 | 10000000, |
---|
235 | interior_regions=interior_regions, |
---|
236 | poly_geo_reference=geo_ref_poly, |
---|
237 | mesh_geo_reference=mesh_geo, |
---|
238 | verbose=False, |
---|
239 | use_cache=True) |
---|
240 | |
---|
241 | |
---|
242 | |
---|
243 | |
---|
244 | def test_create_mesh_from_regions2(self): |
---|
245 | |
---|
246 | # These are the absolute values |
---|
247 | min_x = -10 |
---|
248 | min_y = -88 |
---|
249 | polygon_absolute = [[min_x,min_y],[1000,100],[1000,1000],[100,1000]] |
---|
250 | |
---|
251 | x_p = -10 |
---|
252 | y_p = -40 |
---|
253 | zone = 808 |
---|
254 | geo_ref_poly = Geo_reference(zone, x_p, y_p) |
---|
255 | polygon = geo_ref_poly.change_points_geo_ref(polygon_absolute) |
---|
256 | |
---|
257 | boundary_tags = {'walls':[0,1],'bom':[2]} |
---|
258 | |
---|
259 | inner1_polygon_absolute = [[10,10],[20,10],[20,20],[10,20]] |
---|
260 | inner1_polygon = geo_ref_poly. \ |
---|
261 | change_points_geo_ref(inner1_polygon_absolute) |
---|
262 | |
---|
263 | inner2_polygon_absolute = [[30,30],[40,30],[40,40],[30,40]] |
---|
264 | inner2_polygon = geo_ref_poly. \ |
---|
265 | change_points_geo_ref(inner2_polygon_absolute) |
---|
266 | |
---|
267 | interior_regions = [(inner1_polygon, 5),(inner2_polygon, 0.2)] |
---|
268 | m = create_mesh_from_regions(polygon, |
---|
269 | boundary_tags, |
---|
270 | 10000000, |
---|
271 | interior_regions=interior_regions, |
---|
272 | poly_geo_reference=geo_ref_poly) |
---|
273 | |
---|
274 | |
---|
275 | # Test the mesh instance |
---|
276 | self.failUnless(len(m.regions)==3, |
---|
277 | 'FAILED!') |
---|
278 | segs = m.getUserSegments() |
---|
279 | self.failUnless(len(segs)==12, |
---|
280 | 'FAILED!') |
---|
281 | self.failUnless(len(m.userVertices)==12, |
---|
282 | 'FAILED!') |
---|
283 | self.failUnless(segs[0].tag=='walls', |
---|
284 | 'FAILED!') |
---|
285 | self.failUnless(segs[1].tag=='walls', |
---|
286 | 'FAILED!') |
---|
287 | |
---|
288 | self.failUnless(segs[2].tag=='bom', |
---|
289 | 'FAILED!') |
---|
290 | self.failUnless(segs[3].tag=='', |
---|
291 | 'FAILED!') |
---|
292 | |
---|
293 | self.failUnless(m.geo_reference.get_zone()==zone, |
---|
294 | 'FAILED!') |
---|
295 | self.failUnless(m.geo_reference.get_xllcorner()==min_x, |
---|
296 | 'FAILED!') |
---|
297 | self.failUnless(m.geo_reference.get_yllcorner()==min_y, |
---|
298 | 'FAILED!') |
---|
299 | |
---|
300 | |
---|
301 | def test_create_mesh_from_regions3(self): |
---|
302 | |
---|
303 | # These are the absolute values |
---|
304 | min_x = -10 |
---|
305 | min_y = -88 |
---|
306 | polygon = [[min_x,min_y],[1000,100],[1000,1000],[100,1000]] |
---|
307 | |
---|
308 | |
---|
309 | x_p = -10 |
---|
310 | y_p = -40 |
---|
311 | geo_ref_poly = Geo_reference(56, x_p, y_p) |
---|
312 | |
---|
313 | boundary_tags = {'walls':[0,1],'bom':[2]} |
---|
314 | |
---|
315 | inner1_polygon_absolute = [[10,10],[20,10],[20,20],[10,20]] |
---|
316 | inner1_polygon = geo_ref_poly. \ |
---|
317 | change_points_geo_ref(inner1_polygon_absolute) |
---|
318 | |
---|
319 | inner2_polygon_absolute = [[30,30],[40,30],[40,40],[30,40]] |
---|
320 | inner2_polygon = geo_ref_poly. \ |
---|
321 | change_points_geo_ref(inner2_polygon_absolute) |
---|
322 | |
---|
323 | interior_regions = [(inner1_polygon, 5),(inner2_polygon, 0.2)] |
---|
324 | m = create_mesh_from_regions(polygon, |
---|
325 | boundary_tags, |
---|
326 | 10000000, |
---|
327 | interior_regions=interior_regions) |
---|
328 | |
---|
329 | |
---|
330 | # Test the mesh instance |
---|
331 | self.failUnless(len(m.regions)==3, |
---|
332 | 'FAILED!') |
---|
333 | segs = m.getUserSegments() |
---|
334 | self.failUnless(len(segs)==12, |
---|
335 | 'FAILED!') |
---|
336 | self.failUnless(len(m.userVertices)==12, |
---|
337 | 'FAILED!') |
---|
338 | self.failUnless(segs[0].tag=='walls', |
---|
339 | 'FAILED!') |
---|
340 | self.failUnless(segs[1].tag=='walls', |
---|
341 | 'FAILED!') |
---|
342 | |
---|
343 | self.failUnless(segs[2].tag=='bom', |
---|
344 | 'FAILED!') |
---|
345 | self.failUnless(segs[3].tag=='', |
---|
346 | 'FAILED!') |
---|
347 | |
---|
348 | self.failUnless(m.geo_reference.get_zone()==DEFAULT_ZONE, |
---|
349 | 'FAILED!') |
---|
350 | self.failUnless(m.geo_reference.get_xllcorner()==min_x, |
---|
351 | 'FAILED!') |
---|
352 | self.failUnless(m.geo_reference.get_yllcorner()==min_y, |
---|
353 | 'FAILED!') |
---|
354 | |
---|
355 | def test_create_mesh_from_regions4(self): |
---|
356 | |
---|
357 | file_name = tempfile.mktemp(".tsh") |
---|
358 | |
---|
359 | # These are the absolute values |
---|
360 | density_outer = 1000 |
---|
361 | min_outer = 0 |
---|
362 | max_outer = 1000 |
---|
363 | polygon_outer = [[min_outer,min_outer],[max_outer,min_outer], |
---|
364 | [max_outer,max_outer],[min_outer,max_outer]] |
---|
365 | |
---|
366 | density_inner1 = 10000000 |
---|
367 | inner_buffer = 100 |
---|
368 | min_inner1 = min_outer + inner_buffer |
---|
369 | max_inner1 = max_outer - inner_buffer |
---|
370 | inner1_polygon = [[min_inner1,min_inner1],[max_inner1,min_inner1], |
---|
371 | [max_inner1,max_inner1],[min_inner1,max_inner1]] |
---|
372 | |
---|
373 | |
---|
374 | boundary_tags = {'walls':[0,1],'bom':[2]} |
---|
375 | |
---|
376 | interior_regions = [(inner1_polygon, density_inner1)] |
---|
377 | create_mesh_from_regions(polygon_outer |
---|
378 | , boundary_tags |
---|
379 | , density_outer |
---|
380 | , interior_regions=interior_regions |
---|
381 | ,filename=file_name |
---|
382 | #,verbose=True |
---|
383 | ,verbose=False |
---|
384 | ) |
---|
385 | |
---|
386 | m = importMeshFromFile(file_name) |
---|
387 | |
---|
388 | #print "file_name",file_name |
---|
389 | self.failUnless(len(m.meshTriangles) <= 900, |
---|
390 | 'Test mesh interface failed!') |
---|
391 | self.failUnless(len(m.meshTriangles) >= 200, |
---|
392 | 'Test mesh interface failed!') |
---|
393 | |
---|
394 | create_mesh_from_regions(polygon_outer |
---|
395 | , boundary_tags |
---|
396 | , interior_regions=interior_regions |
---|
397 | ,filename=file_name |
---|
398 | #,verbose=True |
---|
399 | ,verbose=False |
---|
400 | ) |
---|
401 | |
---|
402 | m = importMeshFromFile(file_name) |
---|
403 | |
---|
404 | #print "len(m.meshTriangles)",len(m.meshTriangles) |
---|
405 | self.failUnless(len(m.meshTriangles) <= 100, |
---|
406 | 'Test mesh interface failed!') |
---|
407 | |
---|
408 | os.remove(file_name) |
---|
409 | |
---|
410 | def test_create_mesh_from_regions5(self): |
---|
411 | |
---|
412 | file_name = tempfile.mktemp(".tsh") |
---|
413 | |
---|
414 | # These are the absolute values |
---|
415 | density_outer = 10000000 |
---|
416 | min_outer = 0 |
---|
417 | max_outer = 1000 |
---|
418 | polygon_outer = [[min_outer,min_outer],[max_outer,min_outer], |
---|
419 | [max_outer,max_outer],[min_outer,max_outer]] |
---|
420 | |
---|
421 | density_inner1 = 1000 |
---|
422 | inner_buffer = 100 |
---|
423 | min_inner1 = min_outer + inner_buffer |
---|
424 | max_inner1 = max_outer - inner_buffer |
---|
425 | inner1_polygon = [[min_inner1,min_inner1],[max_inner1,min_inner1], |
---|
426 | [max_inner1,max_inner1],[min_inner1,max_inner1]] |
---|
427 | |
---|
428 | |
---|
429 | boundary_tags = {'walls':[0,1],'bom':[2]} |
---|
430 | |
---|
431 | interior_regions = [(inner1_polygon, density_inner1)] |
---|
432 | create_mesh_from_regions(polygon_outer |
---|
433 | , boundary_tags |
---|
434 | , density_outer |
---|
435 | , interior_regions=interior_regions |
---|
436 | ,filename=file_name |
---|
437 | #,verbose=True |
---|
438 | ,verbose=False |
---|
439 | ) |
---|
440 | |
---|
441 | m = importMeshFromFile(file_name) |
---|
442 | #print "file_name",file_name |
---|
443 | #print "len(m.meshTriangles",len(m.meshTriangles) |
---|
444 | self.failUnless(len(m.meshTriangles) <= 2000, |
---|
445 | 'Test mesh interface failed!') |
---|
446 | |
---|
447 | self.failUnless(len(m.meshTriangles) >= 900, |
---|
448 | 'Test mesh interface failed!') |
---|
449 | |
---|
450 | os.remove(file_name) |
---|
451 | |
---|
452 | def test_create_mesh_from_regions6(self): |
---|
453 | |
---|
454 | file_name = tempfile.mktemp(".tsh") |
---|
455 | |
---|
456 | # These are the absolute values |
---|
457 | density_outer = 1000 |
---|
458 | min_outer = 0 |
---|
459 | max_outer = 1000 |
---|
460 | polygon_outer = [[min_outer,min_outer],[max_outer,min_outer], |
---|
461 | [max_outer,max_outer],[min_outer,max_outer]] |
---|
462 | |
---|
463 | delta = 10 |
---|
464 | density_inner1 = 1000 |
---|
465 | min_inner1 = min_outer + delta |
---|
466 | max_inner1 = max_outer - delta |
---|
467 | inner1_polygon = [[min_inner1,min_inner1],[max_inner1,min_inner1], |
---|
468 | [max_inner1,max_inner1],[min_inner1,max_inner1]] |
---|
469 | |
---|
470 | |
---|
471 | density_inner2 = 10000000 |
---|
472 | min_inner2 = min_outer + 2*delta |
---|
473 | max_inner2 = max_outer - 2*delta |
---|
474 | inner2_polygon = [[min_inner2,min_inner2],[max_inner2,min_inner2], |
---|
475 | [max_inner2,max_inner2],[min_inner2,max_inner2]] |
---|
476 | |
---|
477 | boundary_tags = {'walls':[0,1],'bom':[2]} |
---|
478 | |
---|
479 | interior_regions = [(inner1_polygon, density_inner1), |
---|
480 | (inner2_polygon, density_inner2)] |
---|
481 | create_mesh_from_regions(polygon_outer, |
---|
482 | boundary_tags, |
---|
483 | density_outer, |
---|
484 | interior_regions=interior_regions, |
---|
485 | filename=file_name, |
---|
486 | verbose=False) |
---|
487 | |
---|
488 | m = importMeshFromFile(file_name) |
---|
489 | #print "file_name",file_name |
---|
490 | #print "len(m.meshTriangles",len(m.meshTriangles) |
---|
491 | self.failUnless(len(m.meshTriangles) <= 2000, |
---|
492 | 'Test mesh interface failed!') |
---|
493 | |
---|
494 | self.failUnless(len(m.meshTriangles) >= 900, |
---|
495 | 'Test mesh interface failed!') |
---|
496 | |
---|
497 | os.remove(file_name) |
---|
498 | |
---|
499 | def test_create_mesh_from_regions7(self): |
---|
500 | |
---|
501 | file_name = tempfile.mktemp(".tsh") |
---|
502 | |
---|
503 | # These are the absolute values |
---|
504 | density_outer = 1001 |
---|
505 | min_outer = 0 |
---|
506 | max_outer = 1000 |
---|
507 | polygon_outer = [[min_outer,min_outer],[max_outer,min_outer], |
---|
508 | [max_outer,max_outer],[min_outer,max_outer]] |
---|
509 | |
---|
510 | delta = 10 |
---|
511 | density_inner1 = 100000000 |
---|
512 | min_inner1 = min_outer + delta |
---|
513 | max_inner1 = max_outer - delta |
---|
514 | inner1_polygon = [[min_inner1,min_inner1],[max_inner1,min_inner1], |
---|
515 | [max_inner1,max_inner1],[min_inner1,max_inner1]] |
---|
516 | |
---|
517 | |
---|
518 | density_inner2 = 1000 |
---|
519 | min_inner2 = min_outer + 2*delta |
---|
520 | max_inner2 = max_outer - 2*delta |
---|
521 | inner2_polygon = [[min_inner2,min_inner2],[max_inner2,min_inner2], |
---|
522 | [max_inner2,max_inner2],[min_inner2,max_inner2]] |
---|
523 | |
---|
524 | boundary_tags = {'walls':[0,1],'bom':[2]} |
---|
525 | |
---|
526 | #Note the list order is important |
---|
527 | # The last region added will be the region triangle uses, |
---|
528 | # if two regions points are in the same bounded area. |
---|
529 | interior_regions = [(inner2_polygon, density_inner2),(inner1_polygon, density_inner1)] |
---|
530 | create_mesh_from_regions(polygon_outer, |
---|
531 | boundary_tags, |
---|
532 | density_outer, |
---|
533 | interior_regions=interior_regions, |
---|
534 | filename=file_name, |
---|
535 | verbose=False) |
---|
536 | |
---|
537 | m = importMeshFromFile(file_name) |
---|
538 | #print "file_name",file_name |
---|
539 | #print "len(m.meshTriangles",len(m.meshTriangles) |
---|
540 | self.failUnless(len(m.meshTriangles) <= 3000, |
---|
541 | 'Test mesh interface failed!') |
---|
542 | |
---|
543 | self.failUnless(len(m.meshTriangles) >= 2000, |
---|
544 | 'Test mesh interface failed!') |
---|
545 | |
---|
546 | os.remove(file_name) |
---|
547 | |
---|
548 | |
---|
549 | def test_create_mesh_from_regions_interior_regions(self): |
---|
550 | """Test that create_mesh_from_regions fails when an interior region is |
---|
551 | outside bounding polygon. """ |
---|
552 | |
---|
553 | |
---|
554 | # These are the absolute values |
---|
555 | min_x = 10 |
---|
556 | min_y = 88 |
---|
557 | polygon = [[min_x,min_y],[1000,100],[1000,1000],[100,1000]] |
---|
558 | |
---|
559 | boundary_tags = {'walls':[0,1],'bom':[2]} |
---|
560 | # boundary_tags = {'walls':[0,1]} |
---|
561 | # This one is inside bounding polygon - should pass |
---|
562 | inner_polygon = [[800,400],[900,500],[800,600]] |
---|
563 | |
---|
564 | interior_regions = [(inner_polygon, 5)] |
---|
565 | m = create_mesh_from_regions(polygon, |
---|
566 | boundary_tags, |
---|
567 | 10000000, |
---|
568 | interior_regions=interior_regions) |
---|
569 | |
---|
570 | |
---|
571 | # This one sticks outside bounding polygon - should fail |
---|
572 | inner_polygon = [[800,400],[900,500],[800,600], [200, 995]] |
---|
573 | inner_polygon1 = [[800,400],[1100,500],[800,600]] |
---|
574 | interior_regions = [[inner_polygon, 50], [inner_polygon1, 50]] |
---|
575 | |
---|
576 | |
---|
577 | |
---|
578 | try: |
---|
579 | m = create_mesh_from_regions(polygon, |
---|
580 | boundary_tags, |
---|
581 | 10000000, |
---|
582 | interior_regions=interior_regions, |
---|
583 | verbose=False) |
---|
584 | except: |
---|
585 | pass |
---|
586 | else: |
---|
587 | msg = 'Interior polygon sticking outside bounding polygon should ' |
---|
588 | msg += 'cause an Exception to be raised' |
---|
589 | raise msg |
---|
590 | |
---|
591 | def test_create_mesh_from_regions_interior_regions1(self): |
---|
592 | """Test that create_mesh_from_regions fails when an interior region is |
---|
593 | outside bounding polygon. """ |
---|
594 | |
---|
595 | |
---|
596 | # These are the values |
---|
597 | |
---|
598 | d0 = [310000, 7690000] |
---|
599 | d1 = [280000, 7690000] |
---|
600 | d2 = [270000, 7645000] |
---|
601 | d3 = [240000, 7625000] |
---|
602 | d4 = [270000, 7580000] |
---|
603 | d5 = [300000, 7590000] |
---|
604 | d6 = [340000, 7610000] |
---|
605 | |
---|
606 | poly_all = [d0, d1, d2, d3, d4, d5, d6] |
---|
607 | |
---|
608 | i0 = [304000, 7607000] |
---|
609 | i1 = [302000, 7605000] |
---|
610 | i2 = [304000, 7603000] |
---|
611 | i3 = [307000, 7602000] |
---|
612 | i4 = [309000, 7603000] |
---|
613 | # i4 = [310000, 7580000] |
---|
614 | i5 = [307000, 7606000] |
---|
615 | |
---|
616 | poly_onslow = [i0, i1, i2, i3, i4, i5] |
---|
617 | |
---|
618 | #Thevenard Island |
---|
619 | j0 = [294000, 7629000] |
---|
620 | j1 = [285000, 7625000] |
---|
621 | j2 = [294000, 7621000] |
---|
622 | j3 = [299000, 7625000] |
---|
623 | |
---|
624 | poly_thevenard = [j0, j1, j2, j3] |
---|
625 | |
---|
626 | #med res around onslow |
---|
627 | l0 = [300000, 7610000] |
---|
628 | l1 = [285000, 7600000] |
---|
629 | l2 = [300000, 7597500] |
---|
630 | l3 = [310000, 7770000] #this one is outside |
---|
631 | # l3 = [310000, 7630000] #this one is NOT outside |
---|
632 | l4 = [315000, 7610000] |
---|
633 | poly_coast = [l0, l1, l2, l3, l4] |
---|
634 | |
---|
635 | #general coast and local area to onslow region |
---|
636 | m0 = [270000, 7581000] |
---|
637 | m1 = [300000, 7591000] |
---|
638 | m2 = [339000, 7610000] |
---|
639 | m3 = [330000, 7630000] |
---|
640 | m4 = [290000, 7640000] |
---|
641 | m5 = [260000, 7600000] |
---|
642 | |
---|
643 | poly_region = [m0, m1, m2, m3, m4, m5] |
---|
644 | |
---|
645 | # This one sticks outside bounding polygon - should fail |
---|
646 | |
---|
647 | interior_regions = [[poly_onslow, 50000], [poly_region, 50000], [poly_coast,100000], [poly_thevenard, 100000]] |
---|
648 | |
---|
649 | boundary_tags = {'walls':[0,1],'bom':[2]} |
---|
650 | |
---|
651 | try: |
---|
652 | m = create_mesh_from_regions(poly_all, |
---|
653 | boundary_tags, |
---|
654 | 10000000, |
---|
655 | interior_regions=interior_regions, |
---|
656 | verbose=False) |
---|
657 | except: |
---|
658 | pass |
---|
659 | else: |
---|
660 | msg = 'Interior polygon sticking outside bounding polygon should ' |
---|
661 | msg += 'cause an Exception to be raised' |
---|
662 | raise msg |
---|
663 | |
---|
664 | |
---|
665 | |
---|
666 | def FIXME_test_create_mesh_with_multiply_tagged_segments(self): |
---|
667 | """Test that create_mesh_from_regions fails when |
---|
668 | segments are listed repeatedly in boundary_tags. |
---|
669 | """ |
---|
670 | |
---|
671 | |
---|
672 | |
---|
673 | |
---|
674 | # These are the absolute values |
---|
675 | min_x = 10 |
---|
676 | min_y = 88 |
---|
677 | polygon = [[min_x,min_y],[1000,100],[1000,1000],[100,1000]] |
---|
678 | |
---|
679 | |
---|
680 | boundary_tags = {'walls':[0,1],'bom':[1,2]} |
---|
681 | |
---|
682 | # This one is inside bounding polygon - should pass |
---|
683 | inner_polygon = [[800,400],[900,500],[800,600]] |
---|
684 | |
---|
685 | interior_regions = [(inner_polygon, 5)] |
---|
686 | m = create_mesh_from_regions(polygon, |
---|
687 | boundary_tags, |
---|
688 | 10000000, |
---|
689 | interior_regions=interior_regions,verbose=False) |
---|
690 | |
---|
691 | |
---|
692 | # This one sticks outside bounding polygon - should fail |
---|
693 | inner_polygon = [[800,400],[900,500],[800,600]] |
---|
694 | interior_regions = [(inner_polygon, 5)] |
---|
695 | |
---|
696 | |
---|
697 | |
---|
698 | try: |
---|
699 | m = create_mesh_from_regions(polygon, |
---|
700 | boundary_tags, |
---|
701 | 10000000, |
---|
702 | interior_regions=interior_regions) |
---|
703 | except: |
---|
704 | pass |
---|
705 | else: |
---|
706 | msg = 'Tags are listed repeatedly, but create mesh from regions ' |
---|
707 | msg += 'does not cause an Exception to be raised' |
---|
708 | raise msg |
---|
709 | |
---|
710 | |
---|
711 | |
---|
712 | |
---|
713 | def test_create_mesh_from_regions_with_duplicate_verts(self): |
---|
714 | |
---|
715 | # These are the absolute values |
---|
716 | |
---|
717 | polygon_absolute = [[0.0,0.0], |
---|
718 | [0,4.0], |
---|
719 | [4.0,4.0], |
---|
720 | [4.0,0.0], |
---|
721 | [4.0,0.0]] |
---|
722 | |
---|
723 | x_p = -10 |
---|
724 | y_p = -40 |
---|
725 | zone = 808 |
---|
726 | geo_ref_poly = Geo_reference(zone, x_p, y_p) |
---|
727 | polygon = geo_ref_poly.change_points_geo_ref(polygon_absolute) |
---|
728 | |
---|
729 | boundary_tags = {'50':[0], |
---|
730 | '40':[1], |
---|
731 | '30':[2], |
---|
732 | 'no where seg':[3], |
---|
733 | '20':[4] |
---|
734 | } |
---|
735 | |
---|
736 | m = create_mesh_from_regions(polygon, |
---|
737 | boundary_tags, |
---|
738 | 10000000, |
---|
739 | poly_geo_reference=geo_ref_poly,verbose=False) |
---|
740 | |
---|
741 | |
---|
742 | fileName = "badmesh.tsh" |
---|
743 | #m.export_mesh_file(fileName) |
---|
744 | |
---|
745 | #------------------------------------------------------------- |
---|
746 | if __name__ == "__main__": |
---|
747 | suite = unittest.makeSuite(TestCase,'test') |
---|
748 | # suite = unittest.makeSuite(TestCase,'test_create_mesh_from_regions_interior_regions') |
---|
749 | runner = unittest.TextTestRunner() #verbosity=2) |
---|
750 | runner.run(suite) |
---|
751 | |
---|