Changeset 4898
- Timestamp:
- Dec 31, 2007, 7:37:59 AM (17 years ago)
- Location:
- anuga_core/source/anuga
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/mesh_engine/mesh_engine.py
r4894 r4898 8 8 #import anuga.mesh_engine.list_dic as triang 9 9 10 from Numeric import array, Float, Int32 10 from Numeric import array, Float, Int32, reshape 11 11 12 12 from anuga.utilities.numerical_tools import ensure_numeric … … 18 18 mode=None, dummy_test=None): 19 19 """ 20 20 pointatts can be a list of lists. 21 22 generatedtriangleattributelist is used to represent tagged regions. 23 #FIXME (DSG-DSG): add comments 21 24 """ 22 25 #FIXME (DSG-DSG): Catch parameters that are lists, … … 52 55 if pointatts is None or pointatts == []: 53 56 pointatts = [[] for x in range(points.shape[0])] 54 55 57 try: 56 58 # If Int is used, instead of Int32, it fails in Linux 57 59 segments = ensure_numeric(segments, Int32) 60 58 61 except ValueError: 59 62 msg = 'ERROR: Inconsistent segments array.' … … 63 66 if segatts is None or segatts == []: 64 67 segatts = [0 for x in range(segments.shape[0])] 65 66 68 try: 67 69 holes = ensure_numeric(holes, Float) … … 83 85 84 86 try: 85 #print "pointatts",pointatts86 87 pointatts = ensure_numeric(pointatts, Float) 87 88 except (ValueError, TypeError): … … 93 94 point array.""" 94 95 raise ANUGAError, msg 96 if len(pointatts.shape) == 1: 97 pointatts = reshape(pointatts,(pointatts.shape[0],1)) 95 98 96 99 try: … … 113 116 # input vertices and vertices ``eaten'' by holes). - output a 114 117 # list of neighboring triangles 118 # EG handles lone verts! 115 119 116 120 #print "points",points … … 121 125 #print "pointatts", pointatts 122 126 #print "segatts", segatts 123 # print "mode", mode127 #XSprint "mode", mode 124 128 #print "yeah" 125 mesh_dict, r_test = triang.genMesh(points,segments,holes,regions,129 mesh_dict, trianglelist, pointlist, pointmarkerlist, pointattributelist, triangleattributelist, segmentlist, segmentmarkerlist, neighborlist = triang.genMesh(points,segments,holes,regions, 126 130 pointatts,segatts, mode, segments.flat) 131 # the values as arrays 132 mesh_dict['trianglelist'] = trianglelist 133 mesh_dict['pointlist'] = pointlist 134 135 # WARNING - pointmarkerlist IS UNTESTED 136 mesh_dict['pointmarkerlist'] = pointmarkerlist 137 mesh_dict['pointattributelist'] = pointattributelist 138 mesh_dict['triangleattributelist'] = triangleattributelist 139 mesh_dict['segmentlist'] = segmentlist 140 mesh_dict['segmentmarkerlist'] = segmentmarkerlist 141 mesh_dict['triangleneighborlist'] = neighborlist 127 142 mesh_dict['qaz'] = 1 #debugging 128 143 ##print "r_test", r_test 144 129 145 return mesh_dict 130 146 -
anuga_core/source/anuga/mesh_engine/mesh_engine_c_layer.c
r4894 r4898 36 36 shape and mesh_engine. 37 37 38 to return numeric arrays, check how it is done in39 quantity_ext.c compute_gradients40 38 41 39 Precondition … … 92 90 93 91 94 PyArrayObject *r_test; 92 PyArrayObject *gentrianglelist; 93 PyArrayObject *genpointlist; 94 PyArrayObject *genseglist; 95 PyArrayObject *genpointmarkerlist; 96 PyArrayObject *genpointattributelist; 97 PyArrayObject *gentriangleattributelist; 98 PyArrayObject *gensegmentlist; 99 PyArrayObject *gensegmentmarkerlist; 100 PyArrayObject *genneighborlist; 95 101 PyObject *R; 96 102 97 int dimensions[ 1];103 int dimensions[2]; 98 104 99 105 REAL Attr; … … 149 155 150 156 /* Point attribute list */ 157 /*printf ("in.pointattributelist -> dimensions[0] %i\n", pointattributelist -> dimensions[0]); 158 printf ("in.pointattributelist -> dimensions[1] %i\n", pointattributelist -> dimensions[1]); */ 151 159 if (0 == pointattributelist -> dimensions[0]) { 152 160 in.numberofpointattributes = 0; … … 220 228 221 229 230 231 /* printf(" *** back from triangulate\n" ); */ 222 232 /* 233 ------- Pass point numbers,coordinates and neighbors back to Python ------ 234 we send back a dictionary: 235 { index : [ coordinates, [connections], Attribute ] } 236 */ 237 holder = PyDict_New(); 238 239 /* 240 241 to return numeric arrays, check how it is done in 242 abs quantity_ext.c compute_gradients 243 223 244 PyArray_FromDims allolws you to create a Numeric array with unitialized data. 224 245 The first argument is the size of the second argument ( … … 230 251 */ 231 252 232 //Py_Initialize(); 233 // Testing passing a numeric array out 234 dimensions[0] = 4; 235 // Allocate space for return vectors a and b (don't DECREF) 236 r_test = (PyArrayObject *) PyArray_FromDims(1, dimensions, PyArray_DOUBLE); 237 238 /* printf(" *** back from triangulate\n" ); */ 239 /* 240 ------- Pass point numbers,coordinates and neighbors back to Python ------ 241 we send back a dictionary: 242 { index : [ coordinates, [connections], Attribute ] } 243 */ 244 holder = PyDict_New(); 245 253 254 /* Add triangle list */ 255 dimensions[0] = out.numberoftriangles; 256 dimensions[1] = 3; 257 gentrianglelist = (PyArrayObject *) PyArray_FromDims(2, 258 dimensions, 259 PyArray_INT); 260 gentrianglelist -> data = out.trianglelist; 261 246 262 /* Add triangle list */ 247 263 listsize = out.numberoftriangles; … … 255 271 ii=PyString_FromString("generatedtrianglelist"); 256 272 PyDict_SetItem(holder, ii, holderlist); Py_DECREF(ii); Py_DECREF(holderlist); 273 274 275 /* Add pointlist */ 276 dimensions[0] = out.numberofpoints; 277 dimensions[1] = 2; 278 genpointlist = (PyArrayObject *) PyArray_FromDims(2, 279 dimensions, 280 PyArray_DOUBLE); 281 /* 282 (double*) genpointlist -> data = out.pointlist; 283 ((double*) genpointlist -> data) = out.pointlist; 284 ( genpointlist -> data) = (double*) out.pointlist; 285 286 */ 287 genpointlist -> data = out.pointlist; 257 288 258 289 /* Add pointlist */ … … 269 300 270 301 /* Add point marker list */ 302 dimensions[0] = out.numberofpoints; 303 genpointmarkerlist = (PyArrayObject *) PyArray_FromDims(1, 304 dimensions, 305 PyArray_INT); 306 genpointmarkerlist -> data = out.pointmarkerlist; 307 308 /* Add point marker list */ 271 309 listsize = out.numberofpoints; 272 310 holderlist = PyList_New(listsize); 273 311 274 312 for(i=0; i<listsize;i++){ 275 PyObject *mlist = Py_BuildValue((char *)" d",313 PyObject *mlist = Py_BuildValue((char *)"i", 276 314 out.pointmarkerlist[i]); 277 315 PyList_SetItem(holderlist,i, mlist); … … 280 318 PyDict_SetItem(holder, ii, holderlist); Py_DECREF(ii); Py_DECREF(holderlist); 281 319 320 /* Add point attribute list */ 321 dimensions[0] = out.numberofpoints; 322 dimensions[1] = out.numberofpointattributes; 323 genpointattributelist = (PyArrayObject *) PyArray_FromDims(2, 324 dimensions, 325 PyArray_DOUBLE); 326 genpointattributelist -> data = out.pointattributelist; 327 328 282 329 /* Add point attribute list */ 283 330 listsize = out.numberofpoints; … … 297 344 PyDict_SetItem(holder, ii, holderlist); Py_DECREF(ii); Py_DECREF(holderlist); 298 345 346 /* Add triangle attribute list */ 347 dimensions[0] = out.numberoftriangles; 348 dimensions[1] = out.numberoftriangleattributes; 349 gentriangleattributelist = (PyArrayObject *) PyArray_FromDims(2, 350 dimensions, 351 PyArray_DOUBLE); 352 gentriangleattributelist -> data = out.triangleattributelist; 299 353 300 354 /* Add triangle attribute list */ … … 315 369 316 370 /* Add segment list */ 371 dimensions[0] = out.numberofsegments; 372 dimensions[1] = 2; 373 gensegmentlist = (PyArrayObject *) PyArray_FromDims(2, 374 dimensions, 375 PyArray_INT); 376 gensegmentlist -> data = out.segmentlist; 377 378 379 /* Add segment list */ 317 380 listsize = out.numberofsegments; 318 381 holderlist = PyList_New(listsize); … … 327 390 328 391 /* Add segment marker list */ 392 dimensions[0] = out.numberofsegments; 393 gensegmentmarkerlist = (PyArrayObject *) PyArray_FromDims(1, 394 dimensions, 395 PyArray_INT); 396 gensegmentmarkerlist -> data = out.segmentmarkerlist; 397 398 399 /* Add segment marker list */ 329 400 listsize = out.numberofsegments; 330 401 holderlist = PyList_New(listsize); … … 335 406 } 336 407 ii=PyString_FromString("generatedsegmentmarkerlist"); 337 PyDict_SetItem(holder, ii, holderlist); Py_DECREF(ii); Py_DECREF(holderlist); 408 PyDict_SetItem(holder, ii, holderlist); Py_DECREF(ii); 409 Py_DECREF(holderlist); 410 411 /* Add triangle neighbor list */ 412 dimensions[0] = out.numberoftriangles; 413 dimensions[1] = 3; 414 genneighborlist = (PyArrayObject *) PyArray_FromDims(2, 415 dimensions, 416 PyArray_INT); 417 genneighborlist -> data = out.neighborlist; 418 419 338 420 /* Add triangle neighbor list */ 339 421 if (out.neighborlist != NULL) { … … 399 481 400 482 /* R = Py_BuildValue((char *)"O", holder); */ 401 R = Py_BuildValue((char *)"OO", holder, PyArray_Return(r_test)); 483 R = Py_BuildValue((char *)"OOOOOOOOO", holder 484 ,PyArray_Return(gentrianglelist) 485 ,PyArray_Return(genpointlist) 486 ,PyArray_Return(genpointmarkerlist) 487 ,PyArray_Return(genpointattributelist) 488 ,PyArray_Return(gentriangleattributelist) 489 ,PyArray_Return(gensegmentlist) 490 ,PyArray_Return(gensegmentmarkerlist) 491 ,PyArray_Return(genneighborlist) 492 ); 402 493 Py_DECREF(holder); /** This fixed a memory problem ticket#189 */ 403 Py_DECREF(r_test); 494 Py_DECREF(gentrianglelist); 495 Py_DECREF(genpointlist); 496 Py_DECREF(genpointmarkerlist); 497 Py_DECREF(genpointattributelist); 498 Py_DECREF(gentriangleattributelist); 499 Py_DECREF(gensegmentlist); 500 Py_DECREF(gensegmentmarkerlist); 501 Py_DECREF(genneighborlist); 404 502 return R; 405 503 } -
anuga_core/source/anuga/mesh_engine/test_generate_mesh.py
r4893 r4898 159 159 def testsegmarker(self): 160 160 161 points = []162 seglist = []163 161 holelist = [] 164 162 regionlist = [] … … 259 257 # for Ole on nautilus this returns 6 260 258 # for Duncan on nautilus this returns 7 261 # ??, it seems to be the results from triangle that is259 # It seems to be the results from triangle that is 262 260 # causing the different results, and we are treating 263 261 # triangle as a back box. … … 526 524 self.failUnless(data['lonepointlist'] ==[0], 527 525 'lonepointlist is wrong!') 526 527 528 529 def test_transition_to_arrays(self): 530 # segattlist = [] 531 points = [] 532 seglist = [] 533 holelist = [] 534 regionlist = [] 535 536 points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0,10.0)] 537 pointattlist = [] 538 # 5.0 is the region tag, 99.0 is the max area 539 # REgion tag isn't working though 540 regionlist.append( [0.2,0.2,5.0,99.0] ) 541 seglist = [(0,1),(1,3),(3,2),(2,0)] 542 segattlist = [21,22,23,24] 543 #The 'A' has to be there to get the region marker stuff working 544 mode = "QzpnA" 545 #mode = "jQpznAa2000.1a" 546 data = generate_mesh(points,seglist,holelist,regionlist, 547 pointattlist,segattlist, mode, points) 548 #print "data", data 549 550 self.failUnless(data['generatedtrianglelist'] ==[(1, 0, 2), (2, 3, 1)], 551 'trianglelist is wrong!') 552 #print "data['generatedtrianglelist']",data['generatedtrianglelist'] 553 #print "data['trianglelist']", data['trianglelist'] 554 self.failUnless(data['generatedtrianglelist'] ==data['trianglelist'], 555 'trianglelist is wrong!') 556 self.failUnless(data['generatedsegmentlist'] ==[(0, 1), (1, 3), 557 (3, 2), (2, 0)], 558 'segmentlist is wrong!') 559 self.failUnless(data['generatedpointlist'] ==[(0.0, 0.0), (0.0, 10.0), 560 (3.0, 0.0), (3.0, 10.0)], 561 ' is wrong!') 562 self.failUnless(data['generatedpointlist'] ==data['pointlist'], 563 ' is wrong!') 564 self.failUnless(data['generatedtriangleattributelist'] == [[5.0], 565 [5.0]], 566 ' is wrong!') 567 568 self.failUnless(data['generatedtriangleattributelist'] == \ 569 data['triangleattributelist'], 570 ' is wrong!') 571 self.failUnless(data['generatedsegmentlist'] == seglist, 572 ' is wrong!') 573 self.failUnless(data['generatedsegmentlist'] == data['segmentlist'], 574 ' is wrong!') 575 self.failUnless(data['generatedsegmentmarkerlist'] == segattlist, 576 ' is wrong!') 577 self.failUnless(data['generatedsegmentmarkerlist'] == \ 578 data['segmentmarkerlist'], 579 ' is wrong!') 580 # I copied these answers from the output, so bad test.. 581 self.failUnless(data['generatedtriangleneighborlist'] == \ 582 [(-1, 1, -1), (-1, 0, -1)], 583 ' is wrong!') 584 self.failUnless(data['generatedtriangleneighborlist'] == \ 585 data['triangleneighborlist'], 586 ' is wrong!') 587 588 def test_pointattlist(self): 589 # segattlist = [] 590 points = [] 591 seglist = [] 592 holelist = [] 593 regionlist = [] 594 595 points = [(0.0,0.0),(0.0,4.0),(4.0,2.0),(2.0,0.0)] 596 pointattlist = [0.,0.,10.,10.] 597 regionlist.append( [0.2,0.2,2.1, 99.] ) 598 seglist = [(0,1),(1,2),(2,3),(3,0)] 599 segattlist = [11,12,13,14] 600 mode = "Qzp" 601 data = generate_mesh(points,seglist,holelist,regionlist, 602 pointattlist,segattlist, mode, points) 603 self.failUnless(data['generatedpointattributelist'] == [[0.0],[0.0], 604 [10],[10]], 605 ' is wrong!') 606 self.failUnless(data['generatedpointattributelist'] == \ 607 data['pointattributelist'], 608 ' is wrong!') 609 610 611 pointattlist = [[0.],[0.],[10.],[10.]] 612 mode = "Qzp" 613 data = generate_mesh(points,seglist,holelist,regionlist, 614 pointattlist,segattlist, mode, points) 615 self.failUnless(data['generatedpointattributelist'] == [[0.0],[0.0], 616 [10],[10]], 617 ' is wrong!') 618 self.failUnless(data['generatedpointattributelist'] == \ 619 data['pointattributelist'], 620 ' is wrong!') 621 pointattlist = [[0.,1],[0.,1],[10.,20],[10.,20]] 622 mode = "Qzp" 623 data = generate_mesh(points,seglist,holelist,regionlist, 624 pointattlist,segattlist, mode, points) 625 #print "data", data 626 self.failUnless(data['generatedpointattributelist'] == pointattlist, 627 ' is wrong!') 628 self.failUnless(data['generatedpointattributelist'] == \ 629 data['pointattributelist'], 630 ' is wrong!') 631 528 632 if __name__ == "__main__": 529 633 530 634 suite = unittest.makeSuite(triangTestCase,'test') 531 635 #suite = unittest.makeSuite(triangTestCase,'test_lone_verts4') 532 #suite = unittest.makeSuite(triangTestCase,'test rectangleIIb')636 #suite = unittest.makeSuite(triangTestCase,'test_transition_to_arrays') 533 637 runner = unittest.TextTestRunner() #verbosity=2) 534 638 runner.run(suite) -
anuga_core/source/anuga/pmesh/mesh.py
r4894 r4898 1163 1163 #FIXME (DSG-DSG) move below section into generate_mesh.py 1164 1164 # & 4 functions eg segment_strings2ints 1165 # Actually, because of region_list.append((1.0,2.0,"")) 1166 # don't move it, without careful thought 1165 1167 #print "*************************!@!@ This is going to triangle !@!@" 1166 1168 #print meshDict
Note: See TracChangeset
for help on using the changeset viewer.