Changeset 4916


Ignore:
Timestamp:
Jan 9, 2008, 12:15:17 PM (17 years ago)
Author:
duncan
Message:

Working on generate_mesh memory issues. Thanks Ole for helping me with this, and Nick for letting me use his computer.

Location:
anuga_core/source/anuga/mesh_engine
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/mesh_engine/mesh_engine.py

    r4902 r4916  
    5858    if pointatts is None or pointatts == []:
    5959        pointatts = [[] for x in range(points.shape[0])]
     60       
    6061    try:
    6162        # If Int is used, instead of Int32, it fails in Linux
     
    6970    if segatts is None or segatts == []:
    7071        segatts = [0 for x in range(segments.shape[0])]
     72       
    7173    try:
    7274        holes = ensure_numeric(holes, Float)
     
    109111        segment array."""
    110112        raise ANUGAError, msg
    111 
    112113   
    113114    #print "mode", mode
     
    128129    #print "pointatts", pointatts
    129130    #print "segatts", segatts
    130     #XSprint "mode", mode
    131     #print "yeah"
     131    #print "mode", mode
     132    #print "yeah"
     133    # .copy()
    132134    trianglelist, pointlist, pointmarkerlist, pointattributelist, triangleattributelist, segmentlist, segmentmarkerlist, neighborlist = triang.genMesh(points,segments,holes,regions,
    133                           pointatts,segatts, mode, segments.flat)
     135                          pointatts,segatts, mode)
    134136    mesh_dict = {}
    135137    # the values as arrays
     
    145147    mesh_dict['qaz'] = 1 #debugging
    146148
    147     mesh_dict['triangleattributelist'] = triangleattributelist
     149    #mesh_dict['triangleattributelist'] = triangleattributelist
    148150    #print "mesh eng generatedtrianglelist", trianglelist
    149151    #print "mesh eng mesh_dict['triangleattributelist'] ",mesh_dict['triangleattributelist']
     
    157159        if mesh_dict['generatedpointattributelist'].shape[1] == 0:
    158160            mesh_dict['generatedpointattributelist'] = None
     161           
     162        if mesh_dict['generatedtriangleneighborlist'].shape[1] == 0:
     163            mesh_dict['generatedtriangleneighborlist'] = None
     164           
    159165        if trianglelist.shape[0] == 0:
    160166            # There are no triangles.
     
    162168            raise NoTrianglesError
    163169    #print "mesh eng mesh_dict['generatedtriangleattributelist'] ", mesh_dict['generatedtriangleattributelist'] 
    164    
     170    a = mesh_dict['generatedtriangleattributelist']
     171    #print 'mesh_dict', mesh_dict
    165172    # the structure of generatedtriangleattributelist is an list of
    166173    # list of integers.  It is transformed into a list of list of
  • anuga_core/source/anuga/mesh_engine/mesh_engine_c_layer.c

    r4915 r4916  
    6262//#define PY_ARRAY_UNIQUE_SYMBOL API_YEAH
    6363
    64 //#define PY_ARRAY_UNIQUE_SYMBOL API_YEAH
    65 
     64#define PY_ARRAY_UNIQUE_SYMBOL API_YEAH
    6665//#define NO_IMPORT_ARRAY
    6766#include "Numeric/arrayobject.h"
     
    117116  char *mod;
    118117   
    119   if(!PyArg_ParseTuple(args,(char *)"OOOOOOOO",&pointlist,&seglist,&holelist,&regionlist,&pointattributelist,&segmarkerlist,&mode,&test)){
     118  if(!PyArg_ParseTuple(args,(char *)"OOOOOOO",&pointlist,&seglist,&holelist,&regionlist,&pointattributelist,&segmarkerlist,&mode)){
    120119    return NULL;
    121120  }
     
    128127  /* Initialize and fill up region list */
    129128  in.numberofregions = regionlist-> dimensions[0];
     129 
    130130  in.regionlist = (double *) regionlist -> data;
    131131 
     
    133133  in.numberofsegments = seglist -> dimensions[0];
    134134  in.segmentlist = (int *) seglist -> data;
    135   /* in.segmentlist = (int *) test -> data; */
    136135  in.segmentmarkerlist = (int *) segmarkerlist -> data;
     136  //in.segmentmarkerlist = (int *) NULL;
    137137 
    138138  /*Initialize triangles */
     
    141141  in.numberoftriangleattributes = 0; 
    142142  in.triangleattributelist  = (REAL *)NULL;
     143  in.trianglearealist  = (REAL *)NULL;
     144  in.neighborlist = (int *)NULL;
     145  in.numberofcorners = 0;
    143146     
    144147  /*Initialize holes */
     
    155158  if (0 == pointattributelist -> dimensions[0]) {
    156159    in.numberofpointattributes = 0;
    157     in.pointattributelist =  NULL;
     160    in.pointattributelist =  (double *) NULL;
    158161  } else {
    159162    if (0 == pointattributelist -> dimensions[1]) {
    160163    in.numberofpointattributes = 0;
    161     in.pointattributelist =  NULL;
     164    in.pointattributelist =  (double *) NULL;
    162165    } else {
    163166      in.numberofpointattributes = pointattributelist -> dimensions[1];
     
    170173 
    171174  printf ("numberofpoints %i\n", in.numberofpoints);
     175  printf ("numberofpointattributes %i\n", in.numberofpointattributes);
    172176  for(i = 0; i < in.numberofpoints; i++) {
    173177    printf("(%f,%f)\n",in.pointlist[i* 2+ 0],in.pointlist[i* 2+ 1]);
     178    for(j = 0; j < in.numberofpointattributes; j++) {
     179      printf("point att (%f)\n",in.pointattributelist[i* in.numberofpointattributes + j]);
     180    }
     181   
    174182  }
    175183     
    176184  printf ("numberofregions %i\n", in.numberofregions);
    177185  for(i = 0; i < in.numberofregions; i++) {
    178     printf("(%f,%f)\n",in.regionlist[i* 2+ 0],in.regionlist[i* 2+ 1]);
     186    printf("(%f,%f)  ",in.regionlist[i* 4+ 0],in.regionlist[i* 4+ 1]);
     187    printf("index %f Area %f\n",in.regionlist[i* 4+ 2],in.regionlist[i* 4+ 3]);
    179188  }
    180189   
    181190  printf ("numberofsegments %i\n", in.numberofsegments);
    182191  for(i = 0; i < in.numberofsegments; i++) {
    183       printf("(%i,%i)",in.segmentlist[i* 2+ 0],in.segmentlist[i* 2+ 1]);
     192      printf("(%i,%i)\n",in.segmentlist[i* 2+ 0],in.segmentlist[i* 2+ 1]);
     193      printf("Segment marker (%i)\n",in.segmentmarkerlist[i + 0]);
    184194      }
    185195 
     
    194204      printf("(%i,%i,%i)",in.trianglelist[i* 3+ 0],in.trianglelist[i* 3+ 1], in.trianglelist[i* 3+ 2]);
    195205      }
    196   printf(" ***  see ya world\n" );       */
    197      
     206  printf(" ***  see ya world\n" );       
     207      */
    198208  /* set up the switch arguments to the triangulation routine */
    199209  mod = PyString_AS_STRING(mode);
     
    202212  out.pointlist = (REAL *)NULL;
    203213  out.pointmarkerlist = (int *)NULL;
    204   out.numberofpointattributes = in.numberofpointattributes;
     214  //out.numberofpointattributes = in.numberofpointattributes;
    205215  out.pointattributelist = (REAL *)NULL;
    206216 
     
    220230   
    221231 
    222   /*printf("\n\nTriangulate input args: %s \n\n", mod); */
    223232  triangulate(mod, &in, &out, (struct triangulateio *)NULL );
    224233 
    225234 
    226  
    227   /* printf(" ***  back from triangulate\n" );    */
     235   
    228236  /*
    229237    ------- Pass point numbers,coordinates and neighbors back to Python ------
     
    250258  dimensions[0] = out.numberoftriangles;
    251259  dimensions[1] = 3;   
    252   gentrianglelist = (PyArrayObject *) PyArray_FromDims(2,
    253                                                        dimensions,
    254                                                        PyArray_INT);
    255   gentrianglelist -> data = out.trianglelist;
    256  
    257   /*gentrianglelist = PyArray_ContiguousFromObject(out.trianglelist,
    258                                                  PyArray_DOUBLE,
    259                                                  0,
    260   */                                               
    261  
    262   /*gentrianglelist = PyArray_FromDimsAndData(2,
     260  gentrianglelist = (PyArrayObject *) PyArray_FromDimsAndData(2,
    263261                                            dimensions,
    264262                                            PyArray_INT,
    265                                             (int*) out.trianglelist);   
    266   */ 
     263                                            (char*) out.trianglelist);
     264   
    267265  /* Add pointlist */
    268266  dimensions[0] = out.numberofpoints;
    269267  dimensions[1] = 2;   
    270  
    271   /*genpointlist = (PyArrayObject *) PyArray_FromDims(2,
    272                                                     dimensions,
    273                                                     PyArray_DOUBLE);
    274   */
     268  genpointlist = (PyArrayObject *) PyArray_FromDimsAndData(2,
     269                                         dimensions,
     270                                         PyArray_DOUBLE,
     271                                         (char*) out.pointlist);
     272                                           
    275273  /*                                             
    276274  (double*) genpointlist -> data = out.pointlist;               
    277275  ((double*) genpointlist -> data) = out.pointlist;
    278276  ( genpointlist -> data) = (double*) out.pointlist;
     277   genpointlist -> data = (double) out.pointlist;
    279278 
    280279  */
    281   //genpointlist -> data = out.pointlist;
    282  
    283  
    284   genpointlist = PyArray_FromDimsAndData(2,
    285                                          dimensions,
    286                                          PyArray_DOUBLE,
    287                                          (char*) out.pointlist); 
    288  
    289  
    290280 
    291281  /* Add point marker list */
    292282  dimensions[0] = out.numberofpoints;
    293   genpointmarkerlist = (PyArrayObject *) PyArray_FromDims(1,
    294                                                           dimensions,
    295                                                           PyArray_INT);
    296   genpointmarkerlist -> data = out.pointmarkerlist;
     283  genpointmarkerlist = (PyArrayObject *) PyArray_FromDimsAndData(1,
     284                                        dimensions,
     285                                         PyArray_INT,
     286                                        (char*) out.pointmarkerlist);
    297287 
    298288  /* Add point attribute list */
    299289  dimensions[0] = out.numberofpoints;
    300290  dimensions[1] = out.numberofpointattributes;   
    301   genpointattributelist = (PyArrayObject *) PyArray_FromDims(2,
    302                                                 dimensions,
    303                                                  PyArray_DOUBLE);
    304   genpointattributelist -> data = out.pointattributelist;       
     291  genpointattributelist = (PyArrayObject *) PyArray_FromDimsAndData(2,
     292                                          dimensions,
     293                                          PyArray_DOUBLE,
     294                                          (char*) out.pointattributelist);
    305295 
    306296 
     
    309299  dimensions[0] = out.numberoftriangles;
    310300  dimensions[1] = out.numberoftriangleattributes;   
    311   gentriangleattributelist = (PyArrayObject *) PyArray_FromDims(2,
    312                                                 dimensions,
    313                                                  PyArray_DOUBLE);
    314   gentriangleattributelist -> data = out.triangleattributelist;
     301  gentriangleattributelist = (PyArrayObject *) PyArray_FromDimsAndData(2,
     302                                          dimensions,
     303                                           PyArray_DOUBLE,
     304                                          (char*)out.triangleattributelist);
    315305 
    316306  /* Add segment list */
    317307  dimensions[0] = out.numberofsegments;
    318308  dimensions[1] = 2;   
    319   gensegmentlist = (PyArrayObject *) PyArray_FromDims(2,
     309  gensegmentlist = (PyArrayObject *) PyArray_FromDimsAndData(2,
    320310                                                    dimensions,
    321                                                     PyArray_INT);
    322   gensegmentlist -> data = out.segmentlist;
     311                                                    PyArray_INT,
     312                                                    (char*)out.segmentlist);
    323313 
    324314 
    325315  /* Add segment marker list */
    326316  dimensions[0] = out.numberofsegments;
    327   gensegmentmarkerlist = (PyArrayObject *) PyArray_FromDims(1,
    328                                                     dimensions,
    329                                                     PyArray_INT);
    330   gensegmentmarkerlist -> data = out.segmentmarkerlist;
     317  gensegmentmarkerlist = (PyArrayObject *) PyArray_FromDimsAndData(1,
     318                                            dimensions,
     319                                            PyArray_INT,
     320                                           (char*)out.segmentmarkerlist);
    331321 
    332322  /* Add triangle neighbor list */
    333   dimensions[0] = out.numberoftriangles;
    334   dimensions[1] = 3;   
    335   genneighborlist = (PyArrayObject *) PyArray_FromDims(2,
    336                                                     dimensions,
    337                                                     PyArray_INT);
    338   genneighborlist -> data = out.neighborlist;
    339  
     323  if (out.neighborlist != NULL) {
     324    dimensions[0] = out.numberoftriangles;
     325    dimensions[1] = 3;   
     326    genneighborlist = (PyArrayObject *) PyArray_FromDimsAndData(2,
     327                                                 dimensions,
     328                                                 PyArray_INT,
     329                                                 (char*)out.neighborlist);
     330  }else{
     331    dimensions[0] = 0;
     332    dimensions[1] = 0;   
     333    genneighborlist = (PyArrayObject *) PyArray_FromDims(2,
     334                                                         dimensions,
     335                                                         PyArray_INT);
     336  }
    340337 
    341338  /* Add triangle neighbor list */
     
    356353   */
    357354 
    358  
    359   /* Free in/out structure memory */
    360  
    361   /* OUT */
    362 
    363   if(!out.pointlist){
    364     free(out.pointlist);  out.pointlist=NULL;
    365   }
    366   if(!out.pointmarkerlist){   
    367     free(out.pointmarkerlist); out.pointmarkerlist=NULL;
    368   }
    369   if(!out.pointattributelist){   
    370     free(out.pointattributelist); out.pointattributelist=NULL;
    371   }   
    372   if(!out.trianglelist){   
    373     free(out.trianglelist); out.trianglelist=NULL;
    374   }
    375   if(!out.triangleattributelist){   
    376     free(out.triangleattributelist); out.triangleattributelist=NULL;
    377   }
    378   if(!out.trianglearealist){   
    379     free(out.trianglearealist); out.trianglearealist=NULL;
    380   }
    381   if(!out.neighborlist){   
    382     free(out.neighborlist); out.neighborlist=NULL;
    383   }
    384   if(!out.segmentlist){
    385     free(out.segmentlist); out.segmentlist =NULL;
    386   }
    387   if(!out.segmentmarkerlist){
    388     free(out.segmentmarkerlist); out.segmentmarkerlist  =NULL;
    389   }
    390   if(!out.edgelist){
    391     free(out.edgelist);  out.edgelist=NULL;
    392   }
    393   if(!out.edgemarkerlist){
    394     free(out.edgemarkerlist);  out.edgemarkerlist=NULL;
    395   }
    396   if(!out.holelist){
    397     free(out.holelist); out.holelist=NULL;
    398   }
    399   if(!out.regionlist){
    400     free(out.regionlist); out.regionlist=NULL;
    401   }
    402355 
    403356  /* R = Py_BuildValue((char *)"O", holder); */
     
    421374  Py_DECREF(gensegmentmarkerlist);
    422375  Py_DECREF(genneighborlist);
     376 
     377 
     378  /* Free in/out structure memory */
     379  /* OUT
     380
     381  if(!out.pointlist){
     382    free(out.pointlist);  out.pointlist=NULL;
     383  }
     384  if(!out.pointmarkerlist){   
     385    free(out.pointmarkerlist); out.pointmarkerlist=NULL;
     386  }
     387  if(!out.pointattributelist){   
     388    free(out.pointattributelist); out.pointattributelist=NULL;
     389  }   
     390  if(!in.pointattributelist){   
     391    free(out.pointattributelist); out.pointattributelist=NULL;
     392  }   
     393  if(!out.trianglelist){   
     394    free(out.trianglelist); out.trianglelist=NULL;
     395  }
     396  if(!out.triangleattributelist){   
     397    free(out.triangleattributelist); out.triangleattributelist=NULL;
     398  }
     399  if(!out.trianglearealist){   
     400    free(out.trianglearealist); out.trianglearealist=NULL;
     401  }
     402  if(!out.neighborlist){   
     403    free(out.neighborlist); out.neighborlist=NULL;
     404  }
     405  if(!out.segmentlist){
     406    free(out.segmentlist); out.segmentlist =NULL;
     407  }
     408  if(!out.segmentmarkerlist){
     409    free(out.segmentmarkerlist); out.segmentmarkerlist  =NULL;
     410  }
     411  if(!out.edgelist){
     412    free(out.edgelist);  out.edgelist=NULL;
     413  }
     414  if(!out.edgemarkerlist){
     415    free(out.edgemarkerlist);  out.edgemarkerlist=NULL;
     416  }
     417  if(!out.holelist){
     418    free(out.holelist); out.holelist=NULL;
     419  }
     420  if(!out.regionlist){
     421    free(out.regionlist); out.regionlist=NULL;
     422  }
     423    */
    423424  return R;
    424425}
  • anuga_core/source/anuga/mesh_engine/test_generate_mesh.py

    r4899 r4916  
    355355
    356356    def testrectangle_regionsII(self):
    357 
    358357        points = []
    359358        seglist = []
     
    703702
    704703    suite = unittest.makeSuite(triangTestCase,'test')
    705     #suite = unittest.makeSuite(triangTestCase,'test_lone_verts4')
    706     #suite = unittest.makeSuite(triangTestCase,'test_transition_to_arrays')
    707     runner = unittest.TextTestRunner() #verbosity=2)
     704    #suite = unittest.makeSuite(triangTestCase,'testrectangleIIb')
     705    #suite = unittest.makeSuite(triangTestCase,'testsegmarker')
     706    #suite = unittest.makeSuite(triangTestCase,'testrectangle_regionsII')
     707    runner = unittest.TextTestRunner()  #verbosity=2)
    708708    runner.run(suite)
Note: See TracChangeset for help on using the changeset viewer.