Changeset 4894


Ignore:
Timestamp:
Dec 21, 2007, 12:44:10 PM (15 years ago)
Author:
duncan
Message:

Good fix for the memory leak found in ticket#189

Location:
anuga_core/source/anuga
Files:
5 edited

Legend:

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

    r4668 r4894  
    227227        self._init_boundary_triangles()
    228228       
    229         del tridata['generatedtriangleneighborlist']
    230         del tridata['generatedpointmarkerlist']
    231         del tridata['generatedpointlist']
    232         #del tridata['generatedpointattributetitlelist']
    233         del tridata['generatedsegmentlist']
    234         del tridata['generatedsegmentmarkerlist']
    235         del tridata['generatedtrianglelist']
    236         del tridata['generatedtriangleattributelist']
    237         del tridata['generatedpointattributelist']
    238229        return
    239230
  • anuga_core/source/anuga/mesh_engine/mesh_engine.py

    r4893 r4894  
    123123    #print "mode", mode
    124124    #print "yeah"
    125     mesh_dict = triang.genMesh(points,segments,holes,regions,
     125    mesh_dict, r_test = triang.genMesh(points,segments,holes,regions,
    126126                          pointatts,segatts, mode, segments.flat)
    127127    mesh_dict['qaz'] = 1 #debugging
     128    ##print "r_test", r_test
    128129    return mesh_dict
    129130
  • anuga_core/source/anuga/mesh_engine/mesh_engine_c_layer.c

    r4893 r4894  
    6262#include "Python.h"
    6363
     64//#define PY_ARRAY_UNIQUE_SYMBOL API_YEAH
     65
     66#define PY_ARRAY_UNIQUE_SYMBOL API_YEAH
     67//#define NO_IMPORT_ARRAY
    6468#include "Numeric/arrayobject.h"
    65 
     69#include <sys/types.h>
    6670
    6771 static PyObject *triang_genMesh(PyObject *self, PyObject *args){
     
    214218  /*printf("\n\nTriangulate input args: %s \n\n", mod); */
    215219  triangulate(mod, &in, &out, (struct triangulateio *)NULL );
    216 
     220 
     221 
     222  /*
     223  PyArray_FromDims allolws you to create a Numeric array with unitialized data.
     224   The first argument is the size of the second argument (
     225   the dimensions array).
     226    The dimension array argument is just a 1D C array where each element of
     227     the array is the size of that dimension.
     228     (int dimensions[2] = { 4, 3 }; defines a 4 by 3 array.)
     229     The third argument is just the desired type.
     230  */
     231 
     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 
    217238  /* printf(" ***  back from triangulate\n" );    */
    218239  /*
     
    330351    Py_DECREF(ii); Py_DECREF(holderlist);
    331352  }   
    332   /*
    333   // Testing passing a numeric array out
    334   dimensions[0] = 4;
    335   // Allocate space for return vectors a and b (don't DECREF)
    336   // This is crashing - don't know why
    337   r_test = (PyArrayObject *) PyArray_FromDims(1, dimensions, PyArray_DOUBLE);
    338   */
     353 
     354 
    339355 
    340356  /* Free in/out structure memory */
     
    382398  }
    383399 
    384   /*Py_DECREF(holder);*/
    385   R = Py_BuildValue((char *)"O", holder);
    386   /*Py_DECREF(holder);* Try this to fix memory problems */
     400  /* R = Py_BuildValue((char *)"O", holder); */
     401  R = Py_BuildValue((char *)"OO", holder, PyArray_Return(r_test));
     402  Py_DECREF(holder); /** This fixed a  memory problem ticket#189 */
     403  Py_DECREF(r_test);
    387404  return R;
    388405}
     
    397414void initmesh_engine_c_layer(){
    398415  Py_InitModule((char *)"mesh_engine_c_layer",triang_methods);
     416 
     417  import_array(); // Necessary for handling of NumPY structures
    399418}   
  • anuga_core/source/anuga/pmesh/mesh.py

    r4888 r4894  
    15811581                                                   ObjectNeighbor[2])
    15821582            index += 1
    1583         #genDict['lonepointlist'].sort()
    1584         #genDict['lonepointlist'].reverse()       
    1585         #for loner in genDict['lonepointlist']:
    1586             # Remove the loner vertex
    1587             #print "Removing the loner", loner
    1588             #self.meshVertices.pop(loner)
    1589         # delete the info from this data structure
    1590         del genDict['generatedtriangleneighborlist']
    1591         del genDict['generatedpointmarkerlist']
    1592         del genDict['generatedpointlist']
    1593         del genDict['generatedpointattributetitlelist']
    1594         del genDict['generatedsegmentlist']
    1595         del genDict['generatedsegmentmarkerlist']
    1596         del genDict['generatedtrianglelist']
    1597         del genDict['generatedtriangleattributelist']
    1598         del genDict['generatedpointattributelist']
    1599         genDict['zpp'] = 1 # just an identifier
    16001583           
    16011584    def setMesh(self, genDict):
  • anuga_core/source/anuga/shallow_water/benchmark_sww2dem.py

    r4668 r4894  
    1 """Least squares smooting and interpolation.
     1"""Least squares smoothing and interpolation.
    22
    33   measure the speed of least squares.
     
    2525
    2626from Scientific.IO.NetCDF import NetCDFFile
    27 from Numeric import array
     27from Numeric import array, Float
    2828
    2929from anuga.fit_interpolate.interpolate import Interpolate
     
    107107    fid = NetCDFFile(sww_fileName, 'w')
    108108    sww = Write_sww()
    109     sww.header(fid, 0,
     109    sww.store_header(fid, 0,
    110110               len(mesh_dict['triangles']),
    111                len(mesh_dict["vertices"]))
    112     sww.triangulation(fid,
     111               len(mesh_dict["vertices"]),sww_precision=Float)
     112    sww.store_triangulation(fid,
    113113                      mesh_dict["vertices"], mesh_dict['triangles'],
    114114                      elevation)
    115115       
    116116    for time_step in range(10):
    117         sww.quantities(fid,
     117        sww.store_quantities(fid,
    118118                       time=time_step,
    119119                       stage=stage,
Note: See TracChangeset for help on using the changeset viewer.