1 | #!/usr/bin/env python |
---|
2 | # |
---|
3 | import tempfile |
---|
4 | import unittest |
---|
5 | from mesh import * |
---|
6 | from load_mesh.loadASCII import * |
---|
7 | from coordinate_transforms.geo_reference import Geo_reference |
---|
8 | |
---|
9 | class meshTestCase(unittest.TestCase): |
---|
10 | def setUp(self): |
---|
11 | pass |
---|
12 | |
---|
13 | |
---|
14 | |
---|
15 | def tearDown(self): |
---|
16 | pass |
---|
17 | |
---|
18 | def testPointDistance(self): |
---|
19 | a = Point(0.0, 0.0) |
---|
20 | b = Point(0.0, 10.0) |
---|
21 | |
---|
22 | self.failUnless( a.DistanceToPoint(b) == 10.0, |
---|
23 | 'Point DistanceToPoint is wrong!') |
---|
24 | |
---|
25 | def testVertexDistance(self): |
---|
26 | a = Vertex (0.0, 0.0) |
---|
27 | b = Vertex (0.0, 10.0) |
---|
28 | |
---|
29 | self.failUnless( a.DistanceToPoint(b) == 10.0, |
---|
30 | 'Point DistanceToPoint is wrong!') |
---|
31 | |
---|
32 | def testTriangle(self): |
---|
33 | a = Vertex (0.0, 0.0) |
---|
34 | b = Vertex (0.0, 2.0) |
---|
35 | c = Vertex (2.0,0.0) |
---|
36 | d = Vertex (0.0, 4.0) |
---|
37 | e = Vertex (2.0, 2.0) |
---|
38 | f = Vertex (4.0,0.0) |
---|
39 | |
---|
40 | t1 = Triangle(b,a,c) |
---|
41 | t2 = Triangle(b,c,e) |
---|
42 | t3 = Triangle(e,c,f) |
---|
43 | t4 = Triangle(d,b,e) |
---|
44 | t2.setNeighbors(t3,t4,t1) |
---|
45 | |
---|
46 | self.failUnless( t2.neighbors[2].vertices[0] == b, 'Triangle initialisation is wrong!') |
---|
47 | |
---|
48 | |
---|
49 | def testSegment(self): |
---|
50 | a = Vertex (0.0, 0.0) |
---|
51 | b = Vertex (0.0, 10.0) |
---|
52 | s = Segment(a,b, tag = 20) |
---|
53 | |
---|
54 | self.failUnless( s.vertices[0].DistanceToPoint(s.vertices[1]) == 10.0, |
---|
55 | 'vertices in a segment are wrong') |
---|
56 | |
---|
57 | self.failUnless( s.tag == 20.0, |
---|
58 | 'tag in a segment are wrong') |
---|
59 | |
---|
60 | def testdeleteUserVertex(self): |
---|
61 | |
---|
62 | |
---|
63 | mesh = Mesh() |
---|
64 | a = mesh.addUserVertex(0.0, 0.0) |
---|
65 | b = mesh.addUserVertex (0.0, 2.0) |
---|
66 | c = mesh.addUserVertex (2.0,0.0) |
---|
67 | |
---|
68 | s1 = mesh.addUserSegment(a,b) |
---|
69 | s2 = mesh.addUserSegment(a,c) |
---|
70 | s3 = mesh.addUserSegment(c,b) |
---|
71 | |
---|
72 | mesh.deleteMeshObject (a) |
---|
73 | self.failUnless(mesh.userSegments[0] == s3, |
---|
74 | 'Bad segment. ') |
---|
75 | self.failUnless(len(mesh.userSegments) ==1, |
---|
76 | 'Segments not deleted.') |
---|
77 | self.failUnless(len(mesh.userVertices) == 2, |
---|
78 | 'Vertex not deleted.') |
---|
79 | |
---|
80 | |
---|
81 | |
---|
82 | def testgenerateMesh(self): |
---|
83 | a = Vertex (0.0, 0.0) |
---|
84 | d = Vertex (0.0, 4.0) |
---|
85 | f = Vertex (4.0,0.0) |
---|
86 | |
---|
87 | s1 = Segment(a,d) |
---|
88 | s2 = Segment(d,f) |
---|
89 | s3 = Segment(a,f) |
---|
90 | |
---|
91 | r1 = Region(0.3, 0.3,tag = 1.3,maxArea = .6) |
---|
92 | #print r1 |
---|
93 | m = Mesh(userVertices=[a,d,f], userSegments=[s1,s2,s3], regions=[r1] ) |
---|
94 | |
---|
95 | m.generateMesh("QApz", maxArea = 2.1 ) |
---|
96 | |
---|
97 | #print m |
---|
98 | |
---|
99 | #m.plotMeshTriangle() |
---|
100 | |
---|
101 | result = 1.414214 |
---|
102 | delta = 0.00001 |
---|
103 | |
---|
104 | self.failUnless((m.meshTriangles[1].vertices[0].x < result + delta) or |
---|
105 | (m.meshTriangles[1].vertices[0].x > result - delta), |
---|
106 | 'generated mesh is wrong!') |
---|
107 | |
---|
108 | def test_regionalMaxArea(self): |
---|
109 | v0 = Vertex (0.0, 0.0) |
---|
110 | v1 = Vertex (6.0, 0.0) |
---|
111 | v2 = Vertex (6.0,6.0) |
---|
112 | v3 = Vertex (0.0,6.0) |
---|
113 | |
---|
114 | s1 = Segment(v0,v1) |
---|
115 | s2 = Segment(v1,v2) |
---|
116 | s3 = Segment(v3,v2) |
---|
117 | s4 = Segment(v3,v0) |
---|
118 | s5 = Segment(v2,v0) |
---|
119 | |
---|
120 | r1 = Region(3, 1,tag = 1.3) |
---|
121 | #print r1 |
---|
122 | m = Mesh(userVertices=[v0,v1,v2,v3], userSegments=[s1,s2,s3,s4,s5], regions=[r1] ) |
---|
123 | |
---|
124 | m.generateMesh("Apz", maxArea = 36 ) |
---|
125 | |
---|
126 | #m.plotMeshTriangle() |
---|
127 | #print "len(m.meshTriangles)",len(m.meshTriangles) |
---|
128 | |
---|
129 | self.failUnless(len(m.meshTriangles) == 2, |
---|
130 | 'test_regionalMaxArea 1:generated mesh is wrong!') |
---|
131 | |
---|
132 | ## Another test case |
---|
133 | r1 = Region(3, 1,tag = 1.3) |
---|
134 | r2 = Region(1, 3,tag = 1.3, maxArea = 8) |
---|
135 | m = Mesh(userVertices=[v0,v1,v2,v3], userSegments=[s1,s2,s3,s4,s5], |
---|
136 | regions=[r1,r2] ) |
---|
137 | m.generateMesh("Apz", maxArea = 36 ) |
---|
138 | self.failUnless(len(m.meshTriangles) == 6, |
---|
139 | 'test_regionalMaxArea 2:generated mesh is wrong!') |
---|
140 | |
---|
141 | ## Another test case |
---|
142 | r1 = Region(3, 1, tag = 1.3, maxArea = 8) |
---|
143 | r2 = Region(1, 3, tag = 1.3, maxArea = 8) |
---|
144 | m = Mesh(userVertices=[v0,v1,v2,v3], userSegments=[s1,s2,s3,s4,s5], |
---|
145 | regions=[r1,r2] ) |
---|
146 | m.generateMesh("Apz", maxArea = 36 ) |
---|
147 | #print "len(m.meshTriangles)",len(m.meshTriangles) |
---|
148 | self.failUnless(len(m.meshTriangles) == 8, |
---|
149 | 'test_regionalMaxArea 3:generated mesh is wrong!') |
---|
150 | |
---|
151 | ## Another test case |
---|
152 | r1 = Region(3, 1, tag = 1.3 ) |
---|
153 | r2 = Region(1, 3, tag = 1.3, maxArea = 8) |
---|
154 | m = Mesh(userVertices=[v0,v1,v2,v3], userSegments=[s1,s2,s3,s4,s5], |
---|
155 | regions=[r1,r2] ) |
---|
156 | m.generateMesh("Apz", maxArea = 8 ) |
---|
157 | self.failUnless(len(m.meshTriangles) == 8, |
---|
158 | 'test_regionalMaxArea 4:generated mesh is wrong!') |
---|
159 | |
---|
160 | ## Another test case |
---|
161 | r1 = Region(3, 1,tag = 1.3, maxArea = 8) |
---|
162 | r2 = Region(1, 3,tag = 1.3, maxArea = 8) |
---|
163 | m = Mesh(userVertices=[v0,v1,v2,v3], userSegments=[s1,s2,s3,s4,s5], |
---|
164 | regions=[r1,r2] ) |
---|
165 | m.generateMesh("Apz", maxArea = 36,isRegionalMaxAreas = False ) |
---|
166 | self.failUnless(len(m.meshTriangles) == 2, |
---|
167 | 'test_regionalMaxArea 5:generated mesh is wrong!') |
---|
168 | |
---|
169 | def testdeleteUserVertex(self): |
---|
170 | mesh = Mesh() |
---|
171 | a = mesh.addUserVertex(0.0, 0.0) |
---|
172 | b = mesh.addUserVertex (0.0, 2.0) |
---|
173 | c = mesh.addUserVertex (2.0,0.0) |
---|
174 | |
---|
175 | s1 = mesh.addUserSegment(a,b) |
---|
176 | s2 = mesh.addUserSegment(a,c) |
---|
177 | s3 = mesh.addUserSegment(c,b) |
---|
178 | |
---|
179 | mesh.deleteMeshObject (s2) |
---|
180 | |
---|
181 | #print ",s2 in mesh.userSegments" ,s2 in mesh.userSegments |
---|
182 | self.failUnless(not(s2 in mesh.userSegments), |
---|
183 | 'Bad segment. ') |
---|
184 | self.failUnless(len(mesh.userSegments) ==2, |
---|
185 | 'Segments not deleted.') |
---|
186 | self.failUnless(len(mesh.userVertices) == 3, |
---|
187 | 'Vertex deleted, instead of segment.') |
---|
188 | |
---|
189 | def testTriangleArea(self): |
---|
190 | a = Vertex (10.0, 10.0) |
---|
191 | b = Vertex (10.0, 20.0) |
---|
192 | c = Vertex (20.0,10.0) |
---|
193 | |
---|
194 | d = Vertex (-20.0, 0.0) |
---|
195 | e = Vertex (-20.0, -20.0) |
---|
196 | f = Vertex (20.0,-20.0) |
---|
197 | |
---|
198 | t1 = Triangle(b,a,c) |
---|
199 | t2 = Triangle(e,d,f) |
---|
200 | |
---|
201 | # print "t1", t1 |
---|
202 | # print "t1 area ", t1.calcArea() |
---|
203 | # print "t2", t2 |
---|
204 | # print "t2 area ", t2.calcArea() |
---|
205 | self.failUnless( t1.calcArea() == 50 and t2.calcArea() == 400, 'Triangle area is wrong!') |
---|
206 | def testisUserSegmentNew (self): |
---|
207 | mesh = Mesh() |
---|
208 | a = mesh.addUserVertex(0.0, 0.0) |
---|
209 | b = mesh.addUserVertex (0.0, 2.0) |
---|
210 | c = mesh.addUserVertex (2.0,0.0) |
---|
211 | d = mesh.addUserVertex (2.0,3.0) |
---|
212 | |
---|
213 | s1 = mesh.addUserSegment(a,b) |
---|
214 | s2 = mesh.addUserSegment(a,c) |
---|
215 | s3 = mesh.addUserSegment(c,b) |
---|
216 | |
---|
217 | self.failUnless(mesh.isUserSegmentNew(a,d) , |
---|
218 | 'Segment should be new. ') |
---|
219 | self.failUnless(not(mesh.isUserSegmentNew(a,b)) , |
---|
220 | 'Segment should not be new. ') |
---|
221 | |
---|
222 | |
---|
223 | def testisUserSegmentNew (self): |
---|
224 | mesh = Mesh() |
---|
225 | a = mesh.addUserVertex(0.0, 0.0) |
---|
226 | b = mesh.addUserVertex (0.0, 2.0) |
---|
227 | c = mesh.addUserVertex (2.0,0.0) |
---|
228 | d = mesh.addUserVertex (2.0,3.0) |
---|
229 | |
---|
230 | s1 = mesh.addUserSegment(a,b) |
---|
231 | s2 = mesh.addUserSegment(a,c) |
---|
232 | s3 = mesh.addUserSegment(c,b) |
---|
233 | |
---|
234 | self.failUnless(mesh.representedUserSegment(a,d) == None, |
---|
235 | 'Segment should be new. ') |
---|
236 | self.failUnless(mesh.representedUserSegment(a,b) == s1 , |
---|
237 | 'Segment should not be new. ') |
---|
238 | |
---|
239 | def ztestautoSegment(self): |
---|
240 | p0 = Vertex (0.0, 0.0) |
---|
241 | p1 = Vertex (0.0, 4.0) |
---|
242 | p2 = Vertex (4.0,4.0) |
---|
243 | p3 = Vertex (4.0,0.0) |
---|
244 | |
---|
245 | s1 = Segment(p0,p1) |
---|
246 | |
---|
247 | m = Mesh(userVertices=[p0, p1, p2, p3], userSegments=[s1] ) |
---|
248 | m.autoSegment() |
---|
249 | |
---|
250 | #print 'Len', len(m.userSegments) |
---|
251 | self.failUnless(len(m.getUserSegments()) == 4 , |
---|
252 | 'userSegments is wrong!') |
---|
253 | |
---|
254 | m.autoSegment() |
---|
255 | self.failUnless(len(m.getUserSegments()) == 4 , |
---|
256 | 'userSegments is wrong!') |
---|
257 | |
---|
258 | def ztestautoSegmentII(self): |
---|
259 | p1 = Vertex (3.0, 4.0) |
---|
260 | p2 = Vertex (3.0,2.0) |
---|
261 | p3 = Vertex (3.0,0.0) |
---|
262 | p4 = Vertex (6.0, 4.0) |
---|
263 | p5 = Vertex (6.0,2.0) |
---|
264 | p0 = Vertex (6.0,0.0) |
---|
265 | |
---|
266 | |
---|
267 | s1 = Segment(p2,p3) |
---|
268 | s2 = Segment(p4,p5) |
---|
269 | |
---|
270 | m = Mesh(userVertices=[p0, p1, p2, p3, p4, p5], |
---|
271 | userSegments=[s1, s2]) |
---|
272 | |
---|
273 | m.autoSegment() |
---|
274 | |
---|
275 | s3 = m.representedAlphaUserSegment(p3,p0) |
---|
276 | self.failUnless(not (s3 == None) , |
---|
277 | 'userSegments is wrong!') |
---|
278 | |
---|
279 | |
---|
280 | s6 = m.representedAlphaUserSegment(p1,p4) |
---|
281 | self.failUnless(not (s6 == None) , |
---|
282 | 'userSegments is wrong!') |
---|
283 | |
---|
284 | # remove a segment, add a point, autosegment |
---|
285 | m.alphaUserSegments.remove(s3) |
---|
286 | p6 = Vertex (1.0, 2.0) |
---|
287 | m.userVertices.append(p6) |
---|
288 | m.autoSegment() |
---|
289 | |
---|
290 | s1_now = m.representedUserSegment(p3,p2) |
---|
291 | self.failUnless(s1_now == s1 , |
---|
292 | 'userSegments is wrong!') |
---|
293 | |
---|
294 | s2_now = m.representedUserSegment(p5,p4) |
---|
295 | self.failUnless(s2_now == s2 , |
---|
296 | 'userSegments is wrong!') |
---|
297 | |
---|
298 | s3 = m.representedAlphaUserSegment(p3,p6) |
---|
299 | self.failUnless(not (s3 == None) , |
---|
300 | 'userSegments is wrong!') |
---|
301 | |
---|
302 | s4 = m.representedAlphaUserSegment(p3,p6) |
---|
303 | self.failUnless(not (s4 == None) , |
---|
304 | 'userSegments is wrong!') |
---|
305 | |
---|
306 | s5 = m.representedAlphaUserSegment(p4,p6) |
---|
307 | self.failUnless(s5 == None , |
---|
308 | 'userSegments is wrong!') |
---|
309 | |
---|
310 | s6_now = m.representedAlphaUserSegment(p1,p4) |
---|
311 | self.failUnless(s6_now == s6 , |
---|
312 | 'userSegments is wrong!') |
---|
313 | |
---|
314 | |
---|
315 | |
---|
316 | #print m |
---|
317 | |
---|
318 | def testRegions(self): |
---|
319 | a = Vertex (0.0, 0.0) |
---|
320 | b = Vertex (0.0, 2.0) |
---|
321 | c = Vertex (2.0,0.0) |
---|
322 | d = Vertex (0.0, 4.0) |
---|
323 | e = Vertex (2.0, 2.0) |
---|
324 | f = Vertex (4.0,0.0) |
---|
325 | g = Vertex (0.0,-2.0) |
---|
326 | |
---|
327 | Segment.set_default_tag("") |
---|
328 | s1 = Segment(a,b) |
---|
329 | s2 = Segment(b,e) |
---|
330 | s3 = Segment(e,c) |
---|
331 | s4 = Segment(c,a) |
---|
332 | s5 = Segment(b,d) |
---|
333 | s6 = Segment(e,d) |
---|
334 | s7 = Segment(e,f) |
---|
335 | s8 = Segment(c,f) |
---|
336 | s9 = Segment(g,c) |
---|
337 | s10 = Segment(g,a) |
---|
338 | |
---|
339 | r1 = Region(0.1,0.1,tag="22") |
---|
340 | r2 = Region(0.1,2.1,tag="11") |
---|
341 | r3 = Region(2.1,0.1) |
---|
342 | |
---|
343 | m = Mesh(userVertices=[a,b,c,d,e,f,g], userSegments=[s1,s2,s3,s4,s5,s6,s7,s8,s9,s10], regions=[r1,r2,r3] ) |
---|
344 | m.generateMesh("QApz", maxArea = 2.1 ) |
---|
345 | #print m |
---|
346 | Triangulation = m.getTriangulation() |
---|
347 | #print Triangulation[0].attribute |
---|
348 | #print Triangulation[1].attribute |
---|
349 | #print Triangulation[2].attribute |
---|
350 | #print Triangulation[3].attribute |
---|
351 | #print Triangulation[4].attribute |
---|
352 | |
---|
353 | self.failUnless(Triangulation[0].attribute == "" and |
---|
354 | Triangulation[1].attribute == "22" and |
---|
355 | Triangulation[2].attribute == "" and |
---|
356 | Triangulation[3].attribute == "11" and |
---|
357 | Triangulation[4].attribute == "22" , |
---|
358 | 'region attributes are wrong!') |
---|
359 | |
---|
360 | def test_vertexAttribs(self): |
---|
361 | a = Vertex (0.0, 0.0, attributes = [12.0,2.0]) |
---|
362 | d = Vertex (0.0, 4.0, attributes = [9.0,7.0]) |
---|
363 | f = Vertex (4.0,0.0, attributes = [14.0,3.0]) |
---|
364 | |
---|
365 | Segment.set_default_tag("") |
---|
366 | s1 = Segment(a,d) |
---|
367 | s2 = Segment(d,f) |
---|
368 | s3 = Segment(a,f) |
---|
369 | |
---|
370 | r1 = Region(0.3, 0.3, tag = 88.9) |
---|
371 | |
---|
372 | m = Mesh(userVertices=[a,d,f], userSegments=[s1,s2,s3], regions=[r1]) |
---|
373 | |
---|
374 | m.generateMesh("QApz", maxArea = 2.1) |
---|
375 | |
---|
376 | vert = m.getMeshVertices() |
---|
377 | |
---|
378 | self.failUnless(vert[0].attributes == [12.0, 2.0] and |
---|
379 | vert[1].attributes == [9.0, 7.0] and |
---|
380 | vert[2].attributes == [14.0,3.0] and |
---|
381 | vert[3].attributes == [12.232233047033631, 4.4142135623730949] and |
---|
382 | vert[4].attributes == [13.0, 2.5] , |
---|
383 | 'vertex attributes are wrong!') |
---|
384 | |
---|
385 | |
---|
386 | def test_vertexAttribs2(self): |
---|
387 | |
---|
388 | a = Vertex (0.0, 0.0) |
---|
389 | d = Vertex (0.0, 4.0) |
---|
390 | f = Vertex (4.0,0.0) |
---|
391 | |
---|
392 | Segment.set_default_tag("") |
---|
393 | s1 = Segment(a,d) |
---|
394 | s2 = Segment(d,f) |
---|
395 | s3 = Segment(a,f) |
---|
396 | |
---|
397 | r1 = Region(0.3, 0.3, tag = 88.9) |
---|
398 | |
---|
399 | m = Mesh(userVertices=[a,d,f], userSegments=[s1,s2,s3], regions=[r1]) |
---|
400 | |
---|
401 | m.generateMesh("QApz", maxArea = 2.1 ) |
---|
402 | |
---|
403 | vert = m.getMeshVertices() |
---|
404 | self.failUnless(vert[0].attributes == [] and |
---|
405 | vert[1].attributes == [] and |
---|
406 | vert[2].attributes == [] and |
---|
407 | vert[3].attributes == [] and |
---|
408 | vert[4].attributes == [], |
---|
409 | 'vertex attributes are wrong!') |
---|
410 | |
---|
411 | def test_segtag(self): |
---|
412 | |
---|
413 | a = Vertex (0.0, 0.0) |
---|
414 | d = Vertex (0.0, 4.0) |
---|
415 | f = Vertex (4.0,0.0) |
---|
416 | |
---|
417 | s1 = Segment(a,d,tag = 5) |
---|
418 | s2 = Segment(d,f,tag = 7) |
---|
419 | s3 = Segment(a,f,tag = 9) |
---|
420 | |
---|
421 | m = Mesh(userVertices=[a,d,f], userSegments=[s1,s2,s3]) |
---|
422 | |
---|
423 | m.generateMesh("QApz", maxArea = 2.1 ) |
---|
424 | |
---|
425 | seg = m.getMeshSegments() |
---|
426 | |
---|
427 | #print "seg[0].tag" |
---|
428 | #print seg[0].tag |
---|
429 | #print "seg[0].tag" |
---|
430 | self.failUnless(seg[0].tag == 5 and |
---|
431 | seg[1].tag == 7 and |
---|
432 | seg[2].tag == 9 and |
---|
433 | seg[3].tag == 7 and |
---|
434 | seg[4].tag == 9 and |
---|
435 | seg[5].tag == 7 and |
---|
436 | seg[6].tag == 5, |
---|
437 | 'seg tags are wrong') |
---|
438 | |
---|
439 | def test_segtag2(self): |
---|
440 | |
---|
441 | a = Vertex (0.0, 0.0) |
---|
442 | d = Vertex (0.0, 4.0) |
---|
443 | f = Vertex (4.0,0.0) |
---|
444 | e = Vertex (1.0,1.0) |
---|
445 | |
---|
446 | s1 = Segment(a,d) |
---|
447 | s2 = Segment(d,f) |
---|
448 | s3 = Segment(a,f) |
---|
449 | s4 = Segment(a,e) |
---|
450 | |
---|
451 | m = Mesh(userVertices=[a,d,f,e], userSegments=[s1,s2,s3,s4]) |
---|
452 | |
---|
453 | m.generateMesh("QApz", maxArea = 2.1) |
---|
454 | |
---|
455 | seg = m.getMeshSegments() |
---|
456 | self.failUnless(seg[0].tag == "exterior" and |
---|
457 | seg[1].tag == "exterior" and |
---|
458 | seg[2].tag == "exterior" and |
---|
459 | seg[3].tag == "" and |
---|
460 | seg[4].tag == "exterior", |
---|
461 | '2nd seg tags are wrong') |
---|
462 | |
---|
463 | def test_asciiFile(self): |
---|
464 | |
---|
465 | a = Vertex (0.0, 0.0) #, attributes = [1.1]) |
---|
466 | d = Vertex (0.0, 4.0) #, attributes = [1.2]) |
---|
467 | f = Vertex (4.0,0.0) #, attributes = [1.3]) |
---|
468 | e = Vertex (1.0,1.0) #, attributes = [1.4]) |
---|
469 | |
---|
470 | s1 = Segment(a,d) |
---|
471 | s2 = Segment(d,f) |
---|
472 | s3 = Segment(a,f) |
---|
473 | s4 = Segment(a,e) |
---|
474 | |
---|
475 | m = Mesh(userVertices=[a,d,f,e], userSegments=[s1,s2,s3,s4]) |
---|
476 | |
---|
477 | m.generateMesh("QApz", maxArea = 2.1 ) |
---|
478 | |
---|
479 | seg = m.getMeshSegments() |
---|
480 | |
---|
481 | fileName = tempfile.mktemp(".tsh") |
---|
482 | m.export_mesh_file(fileName) |
---|
483 | file = open(fileName) |
---|
484 | lFile = file.read().split('\n') |
---|
485 | file.close() |
---|
486 | os.remove(fileName) |
---|
487 | |
---|
488 | #print "@^@^" |
---|
489 | #for l in lFile: |
---|
490 | # print l,"<" |
---|
491 | #print "@^@^" |
---|
492 | |
---|
493 | # no need to check the title again |
---|
494 | #self.failUnless(lFile[0] == "5 0 # <vertex #> <x> <y> [attributes] ...Triangulation Vertices..." |
---|
495 | # ,'Ascii file is wrong, vertex title') |
---|
496 | self.failUnless(lFile[1] == "0 0.0 0.0 " and #1.1 " and |
---|
497 | lFile[2] == "1 0.0 4.0 " and #1.2 " and |
---|
498 | lFile[3] == "2 4.0 0.0 " and #1.3 " and |
---|
499 | lFile[4] == "3 1.0 1.0 " and #1.4 " and |
---|
500 | lFile[5] == "4 2.0 2.0 " #1.25 " |
---|
501 | , |
---|
502 | 'Ascii file is wrong, vertex') |
---|
503 | |
---|
504 | #self.failUnless(lFile[6] == "# attribute column titles ...Triangulation Vertex Titles..." |
---|
505 | # ,'Ascii file is wrong, attribute column title') |
---|
506 | self.failUnless(lFile[8] == "0 3 2 4 -1 2 3 " and |
---|
507 | lFile[9] == "1 1 0 3 3 2 -1 " and |
---|
508 | lFile[10] == "2 3 4 1 -1 1 0 " and |
---|
509 | lFile[11] == "3 2 3 0 1 -1 0 " |
---|
510 | , |
---|
511 | 'Ascii file is wrong, triangle') |
---|
512 | |
---|
513 | self.failUnless( lFile[13] == "0 0 1 exterior" and |
---|
514 | lFile[14] == "1 1 4 exterior" and |
---|
515 | lFile[15] == "2 2 0 exterior" and |
---|
516 | lFile[16] == "3 0 3 " and |
---|
517 | lFile[17] == "4 4 2 exterior" , |
---|
518 | 'Ascii file is wrong, segment') |
---|
519 | |
---|
520 | # self.failUnless(lFile[18] == '4 0 # <vertex #> <x> <y> [attributes] ...Mesh Vertices...', |
---|
521 | # 'Ascii file is wrong, Mesh Vertices Title') |
---|
522 | |
---|
523 | self.failUnless(lFile[19] == '0 0.0 0.0 ' and #1.1 ' and |
---|
524 | lFile[20] == '1 0.0 4.0 ' and #1.2 ' and |
---|
525 | lFile[21] == '2 4.0 0.0 ' and #1.3 ' and |
---|
526 | lFile[22] == '3 1.0 1.0 ' #1.4 ' |
---|
527 | , |
---|
528 | 'Ascii file is wrong, Mesh Vertices II') |
---|
529 | |
---|
530 | self.failUnless(lFile[24] == '0 0 1 ' and |
---|
531 | lFile[25] == '1 1 2 ' and |
---|
532 | lFile[26] == '2 0 2 ' and |
---|
533 | lFile[27] == '3 0 3 ' |
---|
534 | ,'Ascii file is wrong, Mesh Segments') |
---|
535 | |
---|
536 | |
---|
537 | def test_ascii_file(self): |
---|
538 | |
---|
539 | a = Vertex (0.0, 0.0) #, attributes = [1.1]) |
---|
540 | d = Vertex (0.0, 4.0) #, attributes = [1.2]) |
---|
541 | f = Vertex (4.0,0.0) #, attributes = [1.3]) |
---|
542 | e = Vertex (1.0,1.0) #, attributes = [1.4]) |
---|
543 | |
---|
544 | s1 = Segment(a,d) |
---|
545 | s2 = Segment(d,f) |
---|
546 | s3 = Segment(a,f) |
---|
547 | s4 = Segment(a,e) |
---|
548 | |
---|
549 | m = Mesh(userVertices=[a,d,f,e], userSegments=[s1,s2,s3,s4]) |
---|
550 | |
---|
551 | m.generateMesh("QApz", maxArea = 2.1 ) |
---|
552 | |
---|
553 | seg = m.getMeshSegments() |
---|
554 | |
---|
555 | fileName = tempfile.mktemp(".tsh") |
---|
556 | m.export_mesh_file(fileName) |
---|
557 | file = open(fileName) |
---|
558 | lFile = file.read().split('\n') |
---|
559 | file.close() |
---|
560 | os.remove(fileName) |
---|
561 | |
---|
562 | #print "@^@^" |
---|
563 | #for l in lFile: |
---|
564 | # print l,"<" |
---|
565 | #print "@^@^" |
---|
566 | self.failUnless(lFile[0] == "5 0 # <# of verts> <# of vert attributes>, next lines <vertex #> <x> <y> [attributes] ...Triangulation Vertices..." |
---|
567 | , |
---|
568 | 'Ascii file is wrong, vertex title') |
---|
569 | self.failUnless(lFile[1] == "0 0.0 0.0 " and #1.1 " and |
---|
570 | lFile[2] == "1 0.0 4.0 " and #1.2 " and |
---|
571 | lFile[3] == "2 4.0 0.0 " and #1.3 " and |
---|
572 | lFile[4] == "3 1.0 1.0 " and #1.4 " and |
---|
573 | lFile[5] == "4 2.0 2.0 " #1.25 " |
---|
574 | , |
---|
575 | 'Ascii file is wrong, vertex') |
---|
576 | |
---|
577 | self.failUnless(lFile[6] == "# attribute column titles ...Triangulation Vertex Titles..." |
---|
578 | , |
---|
579 | 'Ascii file is wrong, attribute column title') |
---|
580 | self.failUnless(lFile[7] == "4 # <# of triangles>, next lines <triangle #> [<vertex #>] [<neigbouring triangle #>] [attribute of region] ...Triangulation Triangles..." and |
---|
581 | lFile[8] == "0 3 2 4 -1 2 3 " and |
---|
582 | lFile[9] == "1 1 0 3 3 2 -1 " and |
---|
583 | lFile[10] == "2 3 4 1 -1 1 0 " and |
---|
584 | lFile[11] == "3 2 3 0 1 -1 0 " |
---|
585 | , |
---|
586 | 'Ascii file is wrong, triangle') |
---|
587 | |
---|
588 | self.failUnless(lFile[12] == "5 # <# of segments>, next lines <segment #> <vertex #> <vertex #> [boundary tag] ...Triangulation Segments..." and |
---|
589 | lFile[13] == "0 0 1 exterior" and |
---|
590 | lFile[14] == "1 1 4 exterior" and |
---|
591 | lFile[15] == "2 2 0 exterior" and |
---|
592 | lFile[16] == "3 0 3 " and |
---|
593 | lFile[17] == "4 4 2 exterior" , |
---|
594 | 'Ascii file is wrong, segment') |
---|
595 | |
---|
596 | self.failUnless(lFile[18] == '4 0 # <# of verts> <# of vert attributes>, next lines <vertex #> <x> <y> [attributes] ...Mesh Vertices...', |
---|
597 | 'Ascii file is wrong, Mesh Vertices Title') |
---|
598 | |
---|
599 | self.failUnless(lFile[19] == '0 0.0 0.0 ' and #1.1 ' and |
---|
600 | lFile[20] == '1 0.0 4.0 ' and #1.2 ' and |
---|
601 | lFile[21] == '2 4.0 0.0 ' and #1.3 ' and |
---|
602 | lFile[22] == '3 1.0 1.0 ' #1.4 ' |
---|
603 | , |
---|
604 | 'Ascii file is wrong, Mesh Vertices II') |
---|
605 | |
---|
606 | self.failUnless(lFile[23] == '4 # <# of segments>, next lines <segment #> <vertex #> <vertex #> [boundary tag] ...Mesh Segments...' and |
---|
607 | lFile[24] == '0 0 1 ' and |
---|
608 | lFile[25] == '1 1 2 ' and |
---|
609 | lFile[26] == '2 0 2 ' and |
---|
610 | lFile[27] == '3 0 3 ' and |
---|
611 | lFile[28] == '0 # <# of holes>, next lines <Hole #> <x> <y> ...Mesh Holes...' and |
---|
612 | lFile[29] == '0 # <# of regions>, next lines <Region #> <x> <y> <tag>...Mesh Regions...' |
---|
613 | , |
---|
614 | 'Ascii file is wrong, Mesh Segments') |
---|
615 | |
---|
616 | |
---|
617 | def test_thinoutVertices(self): |
---|
618 | |
---|
619 | v1 = Vertex(-20,-20) |
---|
620 | v2 = Vertex(-11,-11) |
---|
621 | v3 = Vertex(-10,-10) |
---|
622 | v4 = Vertex(-9,-1) |
---|
623 | v5 = Vertex(-8,2) |
---|
624 | v6 = Vertex(6,3) |
---|
625 | v7 = Vertex(12,9) |
---|
626 | v8 = Vertex(15,3) |
---|
627 | v9 = Vertex(24,3) |
---|
628 | m = Mesh(userVertices = [v1,v2,v3,v4,v5,v6,v7,v8,v9]) |
---|
629 | m.thinoutVertices(10) |
---|
630 | |
---|
631 | self.failUnless(v1 in m.userVertices, |
---|
632 | 'test_thinoutVertices, test 1 failed') |
---|
633 | self.failUnless(v3 in m.userVertices, |
---|
634 | 'test_thinoutVertices, test 2 failed') |
---|
635 | self.failUnless(v4 in m.userVertices, |
---|
636 | 'test_thinoutVertices, test 3 failed') |
---|
637 | self.failUnless(v6 in m.userVertices, |
---|
638 | 'test_thinoutVertices, test 4 failed') |
---|
639 | self.failUnless(v7 in m.userVertices, |
---|
640 | 'test_thinoutVertices, test 5 failed') |
---|
641 | self.failUnless(v9 in m.userVertices, |
---|
642 | 'test_thinoutVertices, test 6 failed') |
---|
643 | self.failUnless(v5 not in m.userVertices, |
---|
644 | 'test_thinoutVertices, test 7 failed') |
---|
645 | self.failUnless(v2 not in m.userVertices, |
---|
646 | 'test_thinoutVertices, test 8 failed') |
---|
647 | self.failUnless(v8 not in m.userVertices, |
---|
648 | 'test_thinoutVertices, test 9 failed') |
---|
649 | |
---|
650 | def test_same_x_y(self): |
---|
651 | v = Point(7,8) |
---|
652 | f = Point(7,8) |
---|
653 | f.same_x_y(v) |
---|
654 | |
---|
655 | self.failUnless(f.same_x_y(v), |
---|
656 | 'same_x_y True failed') |
---|
657 | e = Point(7,9) |
---|
658 | self.failUnless(not f.same_x_y(e), |
---|
659 | 'same_x_y False failed') |
---|
660 | |
---|
661 | def test_import_tsh(self): |
---|
662 | |
---|
663 | a_att = [5.0,2.0] |
---|
664 | d_att =[4.0,2.0] |
---|
665 | f_att = [3.0,2.0] |
---|
666 | e_att = [2.0,2.0] |
---|
667 | a_xy = [0.0, 0.0] |
---|
668 | a = Vertex ( a_xy[0],a_xy[1]) #, attributes =a_att) |
---|
669 | d = Vertex (0.0, 4.0) #, attributes =d_att) |
---|
670 | f = Vertex (4.0,0.0) #, attributes =f_att) |
---|
671 | e = Vertex (1.0,1.0) #, attributes =e_att) |
---|
672 | |
---|
673 | s1 = Segment(a,d, tag = "50") |
---|
674 | s2 = Segment(d,f, tag = "40") |
---|
675 | s3 = Segment(a,f, tag = "30") |
---|
676 | s4 = Segment(a,e, tag = "20") |
---|
677 | |
---|
678 | r1 = Region(0.3, 0.3,tag = "1.3") |
---|
679 | geo = Geo_reference(8.9,8.9,65) |
---|
680 | m = Mesh(userVertices=[a,d,f,e], |
---|
681 | userSegments=[s1,s2,s3,s4], |
---|
682 | regions=[r1], |
---|
683 | geo_reference=geo) |
---|
684 | |
---|
685 | m.generateMesh("QApz", maxArea = 2.1) |
---|
686 | fileName = tempfile.mktemp(".tsh") |
---|
687 | #print "dgs!!!" |
---|
688 | #print "****************** fileName", fileName |
---|
689 | m.export_mesh_file(fileName) |
---|
690 | #print "******************" |
---|
691 | #print "m", m |
---|
692 | #print "******************" |
---|
693 | m_returned = importMeshFromFile(fileName) |
---|
694 | #print "m_returned",m_returned |
---|
695 | #print "******************" |
---|
696 | #print "****************** fileName", fileName |
---|
697 | os.remove(fileName) |
---|
698 | self.failUnless(0 == m.__cmp__(m_returned), |
---|
699 | 'loading and saving of a mesh failed') |
---|
700 | # do this when .msh supports geo_refs |
---|
701 | #self.failUnless(m.geo_reference == m_returned.geo_reference, |
---|
702 | # 'loading and saving of a mesh geo refs failed') |
---|
703 | |
---|
704 | def test_import_mesh(self): |
---|
705 | |
---|
706 | a_att = [5.0,2.0] |
---|
707 | d_att =[4.0,2.0] |
---|
708 | f_att = [3.0,2.0] |
---|
709 | e_att = [2.0,2.0] |
---|
710 | a_xy = [0.0, 0.0] |
---|
711 | a = Vertex ( a_xy[0],a_xy[1]) #, attributes =a_att) |
---|
712 | d = Vertex (0.0, 4.0) #, attributes =d_att) |
---|
713 | f = Vertex (4.0,0.0) #, attributes =f_att) |
---|
714 | e = Vertex (1.0,1.0) #, attributes =e_att) |
---|
715 | |
---|
716 | s1 = Segment(a,d, tag = "50") |
---|
717 | s2 = Segment(d,f, tag = "40") |
---|
718 | s3 = Segment(a,f, tag = "30") |
---|
719 | s4 = Segment(a,e, tag = "20") |
---|
720 | |
---|
721 | r1 = Region(0.3, 0.3,tag = "1.3") |
---|
722 | geo = Geo_reference(65,8.9,8.9) |
---|
723 | m = Mesh(userVertices=[a,d,f,e], |
---|
724 | userSegments=[s1,s2,s3,s4], |
---|
725 | regions=[r1], |
---|
726 | geo_reference=geo) |
---|
727 | |
---|
728 | m.generateMesh("QApz", maxArea = 2.1) |
---|
729 | fileName = tempfile.mktemp(".msh") |
---|
730 | #print "dgs!!!" |
---|
731 | #print "****************** fileName", fileName |
---|
732 | m.export_mesh_file(fileName) |
---|
733 | #print "******************" |
---|
734 | #print "m", m |
---|
735 | #print "******************" |
---|
736 | m_returned = importMeshFromFile(fileName) |
---|
737 | #print "m_returned",m_returned |
---|
738 | #print "******************" |
---|
739 | #print "****************** fileName", fileName |
---|
740 | os.remove(fileName) |
---|
741 | #print "m.geo_reference",m.geo_reference |
---|
742 | #print "m_returned.geo_reference,",m_returned.geo_reference |
---|
743 | self.failUnless(0 == m.__cmp__(m_returned), |
---|
744 | 'loading and saving of a mesh failed') |
---|
745 | self.failUnless(m.geo_reference == m_returned.geo_reference, |
---|
746 | 'loading and saving of a mesh geo refs failed') |
---|
747 | |
---|
748 | def test_normaliseMesh(self): |
---|
749 | |
---|
750 | a_att = [5.0,2.0] |
---|
751 | d_att =[4.0,2.0] |
---|
752 | f_att = [3.0,2.0] |
---|
753 | e_att = [2.0,2.0] |
---|
754 | a_xy = [10.0, 10.0] |
---|
755 | a = Vertex ( a_xy[0],a_xy[1], attributes =a_att) |
---|
756 | d = Vertex (15.0, 10.0, attributes =d_att) |
---|
757 | f = Vertex (10.0,20.0, attributes =f_att) |
---|
758 | e = Vertex (15.0,20.0, attributes =e_att) |
---|
759 | |
---|
760 | s1 = Segment(a,d, tag = 50) |
---|
761 | s2 = Segment(d,e, tag = 40) |
---|
762 | s3 = Segment(e,f, tag = 30) |
---|
763 | s4 = Segment(f,a, tag = 20) |
---|
764 | |
---|
765 | r1 = Region(0.3, 0.3,tag = 1.3) |
---|
766 | m = Mesh(userVertices=[a,d,f,e], |
---|
767 | userSegments=[s1,s2,s3,s4], |
---|
768 | regions=[r1]) |
---|
769 | m.normaliseMesh(1,0,1) |
---|
770 | [xmin, ymin, xmax, ymax] = m.boxsize() |
---|
771 | [attmin, attmax] = m.maxMinVertAtt(0) |
---|
772 | self.failUnless(attmin == 0.0 and attmax == 1.0, |
---|
773 | 'normalise failed') |
---|
774 | self.failUnless(xmin == 0.0 and ymin == 0.0 and xmax == 0.5 and ymax == 1.0, |
---|
775 | 'normalise failed') |
---|
776 | m.normaliseMesh(200,-100,5) |
---|
777 | [xmin, ymin, xmax, ymax] = m.boxsize() |
---|
778 | [attmin, attmax] = m.maxMinVertAtt(0) |
---|
779 | self.failUnless(attmin == 0.0 and attmax == 5.0, |
---|
780 | 'normalise failed') |
---|
781 | self.failUnless(xmin == -100.0 and ymin == -100.0 and xmax == 0.0 and ymax == 100.0, |
---|
782 | 'normalise failed') |
---|
783 | # Fix me, this function has a bug |
---|
784 | def zztest_exportASCIIsegmentoutlinefile(self): |
---|
785 | a = Vertex (0,0) |
---|
786 | b = Vertex (0,3) |
---|
787 | c = Vertex (3,3) |
---|
788 | d = Vertex (1,2) |
---|
789 | e = Vertex (3,1) |
---|
790 | |
---|
791 | s1 = Segment(a,b, tag = "50") |
---|
792 | s2 = Segment(b,c, tag = "40") |
---|
793 | s3 = Segment(c,a, tag = "30") |
---|
794 | |
---|
795 | r1 = Region(2, 1,tag = "1.3") |
---|
796 | h1 = Hole(1,4) |
---|
797 | m = Mesh(userVertices=[a,b,c,d,e], |
---|
798 | userSegments=[s1,s2,s3], |
---|
799 | regions=[r1], |
---|
800 | holes = [h1]) |
---|
801 | |
---|
802 | m.generateMesh("QApz", maxArea = 2.1) |
---|
803 | #print "mesh ***************dsg*", m |
---|
804 | |
---|
805 | fileName = tempfile.mktemp(".tsh") |
---|
806 | m.exportASCIIsegmentoutlinefile(fileName) |
---|
807 | |
---|
808 | m_returned = importMeshFromFile(fileName) |
---|
809 | |
---|
810 | #print "m_returned ****",m_returned |
---|
811 | #print "****************** fileName", fileName |
---|
812 | os.remove(fileName) |
---|
813 | |
---|
814 | #Trim mesh, so it should like like m_returned |
---|
815 | m.meshVertices = [] |
---|
816 | m.meshTriangles = [] |
---|
817 | m.meshSegments = [] |
---|
818 | m.userVertices=[a,b,c] |
---|
819 | #print "mesh ***************dsg*", m |
---|
820 | #print "(m.__cmp__(m_returned)", m.__cmp__(m_returned) |
---|
821 | self.failUnless(0 == m.__cmp__(m), |
---|
822 | 'test_exportASCIIsegmentoutlinefile:loading and saving of a mesh failed') |
---|
823 | self.failUnless(0 == m.__cmp__(m_returned), |
---|
824 | 'test_exportASCIIsegmentoutlinefile:loading and saving of a mesh failed') |
---|
825 | |
---|
826 | def test_loadxy2(self): |
---|
827 | """ |
---|
828 | To test the mesh side of loading xya files. |
---|
829 | Not the loading of xya files |
---|
830 | """ |
---|
831 | import os |
---|
832 | import tempfile |
---|
833 | |
---|
834 | fileName = tempfile.mktemp(".xya") |
---|
835 | file = open(fileName,"w") |
---|
836 | file.write("elevation, speed \n\ |
---|
837 | 1.0, 0.0, 10.0, 0.0\n\ |
---|
838 | 0.0, 1.0, 0.0, 10.0\n\ |
---|
839 | 1.0, 0.0, 10.4, 40.0\n") |
---|
840 | file.close() |
---|
841 | #print fileName |
---|
842 | m = importMeshFromFile(fileName) |
---|
843 | os.remove(fileName) |
---|
844 | |
---|
845 | def test_loadxy(self): |
---|
846 | """ |
---|
847 | To test the mesh side of loading xya files. |
---|
848 | Not the loading of xya files |
---|
849 | """ |
---|
850 | import os |
---|
851 | import tempfile |
---|
852 | |
---|
853 | fileName = tempfile.mktemp(".xya") |
---|
854 | file = open(fileName,"w") |
---|
855 | file.write("elevation speed \n\ |
---|
856 | 1.0 0.0 10.0 0.0\n\ |
---|
857 | 0.0 1.0 0.0 10.0\n\ |
---|
858 | 1.0 0.0 10.4 40.0\n") |
---|
859 | file.close() |
---|
860 | #print fileName |
---|
861 | m = importMeshFromFile(fileName) |
---|
862 | os.remove(fileName) |
---|
863 | self.failUnless(m.userVertices[0].x == 1.0, |
---|
864 | 'loadxy, test 1 failed') |
---|
865 | self.failUnless(m.userVertices[0].y == 0.0, |
---|
866 | 'loadxy, test 2 failed') |
---|
867 | #self.failUnless(m.userVertices[0].attributes == [10.0,0.0], |
---|
868 | # 'loadxy, test 2.2 failed') |
---|
869 | self.failUnless(m.userVertices[1].x == 0.0, |
---|
870 | 'loadxy, test 3 failed') |
---|
871 | self.failUnless(m.userVertices[1].y == 1.0, |
---|
872 | 'loadxy, test 4 failed') |
---|
873 | #self.failUnless(m.userVertices[1].attributes == [0.0,10.0], |
---|
874 | # 'loadxy, test 5 failed') |
---|
875 | |
---|
876 | def test_exportxyafile(self): |
---|
877 | a = Vertex (0,0) |
---|
878 | b = Vertex (0,3) |
---|
879 | c = Vertex (3,3) |
---|
880 | d = Vertex (1,2) |
---|
881 | e = Vertex (3,1) |
---|
882 | f = Vertex (3,1) |
---|
883 | |
---|
884 | s1 = Segment(a,b, tag = 50) |
---|
885 | s2 = Segment(b,c, tag = 40) |
---|
886 | s3 = Segment(c,a, tag = 30) |
---|
887 | |
---|
888 | r1 = Region(2, 1,tag = 1.3) |
---|
889 | h1 = Hole(1,4) |
---|
890 | # Warning mesh can't produce this type of data structure its self |
---|
891 | m = Mesh(userVertices=[a,b,c,d,e], |
---|
892 | userSegments=[s1,s2,s3], |
---|
893 | regions=[r1], |
---|
894 | holes = [h1]) |
---|
895 | |
---|
896 | fileName = tempfile.mktemp(".txt") |
---|
897 | m.exportxyafile(fileName) |
---|
898 | file = open(fileName) |
---|
899 | lFile = file.read().split('\n') |
---|
900 | file.close() |
---|
901 | |
---|
902 | #print "**********************" |
---|
903 | #print lFile |
---|
904 | #print "**********************" |
---|
905 | |
---|
906 | os.remove(fileName) |
---|
907 | self.failUnless(lFile[0] == "5 0 # <vertex #> <x> <y> [attributes]" and |
---|
908 | lFile[1] == "0 0 " and |
---|
909 | lFile[2] == "0 3 " and |
---|
910 | lFile[3] == "3 3 " and |
---|
911 | lFile[4] == "1 2 " and |
---|
912 | lFile[5] == "3 1 " |
---|
913 | , |
---|
914 | 'exported Ascii xya file is wrong') |
---|
915 | |
---|
916 | m.generateMesh("QApz", maxArea = 2.1) |
---|
917 | fileName = tempfile.mktemp(".txt") |
---|
918 | m.exportxyafile(fileName) |
---|
919 | file = open(fileName) |
---|
920 | lFile = file.read().split('\n') |
---|
921 | file.close() |
---|
922 | os.remove(fileName) |
---|
923 | self.failUnless(lFile[0] == "6 0 # <vertex #> <x> <y> [attributes]" and |
---|
924 | lFile[1] == "0.0 0.0 " and |
---|
925 | lFile[2] == "0.0 3.0 " and |
---|
926 | lFile[3] == "3.0 3.0 " and |
---|
927 | lFile[4] == "1.0 2.0 " and |
---|
928 | lFile[5] == "3.0 1.0 " and |
---|
929 | lFile[6] == "1.5 1.5 " |
---|
930 | , |
---|
931 | 'exported Ascii xya file is wrong') |
---|
932 | |
---|
933 | def test_strings2ints(self): |
---|
934 | list = ["sea","river inlet","","sea","","moat"] |
---|
935 | preset = ["moat", "internal boundary"] |
---|
936 | [intlist, converter] = segment_strings2ints(list,preset ) |
---|
937 | self.failUnless(intlist == [2,3 ,0 ,2 ,0 ,0 ] |
---|
938 | , |
---|
939 | 'test_strings2ints produces bad intlist') |
---|
940 | self.failUnless(converter == ['moat', 'internal boundary', |
---|
941 | 'sea', 'river inlet'] |
---|
942 | , |
---|
943 | 'test_strings2ints produces bad converter') |
---|
944 | |
---|
945 | def test_ints2strings(self): |
---|
946 | list = ["internal boundary","sea","river inlet", |
---|
947 | "","sea","","moat","internal boundary"] |
---|
948 | outlist = ['internal boundary', 'sea', 'river inlet', 'moat', |
---|
949 | 'sea', 'moat', 'moat', 'internal boundary'] |
---|
950 | preset = ["moat", "internal boundary"] |
---|
951 | [intlist, converter] = segment_strings2ints(list,preset ) |
---|
952 | newlist = segment_ints2strings(intlist, converter) |
---|
953 | self.failUnless(outlist == newlist |
---|
954 | , |
---|
955 | 'test_strings2ints produces bad intlist') |
---|
956 | self.failUnless(converter == ['moat', 'internal boundary', |
---|
957 | 'sea', 'river inlet'] |
---|
958 | , |
---|
959 | 'test_strings2ints produces bad converter') |
---|
960 | |
---|
961 | def test_ints2strings2(self): |
---|
962 | list = ["","",""] |
---|
963 | preset = ["moat", "internal boundary"] |
---|
964 | [intlist, converter] = segment_strings2ints(list,preset ) |
---|
965 | newlist = segment_ints2strings(intlist, converter) |
---|
966 | outlist = ['moat', 'moat', 'moat'] |
---|
967 | self.failUnless(outlist == newlist |
---|
968 | , |
---|
969 | 'test_strings2ints produces bad intlist') |
---|
970 | self.failUnless(converter == ['moat', 'internal boundary'] |
---|
971 | , |
---|
972 | 'test_strings2ints produces bad converter') |
---|
973 | |
---|
974 | |
---|
975 | def test_removeDuplicatedVertices(self): |
---|
976 | a = Vertex (0,0) |
---|
977 | a.index = 0 |
---|
978 | b = Vertex (0,3) |
---|
979 | b.index = 1 |
---|
980 | c = Vertex (3,3) |
---|
981 | c.index = 2 |
---|
982 | d = Vertex (1,1) |
---|
983 | d.index = 3 |
---|
984 | e = Vertex (3,1) |
---|
985 | e.index = 4 |
---|
986 | f = Vertex (1,1) |
---|
987 | f.index = 5 |
---|
988 | g = Vertex (1,1) |
---|
989 | g.index = 6 |
---|
990 | inputVerts_noDups = [a,b,c,d,e] |
---|
991 | |
---|
992 | m = Mesh(userVertices=[a,b,c,d,e,f,g]) |
---|
993 | counter = m.removeDuplicatedUserVertices() |
---|
994 | UserVerts = m.getUserVertices() |
---|
995 | |
---|
996 | |
---|
997 | self.failUnless(UserVerts == inputVerts_noDups, |
---|
998 | 'duplicate verts not removed') |
---|
999 | #for userVert, inputVert in map(None, UserVerts, inputVerts_noDups): |
---|
1000 | # self.failUnless(userVert.x == inputVert.x, |
---|
1001 | # 'x duplicate verts not removed') |
---|
1002 | # self.failUnless(userVert.y == inputVert.y, |
---|
1003 | # 'y duplicate verts not removed') |
---|
1004 | |
---|
1005 | |
---|
1006 | def test_ungenerateFileLoading(self): |
---|
1007 | |
---|
1008 | fileName = tempfile.mktemp(".txt") |
---|
1009 | file = open(fileName,"w") |
---|
1010 | file.write(" 1 ?? ??\n\ |
---|
1011 | 0.0 0.0\n\ |
---|
1012 | 1.0 0.0\n\ |
---|
1013 | 1.0 1.0\n\ |
---|
1014 | 0.0 1.0\n\ |
---|
1015 | 0.0 0.0\n\ |
---|
1016 | END\n\ |
---|
1017 | 2 ?? ??\n\ |
---|
1018 | 10.0 10.0\n\ |
---|
1019 | 10.0 20.0\n\ |
---|
1020 | 20.0 20.0\n\ |
---|
1021 | 10.0 10.0\n\ |
---|
1022 | END\n\ |
---|
1023 | END\n") |
---|
1024 | file.close() |
---|
1025 | |
---|
1026 | |
---|
1027 | a = Vertex (0.0, 0.0) #, attributes = [1.1]) |
---|
1028 | b = Vertex (0.0, 40.0) #, attributes = [1.2]) |
---|
1029 | c = Vertex (40.0,40.0) #, attributes = [1.3]) |
---|
1030 | d = Vertex (40.0,0.0) #, attributes = [1.4]) |
---|
1031 | |
---|
1032 | s1 = Segment(a,b) |
---|
1033 | s2 = Segment(b,c) |
---|
1034 | s3 = Segment(c,d) |
---|
1035 | s4 = Segment(d,a) |
---|
1036 | |
---|
1037 | m = Mesh(userVertices=[a,b,c,d], userSegments=[s1,s2,s3,s4]) |
---|
1038 | dict = importUngenerateFile(fileName) |
---|
1039 | |
---|
1040 | tag = "DSG" |
---|
1041 | Segment.set_default_tag(tag) |
---|
1042 | m.addVertsSegs(dict) |
---|
1043 | |
---|
1044 | # have to reset this , since it's a class attribute |
---|
1045 | Segment.set_default_tag("") |
---|
1046 | |
---|
1047 | self.failUnless(len(m.userSegments) ==11, |
---|
1048 | 'Wrong segment list length.') |
---|
1049 | self.failUnless(len(m.userVertices) == 11, |
---|
1050 | 'Wrong vertex list length.') |
---|
1051 | self.failUnless(m.userSegments[10].vertices[0] == m.userVertices[10], |
---|
1052 | 'bad vertex on segment.') |
---|
1053 | self.failUnless(m.userSegments[10].vertices[1] == m.userVertices[8], |
---|
1054 | 'Bad segment.') |
---|
1055 | self.failUnless(m.userSegments[10].tag == tag, |
---|
1056 | 'wrong tag.') |
---|
1057 | |
---|
1058 | def test_ungenerateFileLoadingII(self): |
---|
1059 | |
---|
1060 | fileName = tempfile.mktemp(".txt") |
---|
1061 | file = open(fileName,"w") |
---|
1062 | file.write(" 1 ?? ??\n\ |
---|
1063 | 0.0 0.0\n\ |
---|
1064 | 1.0 0.0\n\ |
---|
1065 | 1.0 1.0\n\ |
---|
1066 | 0.0 1.0\n\ |
---|
1067 | 0.0 0.0\n\ |
---|
1068 | END\n\ |
---|
1069 | 2 ?? ??\n\ |
---|
1070 | 10.0 10.0\n\ |
---|
1071 | 10.0 20.0\n\ |
---|
1072 | 20.0 20.0\n\ |
---|
1073 | END\n\ |
---|
1074 | END\n") |
---|
1075 | file.close() |
---|
1076 | |
---|
1077 | |
---|
1078 | a = Vertex (0.0, 0.0) #, attributes = [1.1]) |
---|
1079 | b = Vertex (0.0, 40.0) #, attributes = [1.2]) |
---|
1080 | c = Vertex (40.0,40.0) #, attributes = [1.3]) |
---|
1081 | d = Vertex (40.0,0.0) #, attributes = [1.4]) |
---|
1082 | |
---|
1083 | s1 = Segment(a,b) |
---|
1084 | s2 = Segment(b,c) |
---|
1085 | s3 = Segment(c,d) |
---|
1086 | s4 = Segment(d,a) |
---|
1087 | |
---|
1088 | m = Mesh(userVertices=[a,b,c,d], userSegments=[s1,s2,s3,s4]) |
---|
1089 | dict = importUngenerateFile(fileName) |
---|
1090 | |
---|
1091 | tag = "DSG" |
---|
1092 | Segment.set_default_tag(tag) |
---|
1093 | m.addVertsSegs(dict) |
---|
1094 | |
---|
1095 | self.failUnless(len(m.userSegments) ==10, |
---|
1096 | 'Wrong segment list length.') |
---|
1097 | self.failUnless(len(m.userVertices) == 11, |
---|
1098 | 'Wrong vertex list length.') |
---|
1099 | |
---|
1100 | def test_addVertsSegs(self): |
---|
1101 | m = Mesh() |
---|
1102 | Segment.set_default_tag("food") |
---|
1103 | dict = {} |
---|
1104 | dict['points'] = [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0]] |
---|
1105 | dict['segments'] = [[0, 1], [1, 2]] |
---|
1106 | dict['segment_tags'] = ['','do-op'] |
---|
1107 | m.addVertsSegs(dict) |
---|
1108 | # have to reset this , since it's a class attribute |
---|
1109 | Segment.set_default_tag("") |
---|
1110 | |
---|
1111 | |
---|
1112 | self.failUnless(len(m.userSegments) ==2, |
---|
1113 | 'Wrong segment list length.') |
---|
1114 | self.failUnless(len(m.userVertices) == 3, |
---|
1115 | 'Wrong vertex list length.') |
---|
1116 | self.failUnless(m.userSegments[0].tag =='food', |
---|
1117 | 'Wrong segment tag length.') |
---|
1118 | self.failUnless(m.userSegments[1].tag =='do-op', |
---|
1119 | 'Wrong segment tag.') |
---|
1120 | |
---|
1121 | def test_exportASCIImeshfile(self): |
---|
1122 | |
---|
1123 | #a_att = [5,2] |
---|
1124 | #d_att =[4,2] |
---|
1125 | #f_att = [3,2] |
---|
1126 | #e_att = [2,2] |
---|
1127 | a_xy = [0.0, 0.0] |
---|
1128 | a = Vertex ( a_xy[0],a_xy[1]) #, attributes =a_att) |
---|
1129 | d = Vertex (0.0, 4.0) #, attributes =d_att) |
---|
1130 | f = Vertex (4.0,0.0) #, attributes =f_att) |
---|
1131 | e = Vertex (1.0,1.0) #, attributes =e_att) |
---|
1132 | |
---|
1133 | s1 = Segment(a,d, tag = "50") |
---|
1134 | s2 = Segment(d,f, tag = "40") |
---|
1135 | s3 = Segment(a,f, tag = "30") |
---|
1136 | s4 = Segment(a,e, tag = "20") |
---|
1137 | |
---|
1138 | r1 = Region(0.3, 0.3,tag = "1.3", maxArea = 36) |
---|
1139 | |
---|
1140 | |
---|
1141 | h1 = Hole(0.2,0.6) |
---|
1142 | |
---|
1143 | m = Mesh(userVertices=[a,d,f,e], |
---|
1144 | userSegments=[s1,s2,s3,s4], |
---|
1145 | regions=[r1], |
---|
1146 | holes=[h1]) |
---|
1147 | |
---|
1148 | seg = m.getUserSegments() |
---|
1149 | points = m.getUserVertices() |
---|
1150 | holes = m.getHoles() |
---|
1151 | regions = m.getRegions() |
---|
1152 | fileName = tempfile.mktemp(".tsh") |
---|
1153 | m.export_mesh_file(fileName) |
---|
1154 | #print "***************************fileName", fileName |
---|
1155 | new_m = importMeshFromFile(fileName) |
---|
1156 | os.remove(fileName) |
---|
1157 | |
---|
1158 | |
---|
1159 | #print '**@@@@@******' |
---|
1160 | #print "new_m",new_m |
---|
1161 | #print '**@@@@@******' |
---|
1162 | #print "m",m |
---|
1163 | #print '**@@@@@******' |
---|
1164 | |
---|
1165 | self.failUnless( new_m == m, |
---|
1166 | 'loadASCIITestCase failed. test new 1') |
---|
1167 | |
---|
1168 | def test_Mesh2MeshList(self): |
---|
1169 | |
---|
1170 | a_att = [5,2] |
---|
1171 | d_att =[4,2] |
---|
1172 | f_att = [3,2] |
---|
1173 | e_att = [2,2] |
---|
1174 | a_xy = [0.0, 0.0] |
---|
1175 | a = Vertex ( a_xy[0],a_xy[1]) #, attributes =a_att) |
---|
1176 | d = Vertex (0.0, 4.0) #, attributes =d_att) |
---|
1177 | f = Vertex (4.0,0.0) #, attributes =f_att) |
---|
1178 | e = Vertex (1.0,1.0) #, attributes =e_att) |
---|
1179 | |
---|
1180 | s1 = Segment(a,d, tag = "50") |
---|
1181 | s2 = Segment(d,f, tag = "40") |
---|
1182 | s3 = Segment(a,f, tag = "30") |
---|
1183 | s4 = Segment(a,e, tag = "20") |
---|
1184 | |
---|
1185 | r1 = Region(0.3, 0.3,tag = "1.3", maxArea = 45) |
---|
1186 | m = Mesh(userVertices=[a,d,f,e], |
---|
1187 | userSegments=[s1,s2,s3,s4], |
---|
1188 | regions=[r1]) |
---|
1189 | |
---|
1190 | m.generateMesh("QApza2.1") |
---|
1191 | |
---|
1192 | seg = m.getMeshSegments() |
---|
1193 | points = m.getMeshVertices() |
---|
1194 | dict = m.Mesh2MeshList() |
---|
1195 | #print "dict",dict |
---|
1196 | # test not finished... |
---|
1197 | |
---|
1198 | def test_Mesh2IOTriangulationDict(self): |
---|
1199 | |
---|
1200 | a_att = [5,2] |
---|
1201 | d_att =[4,2] |
---|
1202 | f_att = [3,2] |
---|
1203 | e_att = [2,2] |
---|
1204 | a_xy = [0.0, 0.0] |
---|
1205 | a = Vertex ( a_xy[0],a_xy[1] , attributes =a_att) |
---|
1206 | d = Vertex (0.0, 4.0 , attributes =d_att) |
---|
1207 | f = Vertex (4.0,0.0 , attributes =f_att) |
---|
1208 | e = Vertex (1.0,1.0 , attributes =e_att) |
---|
1209 | |
---|
1210 | s1 = Segment(a,d, tag = "50") |
---|
1211 | s2 = Segment(d,f, tag = "40") |
---|
1212 | s3 = Segment(a,f, tag = "30") |
---|
1213 | s4 = Segment(a,e, tag = "20") |
---|
1214 | |
---|
1215 | r1 = Region(0.3, 0.3,tag = "1.3", maxArea = 45) |
---|
1216 | m = Mesh(userVertices=[a,d,f,e], |
---|
1217 | userSegments=[s1,s2,s3,s4], |
---|
1218 | regions=[r1]) |
---|
1219 | titles = ['ele','friction'] |
---|
1220 | m.attributeTitles = titles |
---|
1221 | m.generateMesh("QApza2.1") |
---|
1222 | |
---|
1223 | seg = m.getMeshSegments() |
---|
1224 | verts = m.getMeshVertices() |
---|
1225 | dict = m.Mesh2IOTriangulationDict() |
---|
1226 | #print "dict",dict |
---|
1227 | |
---|
1228 | self.failUnless( dict['vertex_attribute_titles'] == titles, |
---|
1229 | 'test_Mesh2IOTriangulationDict failed. test 1') |
---|
1230 | answer = [a_xy,[0.0, 4.0],[4.0,0.0], [1.0,1.0], [2.0,2.0]] |
---|
1231 | #print "answer",answer |
---|
1232 | #print "dict['vertices']",dict['vertices'] |
---|
1233 | |
---|
1234 | self.failUnless( dict['vertices'] == answer, |
---|
1235 | 'test_Mesh2IOTriangulationDict failed. test 2') |
---|
1236 | |
---|
1237 | |
---|
1238 | for pimport,pactual,pimpatt in map(None,dict['vertices'], |
---|
1239 | verts,dict['vertex_attributes']): |
---|
1240 | #assert all_close( pimport, (pactual.x,pactual.y)) |
---|
1241 | self.failUnless( pimport == [pactual.x,pactual.y], |
---|
1242 | 'test_Mesh2IOTriangulationDict failed. test 2.1') |
---|
1243 | self.failUnless( pimpatt == pactual.attributes, |
---|
1244 | 'test_Mesh2IOTriangulationDict failed. test 2.2') |
---|
1245 | self.failUnless( dict['segments'][0] == [0,1], |
---|
1246 | 'test_Mesh2IOTriangulationDict failed. test 3') |
---|
1247 | for segimp,segactual in map(None,dict['segment_tags'],seg): |
---|
1248 | self.failUnless( segimp == segactual.tag, |
---|
1249 | 'test_Mesh2IOTriangulationDict failed. test 4') |
---|
1250 | #print " dict['triangles'][0]", dict['triangles'][0] |
---|
1251 | self.failUnless( dict['triangles'][0] == [3,2,4], |
---|
1252 | 'test_Mesh2IOTriangulationDict failed. test 5') |
---|
1253 | self.failUnless( dict['triangle_neighbors'][0] == [-1,2,3], |
---|
1254 | 'test_Mesh2IOTriangulationDict failed. test 6') |
---|
1255 | self.failUnless( dict['triangle_tags'][0] == ["1.3"], |
---|
1256 | 'test_Mesh2IOTriangulationDict failed. test 7') |
---|
1257 | |
---|
1258 | |
---|
1259 | def test_Mesh2IODict(self): |
---|
1260 | |
---|
1261 | a_att = [5,2] |
---|
1262 | d_att =[4,2] |
---|
1263 | f_att = [3,2] |
---|
1264 | e_att = [2,2] |
---|
1265 | a_xy = [0.0, 0.0] |
---|
1266 | a = Vertex ( a_xy[0],a_xy[1] , attributes =a_att) |
---|
1267 | d = Vertex (0.0, 4.0 , attributes =d_att) |
---|
1268 | f = Vertex (4.0,0.0 , attributes =f_att) |
---|
1269 | e = Vertex (1.0,1.0 , attributes =e_att) |
---|
1270 | |
---|
1271 | s1 = Segment(a,d, tag = "50") |
---|
1272 | s2 = Segment(d,f, tag = "40") |
---|
1273 | s3 = Segment(a,f, tag = "30") |
---|
1274 | s4 = Segment(a,e, tag = "20") |
---|
1275 | |
---|
1276 | r1 = Region(0.3, 0.3,tag = "1.3", maxArea = 45) |
---|
1277 | m = Mesh(userVertices=[a,d,f,e], |
---|
1278 | userSegments=[s1,s2,s3,s4], |
---|
1279 | regions=[r1]) |
---|
1280 | titles = ['ele','friction'] |
---|
1281 | m.attributeTitles = titles |
---|
1282 | m.generateMesh("QApza2.1") |
---|
1283 | |
---|
1284 | seg = m.getMeshSegments() |
---|
1285 | verts = m.getMeshVertices() |
---|
1286 | dict = m.Mesh2IODict() |
---|
1287 | #print "dict",dict |
---|
1288 | |
---|
1289 | self.failUnless( dict['vertex_attribute_titles'] == titles, |
---|
1290 | 'test_Mesh2IOTriangulationDict failed. test 1') |
---|
1291 | answer = [a_xy,[0.0, 4.0],[4.0,0.0], [1.0,1.0], [2.0,2.0]] |
---|
1292 | #print "answer",answer |
---|
1293 | #print "dict['vertices']",dict['vertices'] |
---|
1294 | |
---|
1295 | self.failUnless( dict['vertices'] == answer, |
---|
1296 | 'test_Mesh2IOTriangulationDict failed. test 2') |
---|
1297 | |
---|
1298 | |
---|
1299 | for pimport,pactual,pimpatt in map(None,dict['vertices'], |
---|
1300 | verts,dict['vertex_attributes']): |
---|
1301 | #assert all_close( pimport, (pactual.x,pactual.y)) |
---|
1302 | self.failUnless( pimport == [pactual.x,pactual.y], |
---|
1303 | 'test_Mesh2IODict failed. test 2.1') |
---|
1304 | self.failUnless( pimpatt == pactual.attributes, |
---|
1305 | 'test_Mesh2IODict failed. test 2.2') |
---|
1306 | self.failUnless( dict['segments'][0] == [0,1], |
---|
1307 | 'test_Mesh2IODict failed. test 3') |
---|
1308 | for segimp,segactual in map(None,dict['segment_tags'],seg): |
---|
1309 | self.failUnless( segimp == segactual.tag, |
---|
1310 | 'test_Mesh2IODict failed. test 4') |
---|
1311 | #print " dict['triangles'][0]", dict['triangles'][0] |
---|
1312 | self.failUnless( dict['triangles'][0] == [3,2,4], |
---|
1313 | 'test_Mesh2IODict failed. test 5') |
---|
1314 | self.failUnless( dict['triangle_neighbors'][0] == [-1,2,3], |
---|
1315 | 'test_Mesh2IODict failed. test 6') |
---|
1316 | self.failUnless( dict['triangle_tags'][0] == ["1.3"], |
---|
1317 | 'test_Mesh2IODict failed. test 7') |
---|
1318 | |
---|
1319 | seg = m.getUserSegments() |
---|
1320 | points = m.getUserVertices() |
---|
1321 | holes = m.getHoles() |
---|
1322 | regions = m.getRegions() |
---|
1323 | |
---|
1324 | for pimport,pactual,pimpatt in map(None,dict['points'],points,dict['point_attributes']): |
---|
1325 | self.failUnless( pimport == [pactual.x,pactual.y], |
---|
1326 | 'test_Mesh2IODict failed. test 1') |
---|
1327 | self.failUnless( pimpatt == pactual.attributes, |
---|
1328 | 'test_Mesh2IODict failed. test 1.1') |
---|
1329 | self.failUnless( dict['outline_segments'][0] == [0,1], |
---|
1330 | 'test_Mesh2IODict failed. test 3') |
---|
1331 | for segimp,segactual in map(None,dict['outline_segment_tags'],seg): |
---|
1332 | self.failUnless( segimp == segactual.tag, |
---|
1333 | 'test_Mesh2IODict failed. test 4') |
---|
1334 | for holeimp,holeactual in map(None,dict['holes'],holes): |
---|
1335 | self.failUnless( holeimp == [holeactual.x,holeactual.y], |
---|
1336 | 'test_Mesh2IODict failed. test 5') |
---|
1337 | |
---|
1338 | for regimp,regactual,regattimp, regmaxarea in map(None,dict['regions'],regions, dict['region_tags'], dict['region_max_areas']): |
---|
1339 | self.failUnless( regimp == [regactual.x,regactual.y], |
---|
1340 | 'loadASCIITestCase failed. test 6') |
---|
1341 | self.failUnless( regattimp == regactual.getTag(), |
---|
1342 | 'loadASCIITestCase failed. test 7') |
---|
1343 | self.failUnless( regmaxarea == regactual.getMaxArea(), |
---|
1344 | 'loadASCIITestCase failed. test 7') |
---|
1345 | |
---|
1346 | |
---|
1347 | |
---|
1348 | def test_Mesh2IOOutlineDict(self): |
---|
1349 | |
---|
1350 | a_att = [5,2] |
---|
1351 | d_att =[4,2] |
---|
1352 | f_att = [3,2] |
---|
1353 | e_att = [2,2] |
---|
1354 | a_xy = [0.0, 0.0] |
---|
1355 | a = Vertex ( a_xy[0],a_xy[1] , attributes =a_att) |
---|
1356 | d = Vertex (0.0, 4.0 , attributes =d_att) |
---|
1357 | f = Vertex (4.0,0.0 , attributes =f_att) |
---|
1358 | e = Vertex (1.0,1.0 , attributes =e_att) |
---|
1359 | |
---|
1360 | s1 = Segment(a,d, tag = "50") |
---|
1361 | s2 = Segment(d,f, tag = "40") |
---|
1362 | s3 = Segment(a,f, tag = "30") |
---|
1363 | s4 = Segment(a,e, tag = "20") |
---|
1364 | |
---|
1365 | r1 = Region(0.3, 0.3,tag = "1.3", maxArea = 45) |
---|
1366 | m = Mesh(userVertices=[a,d,f,e], |
---|
1367 | userSegments=[s1,s2,s3,s4], |
---|
1368 | regions=[r1]) |
---|
1369 | titles = ['ele','friction'] |
---|
1370 | m.attributeTitles = titles |
---|
1371 | m.generateMesh("QApza2.1") |
---|
1372 | |
---|
1373 | seg = m.getMeshSegments() |
---|
1374 | verts = m.getMeshVertices() |
---|
1375 | dict = m.Mesh2IOOutlineDict() |
---|
1376 | |
---|
1377 | seg = m.getUserSegments() |
---|
1378 | points = m.getUserVertices() |
---|
1379 | holes = m.getHoles() |
---|
1380 | regions = m.getRegions() |
---|
1381 | |
---|
1382 | for pimport,pactual,pimpatt in map(None,dict['points'],points,dict['point_attributes']): |
---|
1383 | self.failUnless( pimport == [pactual.x,pactual.y], |
---|
1384 | 'loadASCIITestCase failed. test 1') |
---|
1385 | self.failUnless( pimpatt == pactual.attributes, |
---|
1386 | 'loadASCIITestCase failed. test 1.1') |
---|
1387 | self.failUnless( dict['outline_segments'][0] == [0,1], |
---|
1388 | 'loadASCIITestCase failed. test 3') |
---|
1389 | for segimp,segactual in map(None,dict['outline_segment_tags'],seg): |
---|
1390 | self.failUnless( segimp == segactual.tag, |
---|
1391 | 'loadASCIITestCase failed. test 4') |
---|
1392 | for holeimp,holeactual in map(None,dict['holes'],holes): |
---|
1393 | self.failUnless( holeimp == [holeactual.x,holeactual.y], |
---|
1394 | 'loadASCIITestCase failed. test 5') |
---|
1395 | #for regimp,regactual in map(None,dict['regions'],regions): |
---|
1396 | # self.failUnless( [regimp[0],regimp[1]]==[regactual.x,regactual.y], |
---|
1397 | # 'loadASCIITestCase failed. test 6') |
---|
1398 | # self.failUnless( regimp[2] == regactual.getTag(), |
---|
1399 | # 'loadASCIITestCase failed. test 7') |
---|
1400 | #self.failUnless( regimp[3] == regactual.getMaxArea(), |
---|
1401 | # 'loadASCIITestCase failed. test 7') |
---|
1402 | |
---|
1403 | |
---|
1404 | for regimp,regactual,regattimp, regmaxarea in map(None,dict['regions'],regions, dict['region_tags'], dict['region_max_areas']): |
---|
1405 | self.failUnless( regimp == [regactual.x,regactual.y], |
---|
1406 | 'loadASCIITestCase failed. test 6') |
---|
1407 | self.failUnless( regattimp == regactual.getTag(), |
---|
1408 | 'loadASCIITestCase failed. test 7') |
---|
1409 | self.failUnless( regmaxarea == regactual.getMaxArea(), |
---|
1410 | 'loadASCIITestCase failed. test 7') |
---|
1411 | |
---|
1412 | |
---|
1413 | #------------------------------------------------------------- |
---|
1414 | if __name__ == "__main__": |
---|
1415 | suite = unittest.makeSuite(meshTestCase,'test') |
---|
1416 | #suite = unittest.makeSuite(meshTestCase,'test_asciiFile') |
---|
1417 | runner = unittest.TextTestRunner() #verbosity=2) |
---|
1418 | runner.run(suite) |
---|
1419 | |
---|