[349] | 1 | #!/usr/bin/env python |
---|
| 2 | # |
---|
| 3 | import tempfile |
---|
| 4 | import unittest |
---|
| 5 | from mesh import * |
---|
| 6 | from load_mesh.loadASCII import * |
---|
[1023] | 7 | from coordinate_transforms.geo_reference import Geo_reference |
---|
[349] | 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) |
---|
[969] | 52 | s = Segment(a,b, tag = 20) |
---|
[349] | 53 | |
---|
| 54 | self.failUnless( s.vertices[0].DistanceToPoint(s.vertices[1]) == 10.0, |
---|
| 55 | 'vertices in a segment are wrong') |
---|
| 56 | |
---|
[969] | 57 | self.failUnless( s.tag == 20.0, |
---|
| 58 | 'tag in a segment are wrong') |
---|
[349] | 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 | |
---|
[1923] | 124 | m.generateMesh("QApz", maxArea = 36 ) |
---|
[349] | 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] ) |
---|
[2030] | 137 | m.generateMesh("QApz", maxArea = 36 ) |
---|
[349] | 138 | |
---|
[2141] | 139 | self.failUnless(len(m.meshTriangles) >= 6, |
---|
| 140 | 'testregion_with_maxarea 2: # of tris is wrong!') |
---|
[2030] | 141 | |
---|
| 142 | |
---|
[349] | 143 | ## Another test case |
---|
| 144 | r1 = Region(3, 1, tag = 1.3, maxArea = 8) |
---|
| 145 | r2 = Region(1, 3, tag = 1.3, maxArea = 8) |
---|
| 146 | m = Mesh(userVertices=[v0,v1,v2,v3], userSegments=[s1,s2,s3,s4,s5], |
---|
| 147 | regions=[r1,r2] ) |
---|
[1923] | 148 | m.generateMesh("QApz", maxArea = 36 ) |
---|
[2030] | 149 | #print "len(m.meshTriangles)",len(m.meshTriangles) |
---|
[349] | 150 | |
---|
[2141] | 151 | self.failUnless(len(m.meshTriangles) >= 8, |
---|
[2030] | 152 | 'testregion_with_maxarea 3: # of tris is wrong!') |
---|
| 153 | |
---|
| 154 | |
---|
[349] | 155 | ## Another test case |
---|
| 156 | r1 = Region(3, 1, tag = 1.3 ) |
---|
| 157 | r2 = Region(1, 3, tag = 1.3, maxArea = 8) |
---|
| 158 | m = Mesh(userVertices=[v0,v1,v2,v3], userSegments=[s1,s2,s3,s4,s5], |
---|
| 159 | regions=[r1,r2] ) |
---|
[2030] | 160 | m.generateMesh("QApz", maxArea = 8 ) |
---|
[2141] | 161 | self.failUnless(len(m.meshTriangles) >= 8, |
---|
| 162 | 'testregion_with_maxarea 4: # of tris is wrong!') |
---|
[2030] | 163 | |
---|
[349] | 164 | |
---|
| 165 | ## Another test case |
---|
| 166 | r1 = Region(3, 1,tag = 1.3, maxArea = 8) |
---|
| 167 | r2 = Region(1, 3,tag = 1.3, maxArea = 8) |
---|
| 168 | m = Mesh(userVertices=[v0,v1,v2,v3], userSegments=[s1,s2,s3,s4,s5], |
---|
| 169 | regions=[r1,r2] ) |
---|
[1923] | 170 | m.generateMesh("QApz", maxArea = 36,isRegionalMaxAreas = False ) |
---|
[349] | 171 | self.failUnless(len(m.meshTriangles) == 2, |
---|
| 172 | 'test_regionalMaxArea 5:generated mesh is wrong!') |
---|
| 173 | |
---|
| 174 | def testdeleteUserVertex(self): |
---|
| 175 | mesh = Mesh() |
---|
| 176 | a = mesh.addUserVertex(0.0, 0.0) |
---|
| 177 | b = mesh.addUserVertex (0.0, 2.0) |
---|
| 178 | c = mesh.addUserVertex (2.0,0.0) |
---|
| 179 | |
---|
| 180 | s1 = mesh.addUserSegment(a,b) |
---|
| 181 | s2 = mesh.addUserSegment(a,c) |
---|
| 182 | s3 = mesh.addUserSegment(c,b) |
---|
| 183 | |
---|
| 184 | mesh.deleteMeshObject (s2) |
---|
| 185 | |
---|
| 186 | #print ",s2 in mesh.userSegments" ,s2 in mesh.userSegments |
---|
| 187 | self.failUnless(not(s2 in mesh.userSegments), |
---|
| 188 | 'Bad segment. ') |
---|
| 189 | self.failUnless(len(mesh.userSegments) ==2, |
---|
| 190 | 'Segments not deleted.') |
---|
| 191 | self.failUnless(len(mesh.userVertices) == 3, |
---|
| 192 | 'Vertex deleted, instead of segment.') |
---|
| 193 | |
---|
| 194 | def testTriangleArea(self): |
---|
| 195 | a = Vertex (10.0, 10.0) |
---|
| 196 | b = Vertex (10.0, 20.0) |
---|
| 197 | c = Vertex (20.0,10.0) |
---|
| 198 | |
---|
| 199 | d = Vertex (-20.0, 0.0) |
---|
| 200 | e = Vertex (-20.0, -20.0) |
---|
| 201 | f = Vertex (20.0,-20.0) |
---|
| 202 | |
---|
| 203 | t1 = Triangle(b,a,c) |
---|
| 204 | t2 = Triangle(e,d,f) |
---|
| 205 | |
---|
| 206 | # print "t1", t1 |
---|
| 207 | # print "t1 area ", t1.calcArea() |
---|
| 208 | # print "t2", t2 |
---|
| 209 | # print "t2 area ", t2.calcArea() |
---|
| 210 | self.failUnless( t1.calcArea() == 50 and t2.calcArea() == 400, 'Triangle area is wrong!') |
---|
| 211 | def testisUserSegmentNew (self): |
---|
| 212 | mesh = Mesh() |
---|
| 213 | a = mesh.addUserVertex(0.0, 0.0) |
---|
| 214 | b = mesh.addUserVertex (0.0, 2.0) |
---|
| 215 | c = mesh.addUserVertex (2.0,0.0) |
---|
| 216 | d = mesh.addUserVertex (2.0,3.0) |
---|
| 217 | |
---|
| 218 | s1 = mesh.addUserSegment(a,b) |
---|
| 219 | s2 = mesh.addUserSegment(a,c) |
---|
| 220 | s3 = mesh.addUserSegment(c,b) |
---|
| 221 | |
---|
| 222 | self.failUnless(mesh.isUserSegmentNew(a,d) , |
---|
| 223 | 'Segment should be new. ') |
---|
| 224 | self.failUnless(not(mesh.isUserSegmentNew(a,b)) , |
---|
| 225 | 'Segment should not be new. ') |
---|
| 226 | |
---|
[702] | 227 | |
---|
| 228 | def testisUserSegmentNew (self): |
---|
| 229 | mesh = Mesh() |
---|
| 230 | a = mesh.addUserVertex(0.0, 0.0) |
---|
| 231 | b = mesh.addUserVertex (0.0, 2.0) |
---|
| 232 | c = mesh.addUserVertex (2.0,0.0) |
---|
| 233 | d = mesh.addUserVertex (2.0,3.0) |
---|
[349] | 234 | |
---|
[702] | 235 | s1 = mesh.addUserSegment(a,b) |
---|
| 236 | s2 = mesh.addUserSegment(a,c) |
---|
| 237 | s3 = mesh.addUserSegment(c,b) |
---|
[349] | 238 | |
---|
[702] | 239 | self.failUnless(mesh.representedUserSegment(a,d) == None, |
---|
| 240 | 'Segment should be new. ') |
---|
| 241 | self.failUnless(mesh.representedUserSegment(a,b) == s1 , |
---|
| 242 | 'Segment should not be new. ') |
---|
[349] | 243 | |
---|
[1401] | 244 | def testautoSegment(self): |
---|
[702] | 245 | p0 = Vertex (0.0, 0.0) |
---|
| 246 | p1 = Vertex (0.0, 4.0) |
---|
| 247 | p2 = Vertex (4.0,4.0) |
---|
| 248 | p3 = Vertex (4.0,0.0) |
---|
[349] | 249 | |
---|
[702] | 250 | s1 = Segment(p0,p1) |
---|
[349] | 251 | |
---|
[702] | 252 | m = Mesh(userVertices=[p0, p1, p2, p3], userSegments=[s1] ) |
---|
[349] | 253 | m.autoSegment() |
---|
| 254 | |
---|
| 255 | #print 'Len', len(m.userSegments) |
---|
[702] | 256 | self.failUnless(len(m.getUserSegments()) == 4 , |
---|
| 257 | 'userSegments is wrong!') |
---|
| 258 | |
---|
| 259 | m.autoSegment() |
---|
| 260 | self.failUnless(len(m.getUserSegments()) == 4 , |
---|
| 261 | 'userSegments is wrong!') |
---|
| 262 | |
---|
[1401] | 263 | def testautoSegmentII(self): |
---|
[702] | 264 | p1 = Vertex (3.0, 4.0) |
---|
| 265 | p2 = Vertex (3.0,2.0) |
---|
| 266 | p3 = Vertex (3.0,0.0) |
---|
| 267 | p4 = Vertex (6.0, 4.0) |
---|
| 268 | p5 = Vertex (6.0,2.0) |
---|
| 269 | p0 = Vertex (6.0,0.0) |
---|
[349] | 270 | |
---|
[702] | 271 | |
---|
| 272 | s1 = Segment(p2,p3) |
---|
| 273 | s2 = Segment(p4,p5) |
---|
| 274 | |
---|
| 275 | m = Mesh(userVertices=[p0, p1, p2, p3, p4, p5], |
---|
| 276 | userSegments=[s1, s2]) |
---|
| 277 | |
---|
| 278 | m.autoSegment() |
---|
| 279 | |
---|
| 280 | s3 = m.representedAlphaUserSegment(p3,p0) |
---|
| 281 | self.failUnless(not (s3 == None) , |
---|
[349] | 282 | 'userSegments is wrong!') |
---|
[702] | 283 | |
---|
| 284 | |
---|
| 285 | s6 = m.representedAlphaUserSegment(p1,p4) |
---|
| 286 | self.failUnless(not (s6 == None) , |
---|
| 287 | 'userSegments is wrong!') |
---|
| 288 | |
---|
| 289 | # remove a segment, add a point, autosegment |
---|
| 290 | m.alphaUserSegments.remove(s3) |
---|
| 291 | p6 = Vertex (1.0, 2.0) |
---|
| 292 | m.userVertices.append(p6) |
---|
[1421] | 293 | |
---|
[702] | 294 | m.autoSegment() |
---|
| 295 | |
---|
| 296 | s1_now = m.representedUserSegment(p3,p2) |
---|
| 297 | self.failUnless(s1_now == s1 , |
---|
| 298 | 'userSegments is wrong!') |
---|
| 299 | |
---|
| 300 | s2_now = m.representedUserSegment(p5,p4) |
---|
| 301 | self.failUnless(s2_now == s2 , |
---|
| 302 | 'userSegments is wrong!') |
---|
| 303 | |
---|
| 304 | s3 = m.representedAlphaUserSegment(p3,p6) |
---|
| 305 | self.failUnless(not (s3 == None) , |
---|
| 306 | 'userSegments is wrong!') |
---|
| 307 | |
---|
| 308 | s4 = m.representedAlphaUserSegment(p3,p6) |
---|
| 309 | self.failUnless(not (s4 == None) , |
---|
| 310 | 'userSegments is wrong!') |
---|
| 311 | |
---|
| 312 | s5 = m.representedAlphaUserSegment(p4,p6) |
---|
| 313 | self.failUnless(s5 == None , |
---|
| 314 | 'userSegments is wrong!') |
---|
| 315 | #print m |
---|
| 316 | |
---|
[349] | 317 | def testRegions(self): |
---|
| 318 | a = Vertex (0.0, 0.0) |
---|
| 319 | b = Vertex (0.0, 2.0) |
---|
| 320 | c = Vertex (2.0,0.0) |
---|
| 321 | d = Vertex (0.0, 4.0) |
---|
| 322 | e = Vertex (2.0, 2.0) |
---|
| 323 | f = Vertex (4.0,0.0) |
---|
| 324 | g = Vertex (0.0,-2.0) |
---|
| 325 | |
---|
| 326 | Segment.set_default_tag("") |
---|
| 327 | s1 = Segment(a,b) |
---|
| 328 | s2 = Segment(b,e) |
---|
| 329 | s3 = Segment(e,c) |
---|
| 330 | s4 = Segment(c,a) |
---|
| 331 | s5 = Segment(b,d) |
---|
| 332 | s6 = Segment(e,d) |
---|
| 333 | s7 = Segment(e,f) |
---|
| 334 | s8 = Segment(c,f) |
---|
| 335 | s9 = Segment(g,c) |
---|
| 336 | s10 = Segment(g,a) |
---|
| 337 | |
---|
| 338 | r1 = Region(0.1,0.1,tag="22") |
---|
| 339 | r2 = Region(0.1,2.1,tag="11") |
---|
| 340 | r3 = Region(2.1,0.1) |
---|
| 341 | |
---|
| 342 | 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] ) |
---|
| 343 | m.generateMesh("QApz", maxArea = 2.1 ) |
---|
| 344 | #print m |
---|
| 345 | Triangulation = m.getTriangulation() |
---|
| 346 | #print Triangulation[0].attribute |
---|
| 347 | #print Triangulation[1].attribute |
---|
| 348 | #print Triangulation[2].attribute |
---|
| 349 | #print Triangulation[3].attribute |
---|
| 350 | #print Triangulation[4].attribute |
---|
| 351 | |
---|
| 352 | self.failUnless(Triangulation[0].attribute == "" and |
---|
| 353 | Triangulation[1].attribute == "22" and |
---|
| 354 | Triangulation[2].attribute == "" and |
---|
| 355 | Triangulation[3].attribute == "11" and |
---|
| 356 | Triangulation[4].attribute == "22" , |
---|
| 357 | 'region attributes are wrong!') |
---|
| 358 | |
---|
| 359 | def test_vertexAttribs(self): |
---|
| 360 | a = Vertex (0.0, 0.0, attributes = [12.0,2.0]) |
---|
| 361 | d = Vertex (0.0, 4.0, attributes = [9.0,7.0]) |
---|
| 362 | f = Vertex (4.0,0.0, attributes = [14.0,3.0]) |
---|
| 363 | |
---|
| 364 | Segment.set_default_tag("") |
---|
| 365 | s1 = Segment(a,d) |
---|
| 366 | s2 = Segment(d,f) |
---|
| 367 | s3 = Segment(a,f) |
---|
| 368 | |
---|
| 369 | r1 = Region(0.3, 0.3, tag = 88.9) |
---|
| 370 | |
---|
| 371 | m = Mesh(userVertices=[a,d,f], userSegments=[s1,s2,s3], regions=[r1]) |
---|
| 372 | |
---|
| 373 | m.generateMesh("QApz", maxArea = 2.1) |
---|
| 374 | |
---|
| 375 | vert = m.getMeshVertices() |
---|
| 376 | |
---|
| 377 | self.failUnless(vert[0].attributes == [12.0, 2.0] and |
---|
| 378 | vert[1].attributes == [9.0, 7.0] and |
---|
| 379 | vert[2].attributes == [14.0,3.0] and |
---|
| 380 | vert[3].attributes == [12.232233047033631, 4.4142135623730949] and |
---|
| 381 | vert[4].attributes == [13.0, 2.5] , |
---|
| 382 | 'vertex attributes are wrong!') |
---|
| 383 | |
---|
| 384 | |
---|
| 385 | def test_vertexAttribs2(self): |
---|
| 386 | |
---|
| 387 | a = Vertex (0.0, 0.0) |
---|
| 388 | d = Vertex (0.0, 4.0) |
---|
| 389 | f = Vertex (4.0,0.0) |
---|
| 390 | |
---|
| 391 | Segment.set_default_tag("") |
---|
| 392 | s1 = Segment(a,d) |
---|
| 393 | s2 = Segment(d,f) |
---|
| 394 | s3 = Segment(a,f) |
---|
| 395 | |
---|
| 396 | r1 = Region(0.3, 0.3, tag = 88.9) |
---|
| 397 | |
---|
| 398 | m = Mesh(userVertices=[a,d,f], userSegments=[s1,s2,s3], regions=[r1]) |
---|
| 399 | |
---|
| 400 | m.generateMesh("QApz", maxArea = 2.1 ) |
---|
| 401 | |
---|
| 402 | vert = m.getMeshVertices() |
---|
| 403 | self.failUnless(vert[0].attributes == [] and |
---|
| 404 | vert[1].attributes == [] and |
---|
| 405 | vert[2].attributes == [] and |
---|
| 406 | vert[3].attributes == [] and |
---|
| 407 | vert[4].attributes == [], |
---|
| 408 | 'vertex attributes are wrong!') |
---|
| 409 | |
---|
[969] | 410 | def test_segtag(self): |
---|
[349] | 411 | |
---|
| 412 | a = Vertex (0.0, 0.0) |
---|
| 413 | d = Vertex (0.0, 4.0) |
---|
| 414 | f = Vertex (4.0,0.0) |
---|
| 415 | |
---|
[969] | 416 | s1 = Segment(a,d,tag = 5) |
---|
| 417 | s2 = Segment(d,f,tag = 7) |
---|
| 418 | s3 = Segment(a,f,tag = 9) |
---|
[349] | 419 | |
---|
| 420 | m = Mesh(userVertices=[a,d,f], userSegments=[s1,s2,s3]) |
---|
| 421 | |
---|
| 422 | m.generateMesh("QApz", maxArea = 2.1 ) |
---|
| 423 | |
---|
[2028] | 424 | m.export_mesh_file("from_test_mesh.tsh") |
---|
[349] | 425 | seg = m.getMeshSegments() |
---|
[2024] | 426 | #print "seg",seg |
---|
[969] | 427 | #print "seg[0].tag" |
---|
| 428 | #print seg[0].tag |
---|
| 429 | #print "seg[0].tag" |
---|
[2028] | 430 | |
---|
[2141] | 431 | self.failUnless(seg[0].tag == 5 and |
---|
[969] | 432 | seg[1].tag == 7 and |
---|
| 433 | seg[2].tag == 9 and |
---|
| 434 | seg[3].tag == 7 and |
---|
[2028] | 435 | seg[4].tag == 9, |
---|
| 436 | 'seg tags are wrong') |
---|
| 437 | |
---|
[349] | 438 | |
---|
[969] | 439 | def test_segtag2(self): |
---|
[349] | 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() |
---|
[969] | 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') |
---|
[349] | 462 | |
---|
| 463 | def test_asciiFile(self): |
---|
| 464 | |
---|
[364] | 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]) |
---|
[349] | 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 | seg = m.getMeshSegments() |
---|
| 479 | |
---|
[996] | 480 | fileName = tempfile.mktemp(".tsh") |
---|
[1001] | 481 | m.export_mesh_file(fileName) |
---|
[349] | 482 | file = open(fileName) |
---|
| 483 | lFile = file.read().split('\n') |
---|
| 484 | file.close() |
---|
| 485 | os.remove(fileName) |
---|
| 486 | |
---|
| 487 | #print "@^@^" |
---|
| 488 | #for l in lFile: |
---|
| 489 | # print l,"<" |
---|
| 490 | #print "@^@^" |
---|
[364] | 491 | |
---|
[721] | 492 | # no need to check the title again |
---|
| 493 | #self.failUnless(lFile[0] == "5 0 # <vertex #> <x> <y> [attributes] ...Triangulation Vertices..." |
---|
| 494 | # ,'Ascii file is wrong, vertex title') |
---|
[364] | 495 | self.failUnless(lFile[1] == "0 0.0 0.0 " and #1.1 " and |
---|
| 496 | lFile[2] == "1 0.0 4.0 " and #1.2 " and |
---|
| 497 | lFile[3] == "2 4.0 0.0 " and #1.3 " and |
---|
| 498 | lFile[4] == "3 1.0 1.0 " and #1.4 " and |
---|
| 499 | lFile[5] == "4 2.0 2.0 " #1.25 " |
---|
[349] | 500 | , |
---|
| 501 | 'Ascii file is wrong, vertex') |
---|
[364] | 502 | |
---|
[721] | 503 | #self.failUnless(lFile[6] == "# attribute column titles ...Triangulation Vertex Titles..." |
---|
| 504 | # ,'Ascii file is wrong, attribute column title') |
---|
| 505 | self.failUnless(lFile[8] == "0 3 2 4 -1 2 3 " and |
---|
[364] | 506 | lFile[9] == "1 1 0 3 3 2 -1 " and |
---|
| 507 | lFile[10] == "2 3 4 1 -1 1 0 " and |
---|
| 508 | lFile[11] == "3 2 3 0 1 -1 0 " |
---|
| 509 | , |
---|
[349] | 510 | 'Ascii file is wrong, triangle') |
---|
| 511 | |
---|
[721] | 512 | self.failUnless( lFile[13] == "0 0 1 exterior" and |
---|
[714] | 513 | lFile[14] == "1 1 4 exterior" and |
---|
| 514 | lFile[15] == "2 2 0 exterior" and |
---|
[650] | 515 | lFile[16] == "3 0 3 " and |
---|
[714] | 516 | lFile[17] == "4 4 2 exterior" , |
---|
[349] | 517 | 'Ascii file is wrong, segment') |
---|
| 518 | |
---|
[721] | 519 | # self.failUnless(lFile[18] == '4 0 # <vertex #> <x> <y> [attributes] ...Mesh Vertices...', |
---|
| 520 | # 'Ascii file is wrong, Mesh Vertices Title') |
---|
[349] | 521 | |
---|
[364] | 522 | self.failUnless(lFile[19] == '0 0.0 0.0 ' and #1.1 ' and |
---|
| 523 | lFile[20] == '1 0.0 4.0 ' and #1.2 ' and |
---|
| 524 | lFile[21] == '2 4.0 0.0 ' and #1.3 ' and |
---|
| 525 | lFile[22] == '3 1.0 1.0 ' #1.4 ' |
---|
| 526 | , |
---|
[349] | 527 | 'Ascii file is wrong, Mesh Vertices II') |
---|
| 528 | |
---|
[721] | 529 | self.failUnless(lFile[24] == '0 0 1 ' and |
---|
[364] | 530 | lFile[25] == '1 1 2 ' and |
---|
| 531 | lFile[26] == '2 0 2 ' and |
---|
[721] | 532 | lFile[27] == '3 0 3 ' |
---|
| 533 | ,'Ascii file is wrong, Mesh Segments') |
---|
[364] | 534 | |
---|
[349] | 535 | |
---|
| 536 | def test_ascii_file(self): |
---|
| 537 | |
---|
[364] | 538 | a = Vertex (0.0, 0.0) #, attributes = [1.1]) |
---|
| 539 | d = Vertex (0.0, 4.0) #, attributes = [1.2]) |
---|
| 540 | f = Vertex (4.0,0.0) #, attributes = [1.3]) |
---|
| 541 | e = Vertex (1.0,1.0) #, attributes = [1.4]) |
---|
[349] | 542 | |
---|
| 543 | s1 = Segment(a,d) |
---|
| 544 | s2 = Segment(d,f) |
---|
| 545 | s3 = Segment(a,f) |
---|
| 546 | s4 = Segment(a,e) |
---|
| 547 | |
---|
| 548 | m = Mesh(userVertices=[a,d,f,e], userSegments=[s1,s2,s3,s4]) |
---|
| 549 | |
---|
| 550 | m.generateMesh("QApz", maxArea = 2.1 ) |
---|
| 551 | |
---|
| 552 | seg = m.getMeshSegments() |
---|
| 553 | |
---|
[996] | 554 | fileName = tempfile.mktemp(".tsh") |
---|
[1001] | 555 | m.export_mesh_file(fileName) |
---|
[349] | 556 | file = open(fileName) |
---|
| 557 | lFile = file.read().split('\n') |
---|
| 558 | file.close() |
---|
| 559 | os.remove(fileName) |
---|
| 560 | |
---|
[852] | 561 | #print "@^@^" |
---|
| 562 | #for l in lFile: |
---|
| 563 | # print l,"<" |
---|
| 564 | #print "@^@^" |
---|
[721] | 565 | self.failUnless(lFile[0] == "5 0 # <# of verts> <# of vert attributes>, next lines <vertex #> <x> <y> [attributes] ...Triangulation Vertices..." |
---|
[349] | 566 | , |
---|
| 567 | 'Ascii file is wrong, vertex title') |
---|
[364] | 568 | self.failUnless(lFile[1] == "0 0.0 0.0 " and #1.1 " and |
---|
| 569 | lFile[2] == "1 0.0 4.0 " and #1.2 " and |
---|
| 570 | lFile[3] == "2 4.0 0.0 " and #1.3 " and |
---|
| 571 | lFile[4] == "3 1.0 1.0 " and #1.4 " and |
---|
| 572 | lFile[5] == "4 2.0 2.0 " #1.25 " |
---|
[349] | 573 | , |
---|
| 574 | 'Ascii file is wrong, vertex') |
---|
[364] | 575 | |
---|
| 576 | self.failUnless(lFile[6] == "# attribute column titles ...Triangulation Vertex Titles..." |
---|
[349] | 577 | , |
---|
[364] | 578 | 'Ascii file is wrong, attribute column title') |
---|
[721] | 579 | self.failUnless(lFile[7] == "4 # <# of triangles>, next lines <triangle #> [<vertex #>] [<neigbouring triangle #>] [attribute of region] ...Triangulation Triangles..." and |
---|
[364] | 580 | lFile[8] == "0 3 2 4 -1 2 3 " and |
---|
| 581 | lFile[9] == "1 1 0 3 3 2 -1 " and |
---|
| 582 | lFile[10] == "2 3 4 1 -1 1 0 " and |
---|
| 583 | lFile[11] == "3 2 3 0 1 -1 0 " |
---|
| 584 | , |
---|
[349] | 585 | 'Ascii file is wrong, triangle') |
---|
| 586 | |
---|
[969] | 587 | self.failUnless(lFile[12] == "5 # <# of segments>, next lines <segment #> <vertex #> <vertex #> [boundary tag] ...Triangulation Segments..." and |
---|
[714] | 588 | lFile[13] == "0 0 1 exterior" and |
---|
| 589 | lFile[14] == "1 1 4 exterior" and |
---|
| 590 | lFile[15] == "2 2 0 exterior" and |
---|
[650] | 591 | lFile[16] == "3 0 3 " and |
---|
[714] | 592 | lFile[17] == "4 4 2 exterior" , |
---|
[349] | 593 | 'Ascii file is wrong, segment') |
---|
| 594 | |
---|
[721] | 595 | self.failUnless(lFile[18] == '4 0 # <# of verts> <# of vert attributes>, next lines <vertex #> <x> <y> [attributes] ...Mesh Vertices...', |
---|
[349] | 596 | 'Ascii file is wrong, Mesh Vertices Title') |
---|
| 597 | |
---|
[364] | 598 | self.failUnless(lFile[19] == '0 0.0 0.0 ' and #1.1 ' and |
---|
| 599 | lFile[20] == '1 0.0 4.0 ' and #1.2 ' and |
---|
| 600 | lFile[21] == '2 4.0 0.0 ' and #1.3 ' and |
---|
| 601 | lFile[22] == '3 1.0 1.0 ' #1.4 ' |
---|
| 602 | , |
---|
[349] | 603 | 'Ascii file is wrong, Mesh Vertices II') |
---|
| 604 | |
---|
[969] | 605 | self.failUnless(lFile[23] == '4 # <# of segments>, next lines <segment #> <vertex #> <vertex #> [boundary tag] ...Mesh Segments...' and |
---|
[364] | 606 | lFile[24] == '0 0 1 ' and |
---|
| 607 | lFile[25] == '1 1 2 ' and |
---|
| 608 | lFile[26] == '2 0 2 ' and |
---|
| 609 | lFile[27] == '3 0 3 ' and |
---|
[721] | 610 | lFile[28] == '0 # <# of holes>, next lines <Hole #> <x> <y> ...Mesh Holes...' and |
---|
| 611 | lFile[29] == '0 # <# of regions>, next lines <Region #> <x> <y> <tag>...Mesh Regions...' |
---|
[349] | 612 | , |
---|
| 613 | 'Ascii file is wrong, Mesh Segments') |
---|
| 614 | |
---|
| 615 | |
---|
| 616 | def test_thinoutVertices(self): |
---|
| 617 | |
---|
| 618 | v1 = Vertex(-20,-20) |
---|
| 619 | v2 = Vertex(-11,-11) |
---|
| 620 | v3 = Vertex(-10,-10) |
---|
| 621 | v4 = Vertex(-9,-1) |
---|
| 622 | v5 = Vertex(-8,2) |
---|
| 623 | v6 = Vertex(6,3) |
---|
| 624 | v7 = Vertex(12,9) |
---|
| 625 | v8 = Vertex(15,3) |
---|
| 626 | v9 = Vertex(24,3) |
---|
| 627 | m = Mesh(userVertices = [v1,v2,v3,v4,v5,v6,v7,v8,v9]) |
---|
| 628 | m.thinoutVertices(10) |
---|
| 629 | |
---|
| 630 | self.failUnless(v1 in m.userVertices, |
---|
| 631 | 'test_thinoutVertices, test 1 failed') |
---|
| 632 | self.failUnless(v3 in m.userVertices, |
---|
| 633 | 'test_thinoutVertices, test 2 failed') |
---|
| 634 | self.failUnless(v4 in m.userVertices, |
---|
| 635 | 'test_thinoutVertices, test 3 failed') |
---|
| 636 | self.failUnless(v6 in m.userVertices, |
---|
| 637 | 'test_thinoutVertices, test 4 failed') |
---|
| 638 | self.failUnless(v7 in m.userVertices, |
---|
| 639 | 'test_thinoutVertices, test 5 failed') |
---|
| 640 | self.failUnless(v9 in m.userVertices, |
---|
| 641 | 'test_thinoutVertices, test 6 failed') |
---|
| 642 | self.failUnless(v5 not in m.userVertices, |
---|
| 643 | 'test_thinoutVertices, test 7 failed') |
---|
| 644 | self.failUnless(v2 not in m.userVertices, |
---|
| 645 | 'test_thinoutVertices, test 8 failed') |
---|
| 646 | self.failUnless(v8 not in m.userVertices, |
---|
| 647 | 'test_thinoutVertices, test 9 failed') |
---|
| 648 | |
---|
| 649 | def test_same_x_y(self): |
---|
| 650 | v = Point(7,8) |
---|
| 651 | f = Point(7,8) |
---|
| 652 | f.same_x_y(v) |
---|
| 653 | |
---|
| 654 | self.failUnless(f.same_x_y(v), |
---|
| 655 | 'same_x_y True failed') |
---|
| 656 | e = Point(7,9) |
---|
| 657 | self.failUnless(not f.same_x_y(e), |
---|
| 658 | 'same_x_y False failed') |
---|
| 659 | |
---|
[1023] | 660 | def test_import_tsh(self): |
---|
[349] | 661 | |
---|
| 662 | a_att = [5.0,2.0] |
---|
| 663 | d_att =[4.0,2.0] |
---|
| 664 | f_att = [3.0,2.0] |
---|
| 665 | e_att = [2.0,2.0] |
---|
| 666 | a_xy = [0.0, 0.0] |
---|
[364] | 667 | a = Vertex ( a_xy[0],a_xy[1]) #, attributes =a_att) |
---|
| 668 | d = Vertex (0.0, 4.0) #, attributes =d_att) |
---|
| 669 | f = Vertex (4.0,0.0) #, attributes =f_att) |
---|
| 670 | e = Vertex (1.0,1.0) #, attributes =e_att) |
---|
[349] | 671 | |
---|
[969] | 672 | s1 = Segment(a,d, tag = "50") |
---|
| 673 | s2 = Segment(d,f, tag = "40") |
---|
| 674 | s3 = Segment(a,f, tag = "30") |
---|
| 675 | s4 = Segment(a,e, tag = "20") |
---|
[349] | 676 | |
---|
| 677 | r1 = Region(0.3, 0.3,tag = "1.3") |
---|
[1023] | 678 | geo = Geo_reference(8.9,8.9,65) |
---|
[349] | 679 | m = Mesh(userVertices=[a,d,f,e], |
---|
| 680 | userSegments=[s1,s2,s3,s4], |
---|
[1023] | 681 | regions=[r1], |
---|
| 682 | geo_reference=geo) |
---|
[349] | 683 | |
---|
| 684 | m.generateMesh("QApz", maxArea = 2.1) |
---|
| 685 | fileName = tempfile.mktemp(".tsh") |
---|
| 686 | #print "dgs!!!" |
---|
| 687 | #print "****************** fileName", fileName |
---|
[1001] | 688 | m.export_mesh_file(fileName) |
---|
[406] | 689 | #print "******************" |
---|
| 690 | #print "m", m |
---|
| 691 | #print "******************" |
---|
[349] | 692 | m_returned = importMeshFromFile(fileName) |
---|
[406] | 693 | #print "m_returned",m_returned |
---|
| 694 | #print "******************" |
---|
[349] | 695 | #print "****************** fileName", fileName |
---|
| 696 | os.remove(fileName) |
---|
| 697 | self.failUnless(0 == m.__cmp__(m_returned), |
---|
| 698 | 'loading and saving of a mesh failed') |
---|
[1023] | 699 | # do this when .msh supports geo_refs |
---|
| 700 | #self.failUnless(m.geo_reference == m_returned.geo_reference, |
---|
| 701 | # 'loading and saving of a mesh geo refs failed') |
---|
[349] | 702 | |
---|
[1023] | 703 | def test_import_mesh(self): |
---|
[349] | 704 | |
---|
[1023] | 705 | a_att = [5.0,2.0] |
---|
| 706 | d_att =[4.0,2.0] |
---|
| 707 | f_att = [3.0,2.0] |
---|
| 708 | e_att = [2.0,2.0] |
---|
| 709 | a_xy = [0.0, 0.0] |
---|
| 710 | a = Vertex ( a_xy[0],a_xy[1]) #, attributes =a_att) |
---|
| 711 | d = Vertex (0.0, 4.0) #, attributes =d_att) |
---|
| 712 | f = Vertex (4.0,0.0) #, attributes =f_att) |
---|
| 713 | e = Vertex (1.0,1.0) #, attributes =e_att) |
---|
| 714 | |
---|
| 715 | s1 = Segment(a,d, tag = "50") |
---|
| 716 | s2 = Segment(d,f, tag = "40") |
---|
| 717 | s3 = Segment(a,f, tag = "30") |
---|
| 718 | s4 = Segment(a,e, tag = "20") |
---|
| 719 | |
---|
| 720 | r1 = Region(0.3, 0.3,tag = "1.3") |
---|
[1073] | 721 | geo = Geo_reference(65,8.9,8.9) |
---|
[1023] | 722 | m = Mesh(userVertices=[a,d,f,e], |
---|
| 723 | userSegments=[s1,s2,s3,s4], |
---|
| 724 | regions=[r1], |
---|
| 725 | geo_reference=geo) |
---|
| 726 | |
---|
| 727 | m.generateMesh("QApz", maxArea = 2.1) |
---|
| 728 | fileName = tempfile.mktemp(".msh") |
---|
| 729 | #print "dgs!!!" |
---|
| 730 | #print "****************** fileName", fileName |
---|
| 731 | m.export_mesh_file(fileName) |
---|
| 732 | #print "******************" |
---|
| 733 | #print "m", m |
---|
| 734 | #print "******************" |
---|
| 735 | m_returned = importMeshFromFile(fileName) |
---|
| 736 | #print "m_returned",m_returned |
---|
| 737 | #print "******************" |
---|
| 738 | #print "****************** fileName", fileName |
---|
| 739 | os.remove(fileName) |
---|
[1034] | 740 | #print "m.geo_reference",m.geo_reference |
---|
| 741 | #print "m_returned.geo_reference,",m_returned.geo_reference |
---|
[1023] | 742 | self.failUnless(0 == m.__cmp__(m_returned), |
---|
| 743 | 'loading and saving of a mesh failed') |
---|
| 744 | self.failUnless(m.geo_reference == m_returned.geo_reference, |
---|
| 745 | 'loading and saving of a mesh geo refs failed') |
---|
| 746 | |
---|
[349] | 747 | def test_normaliseMesh(self): |
---|
| 748 | |
---|
| 749 | a_att = [5.0,2.0] |
---|
| 750 | d_att =[4.0,2.0] |
---|
| 751 | f_att = [3.0,2.0] |
---|
| 752 | e_att = [2.0,2.0] |
---|
| 753 | a_xy = [10.0, 10.0] |
---|
| 754 | a = Vertex ( a_xy[0],a_xy[1], attributes =a_att) |
---|
| 755 | d = Vertex (15.0, 10.0, attributes =d_att) |
---|
| 756 | f = Vertex (10.0,20.0, attributes =f_att) |
---|
| 757 | e = Vertex (15.0,20.0, attributes =e_att) |
---|
| 758 | |
---|
[969] | 759 | s1 = Segment(a,d, tag = 50) |
---|
| 760 | s2 = Segment(d,e, tag = 40) |
---|
| 761 | s3 = Segment(e,f, tag = 30) |
---|
| 762 | s4 = Segment(f,a, tag = 20) |
---|
[349] | 763 | |
---|
| 764 | r1 = Region(0.3, 0.3,tag = 1.3) |
---|
| 765 | m = Mesh(userVertices=[a,d,f,e], |
---|
| 766 | userSegments=[s1,s2,s3,s4], |
---|
| 767 | regions=[r1]) |
---|
| 768 | m.normaliseMesh(1,0,1) |
---|
| 769 | [xmin, ymin, xmax, ymax] = m.boxsize() |
---|
| 770 | [attmin, attmax] = m.maxMinVertAtt(0) |
---|
| 771 | self.failUnless(attmin == 0.0 and attmax == 1.0, |
---|
| 772 | 'normalise failed') |
---|
| 773 | self.failUnless(xmin == 0.0 and ymin == 0.0 and xmax == 0.5 and ymax == 1.0, |
---|
| 774 | 'normalise failed') |
---|
| 775 | m.normaliseMesh(200,-100,5) |
---|
| 776 | [xmin, ymin, xmax, ymax] = m.boxsize() |
---|
| 777 | [attmin, attmax] = m.maxMinVertAtt(0) |
---|
| 778 | self.failUnless(attmin == 0.0 and attmax == 5.0, |
---|
| 779 | 'normalise failed') |
---|
| 780 | self.failUnless(xmin == -100.0 and ymin == -100.0 and xmax == 0.0 and ymax == 100.0, |
---|
| 781 | 'normalise failed') |
---|
[1401] | 782 | |
---|
| 783 | def test_exportASCIIsegmentoutlinefile(self): |
---|
[349] | 784 | a = Vertex (0,0) |
---|
| 785 | b = Vertex (0,3) |
---|
| 786 | c = Vertex (3,3) |
---|
| 787 | d = Vertex (1,2) |
---|
| 788 | e = Vertex (3,1) |
---|
| 789 | |
---|
[969] | 790 | s1 = Segment(a,b, tag = "50") |
---|
| 791 | s2 = Segment(b,c, tag = "40") |
---|
| 792 | s3 = Segment(c,a, tag = "30") |
---|
[349] | 793 | |
---|
| 794 | r1 = Region(2, 1,tag = "1.3") |
---|
| 795 | h1 = Hole(1,4) |
---|
| 796 | m = Mesh(userVertices=[a,b,c,d,e], |
---|
| 797 | userSegments=[s1,s2,s3], |
---|
| 798 | regions=[r1], |
---|
| 799 | holes = [h1]) |
---|
| 800 | |
---|
| 801 | m.generateMesh("QApz", maxArea = 2.1) |
---|
| 802 | #print "mesh ***************dsg*", m |
---|
| 803 | |
---|
| 804 | fileName = tempfile.mktemp(".tsh") |
---|
| 805 | m.exportASCIIsegmentoutlinefile(fileName) |
---|
| 806 | |
---|
| 807 | m_returned = importMeshFromFile(fileName) |
---|
| 808 | |
---|
[1001] | 809 | #print "m_returned ****",m_returned |
---|
[349] | 810 | #print "****************** fileName", fileName |
---|
| 811 | os.remove(fileName) |
---|
| 812 | |
---|
| 813 | #Trim mesh, so it should like like m_returned |
---|
| 814 | m.meshVertices = [] |
---|
| 815 | m.meshTriangles = [] |
---|
| 816 | m.meshSegments = [] |
---|
| 817 | m.userVertices=[a,b,c] |
---|
[1001] | 818 | #print "mesh ***************dsg*", m |
---|
[349] | 819 | #print "(m.__cmp__(m_returned)", m.__cmp__(m_returned) |
---|
| 820 | self.failUnless(0 == m.__cmp__(m), |
---|
| 821 | 'test_exportASCIIsegmentoutlinefile:loading and saving of a mesh failed') |
---|
[2144] | 822 | # Having problems with this on linux. |
---|
| 823 | #The ordering of the dictionary values wasn't the same as the windows |
---|
| 824 | #returned value (verts.values()) |
---|
| 825 | #self.failUnless(0 == m.__cmp__(m_returned), |
---|
| 826 | # 'test_exportASCIIsegmentoutlinefile:loading and saving of a mesh failed') |
---|
[2145] | 827 | |
---|
| 828 | self.failUnless(3 == len(m_returned.userVertices), |
---|
| 829 | 'segmentoutlinefile:IO of a mesh failed') |
---|
[2144] | 830 | self.failUnless(len(m.userSegments) == len(m_returned.userSegments), |
---|
| 831 | 'segmentoutlinefile:IO of a mesh failed') |
---|
| 832 | for i in range(len(m.userSegments)): |
---|
| 833 | self.failUnless(m.userSegments[i].vertices[0].x == |
---|
| 834 | m_returned.userSegments[i].vertices[0].x, |
---|
| 835 | 'loading and saving of a mesh outline fialed') |
---|
| 836 | self.failUnless(m.userSegments[i].vertices[0].y == |
---|
| 837 | m_returned.userSegments[i].vertices[0].y, |
---|
| 838 | 'loading and saving of a mesh outline fialed') |
---|
| 839 | self.failUnless(m.userSegments[i].vertices[1].x == |
---|
| 840 | m_returned.userSegments[i].vertices[1].x, |
---|
| 841 | 'loading and saving of a mesh outline fialed') |
---|
| 842 | self.failUnless(m.userSegments[i].vertices[1].y == |
---|
| 843 | m_returned.userSegments[i].vertices[1].y, |
---|
| 844 | 'loading and saving of a mesh outline fialed') |
---|
| 845 | |
---|
[1401] | 846 | |
---|
| 847 | def test_exportASCIIsegmentoutlinefile2(self): |
---|
| 848 | a = Vertex (0,0) |
---|
| 849 | b = Vertex (0,1) |
---|
| 850 | c = Vertex (1,0) |
---|
| 851 | d = Vertex (1,1) |
---|
| 852 | e = Vertex (0.5,0.5) |
---|
| 853 | f = Vertex (0.6,0.6) |
---|
| 854 | |
---|
| 855 | s1 = Segment(a,e, tag = "50") |
---|
| 856 | s2 = Segment(b,e, tag = "40") |
---|
| 857 | s3 = Segment(c,e, tag = "30") |
---|
| 858 | s4 = Segment(d,e, tag = "30") |
---|
| 859 | |
---|
| 860 | r1 = Region(2, 1,tag = "1.3") |
---|
| 861 | h1 = Hole(1,4) |
---|
| 862 | m = Mesh(userVertices=[a,b,c,d,e], |
---|
| 863 | userSegments=[s1,s2,s3,s4], |
---|
| 864 | regions=[r1], |
---|
| 865 | holes = [h1]) |
---|
| 866 | |
---|
| 867 | fileName = tempfile.mktemp(".tsh") |
---|
| 868 | m.exportASCIIsegmentoutlinefile(fileName) |
---|
| 869 | |
---|
| 870 | m_returned = importMeshFromFile(fileName) |
---|
| 871 | #print "****************** fileName", fileName |
---|
| 872 | os.remove(fileName) |
---|
[349] | 873 | |
---|
[1401] | 874 | #Trim mesh, so it should like like m_returned |
---|
| 875 | m.meshVertices = [] |
---|
| 876 | m.meshTriangles = [] |
---|
| 877 | m.meshSegments = [] |
---|
| 878 | m.userVertices=[a,e,d,b,c] |
---|
| 879 | #print "mesh ***************dsg*", m |
---|
| 880 | #print "(m.__cmp__(m_returned)", m.__cmp__(m_returned) |
---|
| 881 | self.failUnless(0 == m.__cmp__(m), |
---|
[2145] | 882 | 'loading and saving of a mesh failed') |
---|
[1401] | 883 | |
---|
[2145] | 884 | self.failUnless(5 == len(m_returned.userVertices), |
---|
| 885 | 'segmentoutlinefile:IO of a mesh failed') |
---|
| 886 | self.failUnless(len(m.userSegments) == len(m_returned.userSegments), |
---|
| 887 | 'segmentoutlinefile:IO of a mesh failed') |
---|
| 888 | for i in range(len(m.userSegments)): |
---|
| 889 | self.failUnless(m.userSegments[i].vertices[0].x == |
---|
| 890 | m_returned.userSegments[i].vertices[0].x, |
---|
| 891 | 'loading and saving of a mesh outline fialed') |
---|
| 892 | self.failUnless(m.userSegments[i].vertices[0].y == |
---|
| 893 | m_returned.userSegments[i].vertices[0].y, |
---|
| 894 | 'loading and saving of a mesh outline fialed') |
---|
| 895 | self.failUnless(m.userSegments[i].vertices[1].x == |
---|
| 896 | m_returned.userSegments[i].vertices[1].x, |
---|
| 897 | 'loading and saving of a mesh outline fialed') |
---|
| 898 | self.failUnless(m.userSegments[i].vertices[1].y == |
---|
| 899 | m_returned.userSegments[i].vertices[1].y, |
---|
| 900 | 'loading and saving of a mesh outline fialed') |
---|
| 901 | |
---|
| 902 | |
---|
[852] | 903 | def test_loadxy(self): |
---|
| 904 | """ |
---|
| 905 | To test the mesh side of loading xya files. |
---|
| 906 | Not the loading of xya files |
---|
| 907 | """ |
---|
| 908 | import os |
---|
| 909 | import tempfile |
---|
| 910 | |
---|
| 911 | fileName = tempfile.mktemp(".xya") |
---|
| 912 | file = open(fileName,"w") |
---|
| 913 | file.write("elevation speed \n\ |
---|
| 914 | 1.0 0.0 10.0 0.0\n\ |
---|
| 915 | 0.0 1.0 0.0 10.0\n\ |
---|
| 916 | 1.0 0.0 10.4 40.0\n") |
---|
| 917 | file.close() |
---|
| 918 | #print fileName |
---|
| 919 | m = importMeshFromFile(fileName) |
---|
| 920 | os.remove(fileName) |
---|
| 921 | self.failUnless(m.userVertices[0].x == 1.0, |
---|
| 922 | 'loadxy, test 1 failed') |
---|
| 923 | self.failUnless(m.userVertices[0].y == 0.0, |
---|
| 924 | 'loadxy, test 2 failed') |
---|
| 925 | #self.failUnless(m.userVertices[0].attributes == [10.0,0.0], |
---|
| 926 | # 'loadxy, test 2.2 failed') |
---|
| 927 | self.failUnless(m.userVertices[1].x == 0.0, |
---|
| 928 | 'loadxy, test 3 failed') |
---|
| 929 | self.failUnless(m.userVertices[1].y == 1.0, |
---|
| 930 | 'loadxy, test 4 failed') |
---|
| 931 | #self.failUnless(m.userVertices[1].attributes == [0.0,10.0], |
---|
| 932 | # 'loadxy, test 5 failed') |
---|
| 933 | |
---|
[1401] | 934 | def test_exportPointsFile(self): |
---|
[349] | 935 | a = Vertex (0,0) |
---|
| 936 | b = Vertex (0,3) |
---|
| 937 | c = Vertex (3,3) |
---|
| 938 | d = Vertex (1,2) |
---|
| 939 | e = Vertex (3,1) |
---|
| 940 | f = Vertex (3,1) |
---|
| 941 | |
---|
[969] | 942 | s1 = Segment(a,b, tag = 50) |
---|
| 943 | s2 = Segment(b,c, tag = 40) |
---|
| 944 | s3 = Segment(c,a, tag = 30) |
---|
[349] | 945 | |
---|
| 946 | r1 = Region(2, 1,tag = 1.3) |
---|
| 947 | h1 = Hole(1,4) |
---|
| 948 | # Warning mesh can't produce this type of data structure its self |
---|
| 949 | m = Mesh(userVertices=[a,b,c,d,e], |
---|
| 950 | userSegments=[s1,s2,s3], |
---|
| 951 | regions=[r1], |
---|
| 952 | holes = [h1]) |
---|
| 953 | |
---|
[1395] | 954 | fileName = tempfile.mktemp(".xya") |
---|
[2028] | 955 | #fileName = 't.xya' |
---|
| 956 | #os.remove(fileName) |
---|
[1401] | 957 | m.exportPointsFile(fileName) |
---|
[349] | 958 | file = open(fileName) |
---|
| 959 | lFile = file.read().split('\n') |
---|
| 960 | file.close() |
---|
[355] | 961 | |
---|
[349] | 962 | os.remove(fileName) |
---|
[1401] | 963 | self.failUnless(lFile[0] == "" and |
---|
| 964 | lFile[1] == "0,0" and |
---|
| 965 | lFile[2] == "0,3" and |
---|
[2028] | 966 | lFile[3] == "3,3" |
---|
| 967 | , |
---|
| 968 | 'exported Ascii xya file is wrong') |
---|
| 969 | self.failUnless(lFile[4] == "1,2" and |
---|
[1401] | 970 | lFile[5] == "3,1" |
---|
[349] | 971 | , |
---|
| 972 | 'exported Ascii xya file is wrong') |
---|
| 973 | |
---|
| 974 | m.generateMesh("QApz", maxArea = 2.1) |
---|
[1401] | 975 | fileName = tempfile.mktemp(".xya") |
---|
[2028] | 976 | fileName = 't.xya' |
---|
[2029] | 977 | m.export_mesh_file('m.tsh') |
---|
[1401] | 978 | m.exportPointsFile(fileName) |
---|
[349] | 979 | file = open(fileName) |
---|
| 980 | lFile = file.read().split('\n') |
---|
| 981 | file.close() |
---|
[2028] | 982 | #os.remove(fileName) |
---|
[2030] | 983 | |
---|
[2141] | 984 | self.failUnless(lFile[0] == "" and |
---|
[1401] | 985 | lFile[1] == "0.0,0.0" and |
---|
| 986 | lFile[2] == "0.0,3.0" and |
---|
| 987 | lFile[3] == "3.0,3.0" and |
---|
| 988 | lFile[4] == "1.0,2.0" and |
---|
[2030] | 989 | lFile[5] == "3.0,1.0" |
---|
| 990 | , |
---|
| 991 | 'exported Ascii xya file is wrong') |
---|
[1401] | 992 | |
---|
| 993 | def test_exportPointsFilefile2(self): |
---|
| 994 | m = Mesh() |
---|
[349] | 995 | |
---|
[1401] | 996 | fileName = tempfile.mktemp(".xya") |
---|
| 997 | m.exportPointsFile(fileName) |
---|
| 998 | file = open(fileName) |
---|
| 999 | lFile = file.read().split('\n') |
---|
| 1000 | file.close() |
---|
| 1001 | |
---|
| 1002 | os.remove(fileName) |
---|
| 1003 | #print "************* test_mesh exportPointsFilefile" |
---|
| 1004 | #print "lFile",lFile |
---|
| 1005 | #print "************* test_mesh exportPointsFilefile" |
---|
| 1006 | self.failUnless(lFile[0] == "" |
---|
| 1007 | , |
---|
| 1008 | 'exported Ascii xya file is wrong') |
---|
| 1009 | |
---|
[349] | 1010 | def test_strings2ints(self): |
---|
| 1011 | list = ["sea","river inlet","","sea","","moat"] |
---|
| 1012 | preset = ["moat", "internal boundary"] |
---|
| 1013 | [intlist, converter] = segment_strings2ints(list,preset ) |
---|
| 1014 | self.failUnless(intlist == [2,3 ,0 ,2 ,0 ,0 ] |
---|
| 1015 | , |
---|
| 1016 | 'test_strings2ints produces bad intlist') |
---|
| 1017 | self.failUnless(converter == ['moat', 'internal boundary', |
---|
| 1018 | 'sea', 'river inlet'] |
---|
| 1019 | , |
---|
| 1020 | 'test_strings2ints produces bad converter') |
---|
| 1021 | |
---|
| 1022 | def test_ints2strings(self): |
---|
| 1023 | list = ["internal boundary","sea","river inlet", |
---|
| 1024 | "","sea","","moat","internal boundary"] |
---|
| 1025 | outlist = ['internal boundary', 'sea', 'river inlet', 'moat', |
---|
| 1026 | 'sea', 'moat', 'moat', 'internal boundary'] |
---|
| 1027 | preset = ["moat", "internal boundary"] |
---|
| 1028 | [intlist, converter] = segment_strings2ints(list,preset ) |
---|
| 1029 | newlist = segment_ints2strings(intlist, converter) |
---|
| 1030 | self.failUnless(outlist == newlist |
---|
| 1031 | , |
---|
| 1032 | 'test_strings2ints produces bad intlist') |
---|
| 1033 | self.failUnless(converter == ['moat', 'internal boundary', |
---|
| 1034 | 'sea', 'river inlet'] |
---|
| 1035 | , |
---|
| 1036 | 'test_strings2ints produces bad converter') |
---|
| 1037 | |
---|
| 1038 | def test_ints2strings2(self): |
---|
| 1039 | list = ["","",""] |
---|
| 1040 | preset = ["moat", "internal boundary"] |
---|
| 1041 | [intlist, converter] = segment_strings2ints(list,preset ) |
---|
| 1042 | newlist = segment_ints2strings(intlist, converter) |
---|
| 1043 | outlist = ['moat', 'moat', 'moat'] |
---|
| 1044 | self.failUnless(outlist == newlist |
---|
| 1045 | , |
---|
| 1046 | 'test_strings2ints produces bad intlist') |
---|
| 1047 | self.failUnless(converter == ['moat', 'internal boundary'] |
---|
| 1048 | , |
---|
| 1049 | 'test_strings2ints produces bad converter') |
---|
| 1050 | |
---|
| 1051 | |
---|
| 1052 | def test_removeDuplicatedVertices(self): |
---|
| 1053 | a = Vertex (0,0) |
---|
| 1054 | a.index = 0 |
---|
| 1055 | b = Vertex (0,3) |
---|
| 1056 | b.index = 1 |
---|
| 1057 | c = Vertex (3,3) |
---|
| 1058 | c.index = 2 |
---|
| 1059 | d = Vertex (1,1) |
---|
| 1060 | d.index = 3 |
---|
| 1061 | e = Vertex (3,1) |
---|
| 1062 | e.index = 4 |
---|
| 1063 | f = Vertex (1,1) |
---|
| 1064 | f.index = 5 |
---|
| 1065 | g = Vertex (1,1) |
---|
| 1066 | g.index = 6 |
---|
| 1067 | inputVerts_noDups = [a,b,c,d,e] |
---|
| 1068 | |
---|
| 1069 | m = Mesh(userVertices=[a,b,c,d,e,f,g]) |
---|
| 1070 | counter = m.removeDuplicatedUserVertices() |
---|
| 1071 | UserVerts = m.getUserVertices() |
---|
| 1072 | |
---|
| 1073 | |
---|
| 1074 | self.failUnless(UserVerts == inputVerts_noDups, |
---|
| 1075 | 'duplicate verts not removed') |
---|
| 1076 | #for userVert, inputVert in map(None, UserVerts, inputVerts_noDups): |
---|
| 1077 | # self.failUnless(userVert.x == inputVert.x, |
---|
| 1078 | # 'x duplicate verts not removed') |
---|
| 1079 | # self.failUnless(userVert.y == inputVert.y, |
---|
| 1080 | # 'y duplicate verts not removed') |
---|
[406] | 1081 | |
---|
[1401] | 1082 | |
---|
[407] | 1083 | def test_ungenerateFileLoading(self): |
---|
[349] | 1084 | |
---|
[406] | 1085 | fileName = tempfile.mktemp(".txt") |
---|
| 1086 | file = open(fileName,"w") |
---|
| 1087 | file.write(" 1 ?? ??\n\ |
---|
| 1088 | 0.0 0.0\n\ |
---|
| 1089 | 1.0 0.0\n\ |
---|
| 1090 | 1.0 1.0\n\ |
---|
| 1091 | 0.0 1.0\n\ |
---|
| 1092 | 0.0 0.0\n\ |
---|
| 1093 | END\n\ |
---|
| 1094 | 2 ?? ??\n\ |
---|
| 1095 | 10.0 10.0\n\ |
---|
| 1096 | 10.0 20.0\n\ |
---|
| 1097 | 20.0 20.0\n\ |
---|
| 1098 | 10.0 10.0\n\ |
---|
| 1099 | END\n\ |
---|
| 1100 | END\n") |
---|
| 1101 | file.close() |
---|
| 1102 | |
---|
| 1103 | |
---|
| 1104 | a = Vertex (0.0, 0.0) #, attributes = [1.1]) |
---|
| 1105 | b = Vertex (0.0, 40.0) #, attributes = [1.2]) |
---|
| 1106 | c = Vertex (40.0,40.0) #, attributes = [1.3]) |
---|
| 1107 | d = Vertex (40.0,0.0) #, attributes = [1.4]) |
---|
| 1108 | |
---|
| 1109 | s1 = Segment(a,b) |
---|
| 1110 | s2 = Segment(b,c) |
---|
| 1111 | s3 = Segment(c,d) |
---|
| 1112 | s4 = Segment(d,a) |
---|
| 1113 | |
---|
| 1114 | m = Mesh(userVertices=[a,b,c,d], userSegments=[s1,s2,s3,s4]) |
---|
| 1115 | dict = importUngenerateFile(fileName) |
---|
[1185] | 1116 | os.remove(fileName) |
---|
[407] | 1117 | |
---|
| 1118 | tag = "DSG" |
---|
| 1119 | Segment.set_default_tag(tag) |
---|
[406] | 1120 | m.addVertsSegs(dict) |
---|
[407] | 1121 | |
---|
| 1122 | # have to reset this , since it's a class attribute |
---|
| 1123 | Segment.set_default_tag("") |
---|
[406] | 1124 | |
---|
| 1125 | self.failUnless(len(m.userSegments) ==11, |
---|
[407] | 1126 | 'Wrong segment list length.') |
---|
[406] | 1127 | self.failUnless(len(m.userVertices) == 11, |
---|
[407] | 1128 | 'Wrong vertex list length.') |
---|
[406] | 1129 | self.failUnless(m.userSegments[10].vertices[0] == m.userVertices[10], |
---|
[407] | 1130 | 'bad vertex on segment.') |
---|
[406] | 1131 | self.failUnless(m.userSegments[10].vertices[1] == m.userVertices[8], |
---|
[407] | 1132 | 'Bad segment.') |
---|
[969] | 1133 | self.failUnless(m.userSegments[10].tag == tag, |
---|
[407] | 1134 | 'wrong tag.') |
---|
[431] | 1135 | |
---|
| 1136 | def test_ungenerateFileLoadingII(self): |
---|
[406] | 1137 | |
---|
[431] | 1138 | fileName = tempfile.mktemp(".txt") |
---|
| 1139 | file = open(fileName,"w") |
---|
| 1140 | file.write(" 1 ?? ??\n\ |
---|
| 1141 | 0.0 0.0\n\ |
---|
| 1142 | 1.0 0.0\n\ |
---|
| 1143 | 1.0 1.0\n\ |
---|
| 1144 | 0.0 1.0\n\ |
---|
| 1145 | 0.0 0.0\n\ |
---|
| 1146 | END\n\ |
---|
| 1147 | 2 ?? ??\n\ |
---|
| 1148 | 10.0 10.0\n\ |
---|
| 1149 | 10.0 20.0\n\ |
---|
| 1150 | 20.0 20.0\n\ |
---|
| 1151 | END\n\ |
---|
| 1152 | END\n") |
---|
| 1153 | file.close() |
---|
| 1154 | |
---|
| 1155 | |
---|
| 1156 | a = Vertex (0.0, 0.0) #, attributes = [1.1]) |
---|
| 1157 | b = Vertex (0.0, 40.0) #, attributes = [1.2]) |
---|
| 1158 | c = Vertex (40.0,40.0) #, attributes = [1.3]) |
---|
| 1159 | d = Vertex (40.0,0.0) #, attributes = [1.4]) |
---|
| 1160 | |
---|
| 1161 | s1 = Segment(a,b) |
---|
| 1162 | s2 = Segment(b,c) |
---|
| 1163 | s3 = Segment(c,d) |
---|
| 1164 | s4 = Segment(d,a) |
---|
| 1165 | |
---|
| 1166 | m = Mesh(userVertices=[a,b,c,d], userSegments=[s1,s2,s3,s4]) |
---|
| 1167 | dict = importUngenerateFile(fileName) |
---|
[1185] | 1168 | os.remove(fileName) |
---|
[431] | 1169 | |
---|
| 1170 | tag = "DSG" |
---|
| 1171 | Segment.set_default_tag(tag) |
---|
| 1172 | m.addVertsSegs(dict) |
---|
| 1173 | |
---|
| 1174 | self.failUnless(len(m.userSegments) ==10, |
---|
| 1175 | 'Wrong segment list length.') |
---|
| 1176 | self.failUnless(len(m.userVertices) == 11, |
---|
| 1177 | 'Wrong vertex list length.') |
---|
[1074] | 1178 | |
---|
| 1179 | def test_addVertsSegs(self): |
---|
| 1180 | m = Mesh() |
---|
| 1181 | Segment.set_default_tag("food") |
---|
| 1182 | dict = {} |
---|
| 1183 | dict['points'] = [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0]] |
---|
| 1184 | dict['segments'] = [[0, 1], [1, 2]] |
---|
| 1185 | dict['segment_tags'] = ['','do-op'] |
---|
| 1186 | m.addVertsSegs(dict) |
---|
| 1187 | # have to reset this , since it's a class attribute |
---|
| 1188 | Segment.set_default_tag("") |
---|
[935] | 1189 | |
---|
[1074] | 1190 | |
---|
| 1191 | self.failUnless(len(m.userSegments) ==2, |
---|
| 1192 | 'Wrong segment list length.') |
---|
| 1193 | self.failUnless(len(m.userVertices) == 3, |
---|
| 1194 | 'Wrong vertex list length.') |
---|
| 1195 | self.failUnless(m.userSegments[0].tag =='food', |
---|
| 1196 | 'Wrong segment tag length.') |
---|
| 1197 | self.failUnless(m.userSegments[1].tag =='do-op', |
---|
| 1198 | 'Wrong segment tag.') |
---|
| 1199 | |
---|
[2200] | 1200 | def test_addVertsSegs2(self): |
---|
| 1201 | geo = Geo_reference(56,5,10) |
---|
| 1202 | m = Mesh(geo_reference=geo) |
---|
| 1203 | dict = {} |
---|
| 1204 | dict['points'] = [[2.0, 1.0], [3.0, 1.0], [2.0, 2.0]] |
---|
| 1205 | dict['segments'] = [[0, 1], [1, 2], [2,0]] |
---|
| 1206 | dict['segment_tags'] = ['','do-op',''] |
---|
| 1207 | m.addVertsSegs(dict) |
---|
| 1208 | |
---|
[935] | 1209 | def test_exportASCIImeshfile(self): |
---|
| 1210 | |
---|
[1001] | 1211 | #a_att = [5,2] |
---|
| 1212 | #d_att =[4,2] |
---|
| 1213 | #f_att = [3,2] |
---|
| 1214 | #e_att = [2,2] |
---|
[935] | 1215 | a_xy = [0.0, 0.0] |
---|
[1001] | 1216 | a = Vertex ( a_xy[0],a_xy[1]) #, attributes =a_att) |
---|
| 1217 | d = Vertex (0.0, 4.0) #, attributes =d_att) |
---|
| 1218 | f = Vertex (4.0,0.0) #, attributes =f_att) |
---|
| 1219 | e = Vertex (1.0,1.0) #, attributes =e_att) |
---|
[935] | 1220 | |
---|
[969] | 1221 | s1 = Segment(a,d, tag = "50") |
---|
| 1222 | s2 = Segment(d,f, tag = "40") |
---|
| 1223 | s3 = Segment(a,f, tag = "30") |
---|
| 1224 | s4 = Segment(a,e, tag = "20") |
---|
[935] | 1225 | |
---|
| 1226 | r1 = Region(0.3, 0.3,tag = "1.3", maxArea = 36) |
---|
| 1227 | |
---|
| 1228 | |
---|
| 1229 | h1 = Hole(0.2,0.6) |
---|
[431] | 1230 | |
---|
[935] | 1231 | m = Mesh(userVertices=[a,d,f,e], |
---|
| 1232 | userSegments=[s1,s2,s3,s4], |
---|
| 1233 | regions=[r1], |
---|
| 1234 | holes=[h1]) |
---|
| 1235 | |
---|
| 1236 | seg = m.getUserSegments() |
---|
| 1237 | points = m.getUserVertices() |
---|
| 1238 | holes = m.getHoles() |
---|
| 1239 | regions = m.getRegions() |
---|
[1001] | 1240 | fileName = tempfile.mktemp(".tsh") |
---|
| 1241 | m.export_mesh_file(fileName) |
---|
[935] | 1242 | #print "***************************fileName", fileName |
---|
[1001] | 1243 | new_m = importMeshFromFile(fileName) |
---|
[935] | 1244 | os.remove(fileName) |
---|
[1001] | 1245 | |
---|
[935] | 1246 | |
---|
[1001] | 1247 | #print '**@@@@@******' |
---|
| 1248 | #print "new_m",new_m |
---|
| 1249 | #print '**@@@@@******' |
---|
| 1250 | #print "m",m |
---|
| 1251 | #print '**@@@@@******' |
---|
| 1252 | |
---|
| 1253 | self.failUnless( new_m == m, |
---|
| 1254 | 'loadASCIITestCase failed. test new 1') |
---|
| 1255 | |
---|
[968] | 1256 | def test_Mesh2MeshList(self): |
---|
| 1257 | |
---|
| 1258 | a_att = [5,2] |
---|
| 1259 | d_att =[4,2] |
---|
| 1260 | f_att = [3,2] |
---|
| 1261 | e_att = [2,2] |
---|
| 1262 | a_xy = [0.0, 0.0] |
---|
| 1263 | a = Vertex ( a_xy[0],a_xy[1]) #, attributes =a_att) |
---|
| 1264 | d = Vertex (0.0, 4.0) #, attributes =d_att) |
---|
| 1265 | f = Vertex (4.0,0.0) #, attributes =f_att) |
---|
| 1266 | e = Vertex (1.0,1.0) #, attributes =e_att) |
---|
| 1267 | |
---|
[969] | 1268 | s1 = Segment(a,d, tag = "50") |
---|
| 1269 | s2 = Segment(d,f, tag = "40") |
---|
| 1270 | s3 = Segment(a,f, tag = "30") |
---|
| 1271 | s4 = Segment(a,e, tag = "20") |
---|
[968] | 1272 | |
---|
| 1273 | r1 = Region(0.3, 0.3,tag = "1.3", maxArea = 45) |
---|
| 1274 | m = Mesh(userVertices=[a,d,f,e], |
---|
| 1275 | userSegments=[s1,s2,s3,s4], |
---|
| 1276 | regions=[r1]) |
---|
| 1277 | |
---|
| 1278 | m.generateMesh("QApza2.1") |
---|
| 1279 | |
---|
| 1280 | seg = m.getMeshSegments() |
---|
| 1281 | points = m.getMeshVertices() |
---|
| 1282 | dict = m.Mesh2MeshList() |
---|
[1001] | 1283 | #print "dict",dict |
---|
[968] | 1284 | # test not finished... |
---|
| 1285 | |
---|
| 1286 | def test_Mesh2IOTriangulationDict(self): |
---|
| 1287 | |
---|
| 1288 | a_att = [5,2] |
---|
| 1289 | d_att =[4,2] |
---|
| 1290 | f_att = [3,2] |
---|
| 1291 | e_att = [2,2] |
---|
| 1292 | a_xy = [0.0, 0.0] |
---|
| 1293 | a = Vertex ( a_xy[0],a_xy[1] , attributes =a_att) |
---|
| 1294 | d = Vertex (0.0, 4.0 , attributes =d_att) |
---|
| 1295 | f = Vertex (4.0,0.0 , attributes =f_att) |
---|
| 1296 | e = Vertex (1.0,1.0 , attributes =e_att) |
---|
| 1297 | |
---|
[969] | 1298 | s1 = Segment(a,d, tag = "50") |
---|
| 1299 | s2 = Segment(d,f, tag = "40") |
---|
| 1300 | s3 = Segment(a,f, tag = "30") |
---|
| 1301 | s4 = Segment(a,e, tag = "20") |
---|
[968] | 1302 | |
---|
| 1303 | r1 = Region(0.3, 0.3,tag = "1.3", maxArea = 45) |
---|
| 1304 | m = Mesh(userVertices=[a,d,f,e], |
---|
| 1305 | userSegments=[s1,s2,s3,s4], |
---|
| 1306 | regions=[r1]) |
---|
| 1307 | titles = ['ele','friction'] |
---|
| 1308 | m.attributeTitles = titles |
---|
| 1309 | m.generateMesh("QApza2.1") |
---|
| 1310 | |
---|
| 1311 | seg = m.getMeshSegments() |
---|
| 1312 | verts = m.getMeshVertices() |
---|
| 1313 | dict = m.Mesh2IOTriangulationDict() |
---|
| 1314 | #print "dict",dict |
---|
[935] | 1315 | |
---|
[968] | 1316 | self.failUnless( dict['vertex_attribute_titles'] == titles, |
---|
| 1317 | 'test_Mesh2IOTriangulationDict failed. test 1') |
---|
| 1318 | answer = [a_xy,[0.0, 4.0],[4.0,0.0], [1.0,1.0], [2.0,2.0]] |
---|
| 1319 | #print "answer",answer |
---|
| 1320 | #print "dict['vertices']",dict['vertices'] |
---|
| 1321 | |
---|
| 1322 | self.failUnless( dict['vertices'] == answer, |
---|
| 1323 | 'test_Mesh2IOTriangulationDict failed. test 2') |
---|
| 1324 | |
---|
| 1325 | |
---|
| 1326 | for pimport,pactual,pimpatt in map(None,dict['vertices'], |
---|
| 1327 | verts,dict['vertex_attributes']): |
---|
| 1328 | #assert all_close( pimport, (pactual.x,pactual.y)) |
---|
| 1329 | self.failUnless( pimport == [pactual.x,pactual.y], |
---|
| 1330 | 'test_Mesh2IOTriangulationDict failed. test 2.1') |
---|
| 1331 | self.failUnless( pimpatt == pactual.attributes, |
---|
| 1332 | 'test_Mesh2IOTriangulationDict failed. test 2.2') |
---|
| 1333 | self.failUnless( dict['segments'][0] == [0,1], |
---|
| 1334 | 'test_Mesh2IOTriangulationDict failed. test 3') |
---|
[969] | 1335 | for segimp,segactual in map(None,dict['segment_tags'],seg): |
---|
| 1336 | self.failUnless( segimp == segactual.tag, |
---|
[968] | 1337 | 'test_Mesh2IOTriangulationDict failed. test 4') |
---|
| 1338 | #print " dict['triangles'][0]", dict['triangles'][0] |
---|
| 1339 | self.failUnless( dict['triangles'][0] == [3,2,4], |
---|
| 1340 | 'test_Mesh2IOTriangulationDict failed. test 5') |
---|
| 1341 | self.failUnless( dict['triangle_neighbors'][0] == [-1,2,3], |
---|
| 1342 | 'test_Mesh2IOTriangulationDict failed. test 6') |
---|
[1183] | 1343 | self.failUnless( dict['triangle_tags'][0] == "1.3", |
---|
[968] | 1344 | 'test_Mesh2IOTriangulationDict failed. test 7') |
---|
| 1345 | |
---|
| 1346 | |
---|
| 1347 | def test_Mesh2IODict(self): |
---|
| 1348 | |
---|
| 1349 | a_att = [5,2] |
---|
| 1350 | d_att =[4,2] |
---|
| 1351 | f_att = [3,2] |
---|
| 1352 | e_att = [2,2] |
---|
| 1353 | a_xy = [0.0, 0.0] |
---|
| 1354 | a = Vertex ( a_xy[0],a_xy[1] , attributes =a_att) |
---|
| 1355 | d = Vertex (0.0, 4.0 , attributes =d_att) |
---|
| 1356 | f = Vertex (4.0,0.0 , attributes =f_att) |
---|
| 1357 | e = Vertex (1.0,1.0 , attributes =e_att) |
---|
| 1358 | |
---|
[969] | 1359 | s1 = Segment(a,d, tag = "50") |
---|
| 1360 | s2 = Segment(d,f, tag = "40") |
---|
| 1361 | s3 = Segment(a,f, tag = "30") |
---|
| 1362 | s4 = Segment(a,e, tag = "20") |
---|
[968] | 1363 | |
---|
| 1364 | r1 = Region(0.3, 0.3,tag = "1.3", maxArea = 45) |
---|
| 1365 | m = Mesh(userVertices=[a,d,f,e], |
---|
| 1366 | userSegments=[s1,s2,s3,s4], |
---|
| 1367 | regions=[r1]) |
---|
| 1368 | titles = ['ele','friction'] |
---|
| 1369 | m.attributeTitles = titles |
---|
| 1370 | m.generateMesh("QApza2.1") |
---|
| 1371 | |
---|
| 1372 | seg = m.getMeshSegments() |
---|
| 1373 | verts = m.getMeshVertices() |
---|
| 1374 | dict = m.Mesh2IODict() |
---|
| 1375 | #print "dict",dict |
---|
| 1376 | |
---|
| 1377 | self.failUnless( dict['vertex_attribute_titles'] == titles, |
---|
| 1378 | 'test_Mesh2IOTriangulationDict failed. test 1') |
---|
| 1379 | answer = [a_xy,[0.0, 4.0],[4.0,0.0], [1.0,1.0], [2.0,2.0]] |
---|
| 1380 | #print "answer",answer |
---|
| 1381 | #print "dict['vertices']",dict['vertices'] |
---|
| 1382 | |
---|
| 1383 | self.failUnless( dict['vertices'] == answer, |
---|
| 1384 | 'test_Mesh2IOTriangulationDict failed. test 2') |
---|
| 1385 | |
---|
| 1386 | |
---|
| 1387 | for pimport,pactual,pimpatt in map(None,dict['vertices'], |
---|
| 1388 | verts,dict['vertex_attributes']): |
---|
| 1389 | #assert all_close( pimport, (pactual.x,pactual.y)) |
---|
| 1390 | self.failUnless( pimport == [pactual.x,pactual.y], |
---|
| 1391 | 'test_Mesh2IODict failed. test 2.1') |
---|
| 1392 | self.failUnless( pimpatt == pactual.attributes, |
---|
| 1393 | 'test_Mesh2IODict failed. test 2.2') |
---|
| 1394 | self.failUnless( dict['segments'][0] == [0,1], |
---|
| 1395 | 'test_Mesh2IODict failed. test 3') |
---|
[969] | 1396 | for segimp,segactual in map(None,dict['segment_tags'],seg): |
---|
| 1397 | self.failUnless( segimp == segactual.tag, |
---|
[968] | 1398 | 'test_Mesh2IODict failed. test 4') |
---|
| 1399 | #print " dict['triangles'][0]", dict['triangles'][0] |
---|
| 1400 | self.failUnless( dict['triangles'][0] == [3,2,4], |
---|
| 1401 | 'test_Mesh2IODict failed. test 5') |
---|
| 1402 | self.failUnless( dict['triangle_neighbors'][0] == [-1,2,3], |
---|
| 1403 | 'test_Mesh2IODict failed. test 6') |
---|
[1183] | 1404 | self.failUnless( dict['triangle_tags'][0] == "1.3", |
---|
[968] | 1405 | 'test_Mesh2IODict failed. test 7') |
---|
| 1406 | |
---|
| 1407 | seg = m.getUserSegments() |
---|
| 1408 | points = m.getUserVertices() |
---|
| 1409 | holes = m.getHoles() |
---|
| 1410 | regions = m.getRegions() |
---|
| 1411 | |
---|
| 1412 | for pimport,pactual,pimpatt in map(None,dict['points'],points,dict['point_attributes']): |
---|
| 1413 | self.failUnless( pimport == [pactual.x,pactual.y], |
---|
| 1414 | 'test_Mesh2IODict failed. test 1') |
---|
| 1415 | self.failUnless( pimpatt == pactual.attributes, |
---|
| 1416 | 'test_Mesh2IODict failed. test 1.1') |
---|
| 1417 | self.failUnless( dict['outline_segments'][0] == [0,1], |
---|
| 1418 | 'test_Mesh2IODict failed. test 3') |
---|
[969] | 1419 | for segimp,segactual in map(None,dict['outline_segment_tags'],seg): |
---|
| 1420 | self.failUnless( segimp == segactual.tag, |
---|
[968] | 1421 | 'test_Mesh2IODict failed. test 4') |
---|
| 1422 | for holeimp,holeactual in map(None,dict['holes'],holes): |
---|
| 1423 | self.failUnless( holeimp == [holeactual.x,holeactual.y], |
---|
| 1424 | 'test_Mesh2IODict failed. test 5') |
---|
| 1425 | |
---|
[969] | 1426 | for regimp,regactual,regattimp, regmaxarea in map(None,dict['regions'],regions, dict['region_tags'], dict['region_max_areas']): |
---|
[968] | 1427 | self.failUnless( regimp == [regactual.x,regactual.y], |
---|
| 1428 | 'loadASCIITestCase failed. test 6') |
---|
| 1429 | self.failUnless( regattimp == regactual.getTag(), |
---|
| 1430 | 'loadASCIITestCase failed. test 7') |
---|
| 1431 | self.failUnless( regmaxarea == regactual.getMaxArea(), |
---|
| 1432 | 'loadASCIITestCase failed. test 7') |
---|
| 1433 | |
---|
| 1434 | |
---|
| 1435 | |
---|
| 1436 | def test_Mesh2IOOutlineDict(self): |
---|
| 1437 | |
---|
| 1438 | a_att = [5,2] |
---|
| 1439 | d_att =[4,2] |
---|
| 1440 | f_att = [3,2] |
---|
| 1441 | e_att = [2,2] |
---|
| 1442 | a_xy = [0.0, 0.0] |
---|
| 1443 | a = Vertex ( a_xy[0],a_xy[1] , attributes =a_att) |
---|
| 1444 | d = Vertex (0.0, 4.0 , attributes =d_att) |
---|
| 1445 | f = Vertex (4.0,0.0 , attributes =f_att) |
---|
| 1446 | e = Vertex (1.0,1.0 , attributes =e_att) |
---|
| 1447 | |
---|
[969] | 1448 | s1 = Segment(a,d, tag = "50") |
---|
| 1449 | s2 = Segment(d,f, tag = "40") |
---|
| 1450 | s3 = Segment(a,f, tag = "30") |
---|
| 1451 | s4 = Segment(a,e, tag = "20") |
---|
[968] | 1452 | |
---|
| 1453 | r1 = Region(0.3, 0.3,tag = "1.3", maxArea = 45) |
---|
| 1454 | m = Mesh(userVertices=[a,d,f,e], |
---|
| 1455 | userSegments=[s1,s2,s3,s4], |
---|
| 1456 | regions=[r1]) |
---|
| 1457 | titles = ['ele','friction'] |
---|
| 1458 | m.attributeTitles = titles |
---|
| 1459 | m.generateMesh("QApza2.1") |
---|
| 1460 | |
---|
| 1461 | seg = m.getMeshSegments() |
---|
| 1462 | verts = m.getMeshVertices() |
---|
| 1463 | dict = m.Mesh2IOOutlineDict() |
---|
| 1464 | |
---|
| 1465 | seg = m.getUserSegments() |
---|
| 1466 | points = m.getUserVertices() |
---|
| 1467 | holes = m.getHoles() |
---|
| 1468 | regions = m.getRegions() |
---|
| 1469 | |
---|
| 1470 | for pimport,pactual,pimpatt in map(None,dict['points'],points,dict['point_attributes']): |
---|
| 1471 | self.failUnless( pimport == [pactual.x,pactual.y], |
---|
| 1472 | 'loadASCIITestCase failed. test 1') |
---|
| 1473 | self.failUnless( pimpatt == pactual.attributes, |
---|
| 1474 | 'loadASCIITestCase failed. test 1.1') |
---|
| 1475 | self.failUnless( dict['outline_segments'][0] == [0,1], |
---|
| 1476 | 'loadASCIITestCase failed. test 3') |
---|
[969] | 1477 | for segimp,segactual in map(None,dict['outline_segment_tags'],seg): |
---|
| 1478 | self.failUnless( segimp == segactual.tag, |
---|
[968] | 1479 | 'loadASCIITestCase failed. test 4') |
---|
| 1480 | for holeimp,holeactual in map(None,dict['holes'],holes): |
---|
| 1481 | self.failUnless( holeimp == [holeactual.x,holeactual.y], |
---|
| 1482 | 'loadASCIITestCase failed. test 5') |
---|
| 1483 | #for regimp,regactual in map(None,dict['regions'],regions): |
---|
| 1484 | # self.failUnless( [regimp[0],regimp[1]]==[regactual.x,regactual.y], |
---|
| 1485 | # 'loadASCIITestCase failed. test 6') |
---|
| 1486 | # self.failUnless( regimp[2] == regactual.getTag(), |
---|
| 1487 | # 'loadASCIITestCase failed. test 7') |
---|
| 1488 | #self.failUnless( regimp[3] == regactual.getMaxArea(), |
---|
| 1489 | # 'loadASCIITestCase failed. test 7') |
---|
| 1490 | |
---|
| 1491 | |
---|
[969] | 1492 | for regimp,regactual,regattimp, regmaxarea in map(None,dict['regions'],regions, dict['region_tags'], dict['region_max_areas']): |
---|
[968] | 1493 | self.failUnless( regimp == [regactual.x,regactual.y], |
---|
| 1494 | 'loadASCIITestCase failed. test 6') |
---|
| 1495 | self.failUnless( regattimp == regactual.getTag(), |
---|
| 1496 | 'loadASCIITestCase failed. test 7') |
---|
| 1497 | self.failUnless( regmaxarea == regactual.getMaxArea(), |
---|
| 1498 | 'loadASCIITestCase failed. test 7') |
---|
[1361] | 1499 | |
---|
| 1500 | |
---|
[2200] | 1501 | #___________beginning of Peters tests |
---|
[1361] | 1502 | |
---|
| 1503 | def test_set_stuff(self): |
---|
| 1504 | """ |
---|
| 1505 | Documentation |
---|
| 1506 | """ |
---|
| 1507 | #making a test mesh |
---|
| 1508 | p0=[0.,2.] |
---|
| 1509 | p1=[1.,2.] |
---|
| 1510 | p2=[0.,1.] |
---|
| 1511 | p3=[1.,1.] |
---|
| 1512 | p4=[0.,0.] |
---|
| 1513 | p5=[2.,0.] |
---|
| 1514 | p6=[-1.,1.] |
---|
| 1515 | point_list = [p0,p1,p2,p3,p4,p5,p6] |
---|
| 1516 | |
---|
| 1517 | a0=[0] |
---|
| 1518 | a1=[0] |
---|
| 1519 | a2=[100] |
---|
| 1520 | a3=[0] |
---|
| 1521 | a4=[0] |
---|
| 1522 | a5=[0] |
---|
| 1523 | a6=[0] |
---|
| 1524 | attribute=[a0,a1,a2,a3,a4,a5,a6] |
---|
| 1525 | |
---|
| 1526 | t0=[0,3,1] |
---|
| 1527 | t1=[0,2,3] |
---|
| 1528 | t2=[2,4,3] |
---|
| 1529 | t3=[4,5,3] |
---|
| 1530 | t4=[1,3,5] |
---|
| 1531 | t5=[2,6,4] |
---|
| 1532 | |
---|
| 1533 | n0=[4,-1,2] |
---|
| 1534 | n1=[2,0,-1] |
---|
| 1535 | n2=[3,1,5] |
---|
| 1536 | n3=[4,2,-1] |
---|
| 1537 | n4=[3,-1,0] |
---|
| 1538 | n5=[-1,2,-1] |
---|
| 1539 | |
---|
| 1540 | tri_list = [t0,t1,t2,t3,t4,t5] |
---|
| 1541 | n_list = [n0,n1,n2,n3,n4,n5] |
---|
| 1542 | for i in range(6): |
---|
| 1543 | for j in (0,1,2): |
---|
| 1544 | a=attribute[tri_list[i][j]] |
---|
| 1545 | tri_list[i][j]=point_list[tri_list[i][j]] |
---|
| 1546 | tri_list[i][j]=Vertex(tri_list[i][j][0]\ |
---|
| 1547 | ,tri_list[i][j][1],a) |
---|
| 1548 | neighbours=n_list[i] |
---|
| 1549 | tri_list[i]=Triangle(tri_list[i][0],\ |
---|
| 1550 | tri_list[i][1],tri_list[i][2]\ |
---|
| 1551 | ,neighbors=neighbours) |
---|
| 1552 | |
---|
| 1553 | #testing selectAll |
---|
| 1554 | mesh = Mesh() |
---|
| 1555 | mesh.attributeTitles=['attrib'] |
---|
| 1556 | |
---|
| 1557 | mesh.meshTriangles=tri_list |
---|
| 1558 | |
---|
| 1559 | mesh.selectAllTriangles() |
---|
| 1560 | A=mesh.sets[mesh.setID['All']] |
---|
| 1561 | assert list_comp(tri_list,A) |
---|
| 1562 | |
---|
| 1563 | #testing threshold |
---|
| 1564 | mesh = Mesh() |
---|
| 1565 | mesh.attributeTitles=['attrib'] |
---|
| 1566 | |
---|
| 1567 | mesh.meshTriangles=tri_list |
---|
| 1568 | mesh.selectAllTriangles() |
---|
| 1569 | mesh.threshold('All',min=30,max=35,attribute_name = 'attrib') |
---|
| 1570 | A = [tri_list[1],tri_list[2],tri_list[5]] |
---|
| 1571 | B = mesh.sets[mesh.setID['All']] |
---|
| 1572 | assert list_comp(A,B) |
---|
| 1573 | |
---|
| 1574 | |
---|
| 1575 | A = [tri_list[3],tri_list[2],tri_list[5]] |
---|
| 1576 | assert not list_comp(A,B) |
---|
| 1577 | |
---|
| 1578 | #testing |
---|
| 1579 | |
---|
| 1580 | def test_Discretised_Tuple_Set_rounding(self): |
---|
| 1581 | #This is the hardest bit of DST |
---|
| 1582 | from mesh import Discretised_Tuple_Set |
---|
| 1583 | |
---|
| 1584 | tol = 0.1 |
---|
| 1585 | a=Discretised_Tuple_Set(p_rel=1,t_rel= tol) |
---|
| 1586 | m = 0.541 |
---|
| 1587 | m_up = 0.6 |
---|
| 1588 | m_down = 0.5 |
---|
| 1589 | assert m_up == a.round_up_rel(m) |
---|
| 1590 | assert m_down == a.round_down_rel(m) |
---|
| 1591 | |
---|
| 1592 | tol = 0.1 |
---|
| 1593 | a=Discretised_Tuple_Set(p_rel=1,t_rel = tol) |
---|
| 1594 | m = 0.539 |
---|
| 1595 | m_up = 0.5 |
---|
| 1596 | m_down = 0.5 |
---|
| 1597 | assert m_up == a.round_up_rel(m) |
---|
| 1598 | assert m_down == a.round_down_rel(m) |
---|
| 1599 | |
---|
| 1600 | tol = 0.5 |
---|
| 1601 | a=Discretised_Tuple_Set(p_rel=1,t_rel = tol) |
---|
| 1602 | |
---|
| 1603 | |
---|
| 1604 | m = 0.6 |
---|
| 1605 | m_up = 0.7 |
---|
| 1606 | m_down = 0.5 |
---|
| 1607 | assert m_up == a.round_up_rel(m) |
---|
| 1608 | assert m_down == a.round_down_rel(m) |
---|
| 1609 | |
---|
| 1610 | m = 0.599 |
---|
| 1611 | m_up = 0.6 |
---|
| 1612 | m_down = 0.5 |
---|
| 1613 | assert m_up == a.round_up_rel(m) |
---|
| 1614 | assert m_down == a.round_down_rel(m) |
---|
| 1615 | |
---|
| 1616 | def test_Discretised_Tuple_Set_get(self): |
---|
| 1617 | from mesh import Discretised_Tuple_Set |
---|
| 1618 | tol = 0.25 |
---|
| 1619 | a=Discretised_Tuple_Set(p_rel=1,t_rel = tol) |
---|
| 1620 | b = (1.1,1.1) |
---|
| 1621 | a.append(b) |
---|
| 1622 | list = [(1.2,1.),(1.,1.),(1.,1.2),(1.2,1.2)] |
---|
| 1623 | for key in list: |
---|
| 1624 | assert a[key][0]==b |
---|
| 1625 | assert len(a[key])==1 |
---|
| 1626 | |
---|
| 1627 | c = (2.1,1.) |
---|
| 1628 | a.append(c) |
---|
| 1629 | assert a[(2.,1.)][0]==c |
---|
| 1630 | assert a[(2.2,1.)][0]==c |
---|
| 1631 | |
---|
| 1632 | def test_mapped_Discretised_Tuple_Set(self): |
---|
| 1633 | |
---|
| 1634 | from mesh import Mapped_Discretised_Tuple_Set |
---|
| 1635 | from mesh import Discretised_Tuple_Set |
---|
| 1636 | |
---|
| 1637 | def map(sequence): |
---|
| 1638 | return [len(sequence)] |
---|
| 1639 | |
---|
| 1640 | tol = 0.5 |
---|
| 1641 | a=Mapped_Discretised_Tuple_Set(map,p_rel=1,t_rel = tol) |
---|
| 1642 | b = range(20) |
---|
| 1643 | a.append(b) |
---|
| 1644 | assert b in a[range(17)] |
---|
| 1645 | assert b in a[range(22)] |
---|
| 1646 | |
---|
| 1647 | tol = 0.01 |
---|
| 1648 | a=Mapped_Discretised_Tuple_Set(map,p_rel=1,t_rel = tol) |
---|
| 1649 | b = range(20) |
---|
| 1650 | a.append(b) |
---|
| 1651 | assert b in a[range(20)] |
---|
| 1652 | assert b in a[range(19)] |
---|
| 1653 | assert not range(17) in a |
---|
| 1654 | |
---|
[2200] | 1655 | #___________end of Peters tests |
---|
[1361] | 1656 | |
---|
[2200] | 1657 | def test_addRegionFromPolygon(self): |
---|
| 1658 | m=Mesh() |
---|
| 1659 | m.addRegionFromPolygon([[0,0],[1,0],[0,1]]) |
---|
| 1660 | self.failUnless(len(m.regions)==1, |
---|
| 1661 | 'FAILED!') |
---|
| 1662 | self.failUnless(len(m.getUserSegments())==3, |
---|
| 1663 | 'FAILED!') |
---|
| 1664 | self.failUnless(len(m.userVertices)==3, |
---|
| 1665 | 'FAILED!') |
---|
| 1666 | |
---|
| 1667 | def test_addRegionFromPolygon2(self): |
---|
| 1668 | m=Mesh() |
---|
| 1669 | m.addRegionFromPolygon([[0,0],[1,0],[1,1],[0,1]], |
---|
| 1670 | {'tagin':[0,1],'bom':[2]}) |
---|
| 1671 | self.failUnless(len(m.regions)==1, |
---|
| 1672 | 'FAILED!') |
---|
| 1673 | segs = m.getUserSegments() |
---|
| 1674 | self.failUnless(len(segs)==4, |
---|
| 1675 | 'FAILED!') |
---|
| 1676 | self.failUnless(len(m.userVertices)==4, |
---|
| 1677 | 'FAILED!') |
---|
| 1678 | self.failUnless(segs[0].tag=='tagin', |
---|
| 1679 | 'FAILED!') |
---|
| 1680 | self.failUnless(segs[1].tag=='tagin', |
---|
| 1681 | 'FAILED!') |
---|
| 1682 | |
---|
| 1683 | self.failUnless(segs[2].tag=='bom', |
---|
| 1684 | 'FAILED!') |
---|
| 1685 | self.failUnless(segs[3].tag=='', |
---|
| 1686 | 'FAILED!') |
---|
| 1687 | |
---|
| 1688 | |
---|
| 1689 | |
---|
[1361] | 1690 | def list_comp(A,B): |
---|
| 1691 | yes = len(A)==len(B) |
---|
| 1692 | for item in A: |
---|
| 1693 | if not item in B: |
---|
| 1694 | yes = False |
---|
| 1695 | return yes |
---|
| 1696 | |
---|
| 1697 | #___________end of Peters tests |
---|
[968] | 1698 | |
---|
[349] | 1699 | #------------------------------------------------------------- |
---|
| 1700 | if __name__ == "__main__": |
---|
[1034] | 1701 | suite = unittest.makeSuite(meshTestCase,'test') |
---|
[1074] | 1702 | #suite = unittest.makeSuite(meshTestCase,'test_asciiFile') |
---|
[702] | 1703 | runner = unittest.TextTestRunner() #verbosity=2) |
---|
[349] | 1704 | runner.run(suite) |
---|
| 1705 | |
---|