Changeset 364
- Timestamp:
- Oct 6, 2004, 7:10:14 PM (20 years ago)
- Location:
- inundation/ga/storm_surge/pmesh
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pmesh/load_mesh/loadASCII.py
r363 r364 67 67 68 68 ######### loading the point title info 69 line = fd.readline() 70 #print "point title comments",line 69 71 vertTitle = [] 70 72 for index in range(int(NumOfVertAttributes)): … … 75 77 ######### loading the triangle info 76 78 line = fd.readline() 77 #print line79 #print "triangle comments",line 78 80 fragments = line.split() 79 81 #for fragment in fragments: … … 103 105 ######### loading the segment info 104 106 line = fd.readline() 105 #printline107 print "seg comment line",line 106 108 fragments = line.split() 107 109 #for fragment in fragments: … … 306 308 vertices = gen_dict['generatedpointlist'] 307 309 vertices_attributes = gen_dict['generatedpointattributelist'] 308 vertices_attribute_titles = gen_dict['generatedpointattributetitlelist'] 310 try: 311 vertices_attribute_titles = gen_dict['generatedpointattributetitlelist'] 312 313 except KeyError, e: 314 #FIXME is this the best way? 315 if vertices_attributes == [] or vertices_attributes[0] == []: 316 vertices_attribute_titles = [] 317 else: 318 raise KeyError, e 319 309 320 triangles = gen_dict['generatedtrianglelist'] 310 321 triangles_attributes = gen_dict['generatedtriangleattributelist'] … … 335 346 336 347 # write comments for title 337 fd.write(" 348 fd.write("# attribute column titles ...Triangulation Vertex Titles..." + "\n") 338 349 for title in vertices_attribute_titles: 339 350 fd.write(title + "\n") -
inundation/ga/storm_surge/pmesh/load_mesh/loadASCIIHarness.py
r349 r364 25 25 e_att = [2,2] 26 26 a_xy = [0.0, 0.0] 27 a = Vertex ( a_xy[0],a_xy[1] , attributes =a_att)28 d = Vertex (0.0, 4.0 , attributes =d_att)29 f = Vertex (4.0,0.0 , attributes =f_att)30 e = Vertex (1.0,1.0 , attributes =e_att)27 a = Vertex ( a_xy[0],a_xy[1]) #, attributes =a_att) 28 d = Vertex (0.0, 4.0) #, attributes =d_att) 29 f = Vertex (4.0,0.0) #, attributes =f_att) 30 e = Vertex (1.0,1.0) #, attributes =e_att) 31 31 32 32 s1 = Segment(a,d, marker = "50") … … 47 47 fileName = tempfile.mktemp(".txt") 48 48 #print "fileName",fileName 49 m.export ASCIItrianglulationfile(fileName)49 m.export_ASCII_trianglulation_file(fileName) 50 50 51 51 dict = import_trianglulation(fileName) … … 152 152 self.failUnless(m.userVertices[0].y == 0.0, 153 153 'loadxy, test 2 failed') 154 self.failUnless(m.userVertices[0].attributes == [10.0,0.0],155 'loadxy, test 2.2 failed')154 #self.failUnless(m.userVertices[0].attributes == [10.0,0.0], 155 # 'loadxy, test 2.2 failed') 156 156 self.failUnless(m.userVertices[1].x == 0.0, 157 157 'loadxy, test 3 failed') 158 158 self.failUnless(m.userVertices[1].y == 1.0, 159 159 'loadxy, test 4 failed') 160 self.failUnless(m.userVertices[1].attributes == [0.0,10.0],161 'loadxy, test 5 failed')160 #self.failUnless(m.userVertices[1].attributes == [0.0,10.0], 161 # 'loadxy, test 5 failed') 162 162 #------------------------------------------------------------- 163 163 if __name__ == "__main__": -
inundation/ga/storm_surge/pmesh/mesh.py
r355 r364 917 917 index +=1 918 918 self.userSegments.append(segObject) 919 index = 0 920 for att in genDict['pointattributelist']: 921 if att == None: 922 self.userVertices[index].setAttributes([]) 923 else: 924 self.userVertices[index].setAttributes(att) 925 index += 1 919 920 # Remove the loading of attribute info. 921 # Have attribute info added using least_squares in pyvolution 922 # index = 0 923 # for att in genDict['pointattributelist']: 924 # if att == None: 925 # self.userVertices[index].setAttributes([]) 926 # else: 927 # self.userVertices[index].setAttributes(att) 928 # index += 1 926 929 927 930 index = 0 … … 1268 1271 """ 1269 1272 fd = open(ofile,'w') 1270 self.writeASCIItrianglulation(fd,1271 self.meshVertices,1272 self.meshTriangles,1273 self.meshSegments)1274 self.writeASCIImesh(fd,1275 self.userVertices,1276 self.userSegments,1277 self.holes,1278 self.regions)1279 fd.close()1280 1281 def export_ASCII_trianglulation_file(self,ofile):1282 """1283 export a file, ofile, with the format1284 1285 First line: <# of vertices> <# of attributes>1286 Following lines: <vertex #> <x> <y> [attributes]1287 One line: <# of triangles>1288 Following lines: <triangle #> <vertex #> <vertex #> <vertex #> <neigbouring triangle #> <neigbouring triangle #> <neigbouring triangle #> [attribute of region]1289 One line: <# of segments>1290 Following lines: <segment #> <vertex #> <vertex #> [boundary marker]1291 """1292 fd = open(ofile,'w')1293 1273 gen_dict = self.Mesh2MeshList() 1294 1274 load_mesh.loadASCII.write_ASCII_trianglulation(fd,gen_dict) … … 1305 1285 """ 1306 1286 fd = open(ofile,'w') 1307 self.writeASCIItrianglulation(fd, 1308 [], 1309 [], 1310 []) 1287 meshDict = {} 1288 1289 meshDict['generatedpointlist'] = [] 1290 meshDict['generatedpointattributelist'] = [] 1291 meshDict['generatedsegmentlist'] = [] 1292 meshDict['generatedsegmentmarkerlist'] = [] 1293 1294 meshDict['generatedtrianglelist'] = [] 1295 meshDict['generatedtriangleattributelist'] = [] 1296 meshDict['generatedtriangleneighborlist'] = [] 1297 1298 load_mesh.loadASCII.write_ASCII_trianglulation(fd,meshDict) 1311 1299 self.writeASCIIsegmentoutline(fd, 1312 1300 self.userVertices, … … 1369 1357 self.holes, 1370 1358 self.regions) 1371 1372 def writeASCIItrianglulation(self, 1373 fd, 1374 meshVertices, 1375 meshTriangles, 1376 meshSegments): 1377 1378 numVert = str(len(meshVertices)) 1379 if (numVert == "0"): 1380 numVertAttrib = "0" 1381 else: 1382 numVertAttrib = str(len(meshVertices[0].attributes)) 1383 fd.write(numVert + " " + numVertAttrib + " # <vertex #> <x> <y> [attributes] ...Triangulation Vertices..." + "\n") 1384 1385 #<vertex #> <x> <y> [attributes] 1386 index = 0 1387 for vert in meshVertices: 1388 vert.index = index 1389 index += 1 1390 attlist = "" 1391 for att in vert.attributes: 1392 attlist = attlist + str(att)+" " 1393 attlist.strip() 1394 fd.write(str(vert.index) + " " 1395 + str(vert.x) + " " 1396 + str(vert.y) + " " 1397 + attlist + "\n") 1398 #<# of triangles> 1399 fd.write(str(len(meshTriangles)) + " # <triangle #> [<vertex #>] [<neigbouring triangle #>] [attribute of region] ...Triangulation Triangles..." + "\n") 1400 1401 # <triangle #> <vertex #> <vertex #> <vertex #> <neigbouring triangle #> <neigbouring triangle #> <neigbouring triangle #> [attribute of region] 1402 for tri in meshTriangles: 1403 neighbors = "" 1404 1405 for neighbor in tri.neighbors: 1406 if neighbor: 1407 neighbors += str(neighbor.index) + " " 1408 else: 1409 neighbors += "-1 " 1410 1411 #for att in vert.attributes: 1412 # attlist = attlist + str(att)+" " 1413 fd.write(str(tri.index) + " " 1414 + str(tri.vertices[0].index) + " " 1415 + str(tri.vertices[1].index) + " " 1416 + str(tri.vertices[2].index) + " " 1417 + neighbors + " " 1418 + str(tri.attribute) + "\n") 1419 1420 #One line: <# of segments> 1421 fd.write(str(len(meshSegments)) + 1422 " # <segment #> <vertex #> <vertex #> [boundary marker] ...Triangulation Segments..." + "\n") 1423 1424 #Following lines: <segment #> <vertex #> <vertex #> [boundary marker] 1425 for seg in meshSegments: 1426 fd.write(str(seg.index) + " " 1427 + str(seg.vertices[0].index) + " " 1428 + str(seg.vertices[1].index) + " " 1429 + str(seg.marker) + "\n") 1430 1359 1431 1360 def exportASCIImeshfile(self,ofile): 1432 1361 """ … … 1554 1483 xya_dict['pointattributelist'] = pointattributes 1555 1484 1556 load_mesh.loadASCII.export_xya_file(ofile, xya_dict, title )1485 load_mesh.loadASCII.export_xya_file(ofile, xya_dict, title, delimiter = " ") 1557 1486 1558 1487 -
inundation/ga/storm_surge/pmesh/meshHarness.py
r355 r364 390 390 def test_asciiFile(self): 391 391 392 a = Vertex (0.0, 0.0 , attributes = [1.1])393 d = Vertex (0.0, 4.0 , attributes = [1.2])394 f = Vertex (4.0,0.0 , attributes = [1.3])395 e = Vertex (1.0,1.0 , attributes = [1.4])392 a = Vertex (0.0, 0.0) #, attributes = [1.1]) 393 d = Vertex (0.0, 4.0) #, attributes = [1.2]) 394 f = Vertex (4.0,0.0) #, attributes = [1.3]) 395 e = Vertex (1.0,1.0) #, attributes = [1.4]) 396 396 397 397 s1 = Segment(a,d) … … 417 417 # print l,"<" 418 418 #print "@^@^" 419 self.failUnless(lFile[0] == "5 1 # <vertex #> <x> <y> [attributes] ...Triangulation Vertices..." 419 420 self.failUnless(lFile[0] == "5 0 # <vertex #> <x> <y> [attributes] ...Triangulation Vertices..." 420 421 , 421 422 'Ascii file is wrong, vertex title') 422 self.failUnless(lFile[1] == "0 0.0 0.0 1.1 " and423 lFile[2] == "1 0.0 4.0 1.2 " and424 lFile[3] == "2 4.0 0.0 1.3 " and425 lFile[4] == "3 1.0 1.0 1.4 " and426 lFile[5] == "4 2.0 2.0 1.25 "423 self.failUnless(lFile[1] == "0 0.0 0.0 " and #1.1 " and 424 lFile[2] == "1 0.0 4.0 " and #1.2 " and 425 lFile[3] == "2 4.0 0.0 " and #1.3 " and 426 lFile[4] == "3 1.0 1.0 " and #1.4 " and 427 lFile[5] == "4 2.0 2.0 " #1.25 " 427 428 , 428 429 'Ascii file is wrong, vertex') 429 self.failUnless(lFile[6] == "4 # <triangle #> [<vertex #>] [<neigbouring triangle #>] [attribute of region] ...Triangulation Triangles..." and 430 lFile[7] == "0 3 2 4 -1 2 3 " and 431 lFile[8] == "1 1 0 3 3 2 -1 " and 432 lFile[9] == "2 3 4 1 -1 1 0 " and 433 lFile[10] == "3 2 3 0 1 -1 0 " 430 431 self.failUnless(lFile[6] == "# attribute column titles ...Triangulation Vertex Titles..." 432 , 433 'Ascii file is wrong, attribute column title') 434 self.failUnless(lFile[7] == "4 # <triangle #> [<vertex #>] [<neigbouring triangle #>] [attribute of region] ...Triangulation Triangles..." and 435 lFile[8] == "0 3 2 4 -1 2 3 " and 436 lFile[9] == "1 1 0 3 3 2 -1 " and 437 lFile[10] == "2 3 4 1 -1 1 0 " and 438 lFile[11] == "3 2 3 0 1 -1 0 " 434 439 , 435 440 'Ascii file is wrong, triangle') 436 441 437 self.failUnless(lFile[1 1] == "5 # <segment #> <vertex #> <vertex #> [boundary marker] ...Triangulation Segments..." and438 lFile[1 2] == "0 0 1 external" and439 lFile[1 3] == "1 1 4 external" and440 lFile[1 4] == "2 2 0 external" and441 lFile[1 5] == "3 0 3 internal" and442 lFile[1 6] == "4 4 2 external" ,442 self.failUnless(lFile[12] == "5 # <segment #> <vertex #> <vertex #> [boundary marker] ...Triangulation Segments..." and 443 lFile[13] == "0 0 1 external" and 444 lFile[14] == "1 1 4 external" and 445 lFile[15] == "2 2 0 external" and 446 lFile[16] == "3 0 3 internal" and 447 lFile[17] == "4 4 2 external" , 443 448 'Ascii file is wrong, segment') 444 449 445 self.failUnless(lFile[1 7] == '4 1# <vertex #> <x> <y> [attributes] ...Mesh Vertices...',450 self.failUnless(lFile[18] == '4 0 # <vertex #> <x> <y> [attributes] ...Mesh Vertices...', 446 451 'Ascii file is wrong, Mesh Vertices Title') 447 452 448 self.failUnless(lFile[18] == '0 0.0 0.0 1.1 ' and 449 lFile[19] == '1 0.0 4.0 1.2 ' and 450 lFile[20] == '2 4.0 0.0 1.3 ' and 451 lFile[21] == '3 1.0 1.0 1.4 ', 453 self.failUnless(lFile[19] == '0 0.0 0.0 ' and #1.1 ' and 454 lFile[20] == '1 0.0 4.0 ' and #1.2 ' and 455 lFile[21] == '2 4.0 0.0 ' and #1.3 ' and 456 lFile[22] == '3 1.0 1.0 ' #1.4 ' 457 , 452 458 'Ascii file is wrong, Mesh Vertices II') 453 459 454 self.failUnless(lFile[2 2] == '4 # <segment #> <vertex #> <vertex #> [boundary marker] ...Mesh Segments...' and455 lFile[2 3] == '0 0 1 ' and456 lFile[2 4] == '1 1 2 ' and457 lFile[2 5] == '2 0 2 ' and458 lFile[2 6] == '3 0 3 ' and459 lFile[2 7] == '0 # <Hole #> <x> <y> ...Mesh Holes...' and460 lFile[2 8] == '0 # <Region #> <x> <y> <tag>...Mesh Regions...'460 self.failUnless(lFile[23] == '4 # <segment #> <vertex #> <vertex #> [boundary marker] ...Mesh Segments...' and 461 lFile[24] == '0 0 1 ' and 462 lFile[25] == '1 1 2 ' and 463 lFile[26] == '2 0 2 ' and 464 lFile[27] == '3 0 3 ' and 465 lFile[28] == '0 # <Hole #> <x> <y> ...Mesh Holes...' and 466 lFile[29] == '0 # <Region #> <x> <y> <tag>...Mesh Regions...' 461 467 , 462 468 'Ascii file is wrong, Mesh Segments') 469 463 470 464 465 471 def test_ascii_file(self): 466 472 467 a = Vertex (0.0, 0.0 , attributes = [1.1])468 d = Vertex (0.0, 4.0 , attributes = [1.2])469 f = Vertex (4.0,0.0 , attributes = [1.3])470 e = Vertex (1.0,1.0 , attributes = [1.4])473 a = Vertex (0.0, 0.0) #, attributes = [1.1]) 474 d = Vertex (0.0, 4.0) #, attributes = [1.2]) 475 f = Vertex (4.0,0.0) #, attributes = [1.3]) 476 e = Vertex (1.0,1.0) #, attributes = [1.4]) 471 477 472 478 s1 = Segment(a,d) … … 482 488 483 489 fileName = tempfile.mktemp(".txt") 484 m.export _ASCII_trianglulation_file(fileName)490 m.exportASCIItrianglulationfile(fileName) 485 491 file = open(fileName) 486 492 lFile = file.read().split('\n') … … 488 494 os.remove(fileName) 489 495 490 print "@^@^"491 for l in lFile:492 print l,"<"493 print "@^@^"494 self.failUnless(lFile[0] == "5 1# <vertex #> <x> <y> [attributes] ...Triangulation Vertices..."496 #print "@^@^" 497 #for l in lFile: 498 # print l,"<" 499 #print "@^@^" 500 self.failUnless(lFile[0] == "5 0 # <vertex #> <x> <y> [attributes] ...Triangulation Vertices..." 495 501 , 496 502 'Ascii file is wrong, vertex title') 497 self.failUnless(lFile[1] == "0 0.0 0.0 1.1 " and498 lFile[2] == "1 0.0 4.0 1.2 " and499 lFile[3] == "2 4.0 0.0 1.3 " and500 lFile[4] == "3 1.0 1.0 1.4 " and501 lFile[5] == "4 2.0 2.0 1.25 "503 self.failUnless(lFile[1] == "0 0.0 0.0 " and #1.1 " and 504 lFile[2] == "1 0.0 4.0 " and #1.2 " and 505 lFile[3] == "2 4.0 0.0 " and #1.3 " and 506 lFile[4] == "3 1.0 1.0 " and #1.4 " and 507 lFile[5] == "4 2.0 2.0 " #1.25 " 502 508 , 503 509 'Ascii file is wrong, vertex') 504 self.failUnless(lFile[6] == "4 # <triangle #> [<vertex #>] [<neigbouring triangle #>] [attribute of region] ...Triangulation Triangles..." and 505 lFile[7] == "0 3 2 4 -1 2 3 " and 506 lFile[8] == "1 1 0 3 3 2 -1 " and 507 lFile[9] == "2 3 4 1 -1 1 0 " and 508 lFile[10] == "3 2 3 0 1 -1 0 " 510 511 self.failUnless(lFile[6] == "# attribute column titles ...Triangulation Vertex Titles..." 512 , 513 'Ascii file is wrong, attribute column title') 514 self.failUnless(lFile[7] == "4 # <triangle #> [<vertex #>] [<neigbouring triangle #>] [attribute of region] ...Triangulation Triangles..." and 515 lFile[8] == "0 3 2 4 -1 2 3 " and 516 lFile[9] == "1 1 0 3 3 2 -1 " and 517 lFile[10] == "2 3 4 1 -1 1 0 " and 518 lFile[11] == "3 2 3 0 1 -1 0 " 509 519 , 510 520 'Ascii file is wrong, triangle') 511 521 512 self.failUnless(lFile[1 1] == "5 # <segment #> <vertex #> <vertex #> [boundary marker] ...Triangulation Segments..." and513 lFile[1 2] == "0 0 1 external" and514 lFile[1 3] == "1 1 4 external" and515 lFile[1 4] == "2 2 0 external" and516 lFile[1 5] == "3 0 3 internal" and517 lFile[1 6] == "4 4 2 external" ,522 self.failUnless(lFile[12] == "5 # <segment #> <vertex #> <vertex #> [boundary marker] ...Triangulation Segments..." and 523 lFile[13] == "0 0 1 external" and 524 lFile[14] == "1 1 4 external" and 525 lFile[15] == "2 2 0 external" and 526 lFile[16] == "3 0 3 internal" and 527 lFile[17] == "4 4 2 external" , 518 528 'Ascii file is wrong, segment') 519 529 520 self.failUnless(lFile[1 7] == '4 1# <vertex #> <x> <y> [attributes] ...Mesh Vertices...',530 self.failUnless(lFile[18] == '4 0 # <vertex #> <x> <y> [attributes] ...Mesh Vertices...', 521 531 'Ascii file is wrong, Mesh Vertices Title') 522 532 523 self.failUnless(lFile[18] == '0 0.0 0.0 1.1 ' and 524 lFile[19] == '1 0.0 4.0 1.2 ' and 525 lFile[20] == '2 4.0 0.0 1.3 ' and 526 lFile[21] == '3 1.0 1.0 1.4 ', 533 self.failUnless(lFile[19] == '0 0.0 0.0 ' and #1.1 ' and 534 lFile[20] == '1 0.0 4.0 ' and #1.2 ' and 535 lFile[21] == '2 4.0 0.0 ' and #1.3 ' and 536 lFile[22] == '3 1.0 1.0 ' #1.4 ' 537 , 527 538 'Ascii file is wrong, Mesh Vertices II') 528 539 529 self.failUnless(lFile[2 2] == '4 # <segment #> <vertex #> <vertex #> [boundary marker] ...Mesh Segments...' and530 lFile[2 3] == '0 0 1 ' and531 lFile[2 4] == '1 1 2 ' and532 lFile[2 5] == '2 0 2 ' and533 lFile[2 6] == '3 0 3 ' and534 lFile[2 7] == '0 # <Hole #> <x> <y> ...Mesh Holes...' and535 lFile[2 8] == '0 # <Region #> <x> <y> <tag>...Mesh Regions...'540 self.failUnless(lFile[23] == '4 # <segment #> <vertex #> <vertex #> [boundary marker] ...Mesh Segments...' and 541 lFile[24] == '0 0 1 ' and 542 lFile[25] == '1 1 2 ' and 543 lFile[26] == '2 0 2 ' and 544 lFile[27] == '3 0 3 ' and 545 lFile[28] == '0 # <Hole #> <x> <y> ...Mesh Holes...' and 546 lFile[29] == '0 # <Region #> <x> <y> <tag>...Mesh Regions...' 536 547 , 537 548 'Ascii file is wrong, Mesh Segments') … … 589 600 e_att = [2.0,2.0] 590 601 a_xy = [0.0, 0.0] 591 a = Vertex ( a_xy[0],a_xy[1] , attributes =a_att)592 d = Vertex (0.0, 4.0 , attributes =d_att)593 f = Vertex (4.0,0.0 , attributes =f_att)594 e = Vertex (1.0,1.0 , attributes =e_att)602 a = Vertex ( a_xy[0],a_xy[1]) #, attributes =a_att) 603 d = Vertex (0.0, 4.0) #, attributes =d_att) 604 f = Vertex (4.0,0.0) #, attributes =f_att) 605 e = Vertex (1.0,1.0) #, attributes =e_att) 595 606 596 607 s1 = Segment(a,d, marker = "50") … … 609 620 #print "****************** fileName", fileName 610 621 m.exportASCIItrianglulationfile(fileName) 611 #print m 622 print "******************" 623 print "m", m 624 print "******************" 612 625 m_returned = importMeshFromFile(fileName) 613 #print m_returned 626 print "m_returned",m_returned 627 print "******************" 614 628 #print "****************** fileName", fileName 615 629 os.remove(fileName)
Note: See TracChangeset
for help on using the changeset viewer.