Changeset 8847


Ignore:
Timestamp:
Apr 22, 2013, 2:59:58 PM (12 years ago)
Author:
steve
Message:

Small changes to sww2array looking for memory leak

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

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/quantity_ext.c

    r8690 r8847  
    15311531
    15321532  // Release
     1533  Py_DECREF(domain);
    15331534  Py_DECREF(domain_centroids);
    15341535  Py_DECREF(domain_surrogate_neighbours);
  • trunk/anuga_core/source/anuga/file_conversion/calc_grid_values_ext.c

    r8634 r8847  
    412412        long *volumes;
    413413        double nodata_val;
    414         double cell_size;
     414    double cell_size;
    415415        double *x, *y;
    416         double *norms;
     416    double *norms;
    417417        double *result;
    418418        double *grid_val;
    419419        PyObject *pyobj_x;
    420         PyObject *pyobj_y;
    421         PyObject *pyobj_norms;
     420    PyObject *pyobj_y;
     421    PyObject *pyobj_norms;
    422422        PyObject *pyobj_volumes;
    423423        PyObject *pyobj_result;
     
    427427                                &nrow,
    428428                                &ncol,
    429                                 &cell_size,
     429                &cell_size,
    430430                                &nodata_val,
    431431                                &pyobj_x,
    432                                 &pyobj_y,
    433                                 &pyobj_norms,
     432                &pyobj_y,
     433                &pyobj_norms,
    434434                                &pyobj_volumes,
    435435                                &pyobj_result,
     
    446446        // get data from python objects
    447447        x = DDATA( pyobj_x );
    448         y = DDATA( pyobj_y );
    449         norms    = DDATA( pyobj_norms );
     448    y = DDATA( pyobj_y );
     449    norms    = DDATA( pyobj_norms );
    450450        result   = DDATA( pyobj_result );
    451451        grid_val = DDATA( pyobj_grid_val );
     
    455455        num_tri  = ((PyArrayObject*)pyobj_volumes)->dimensions[0];
    456456        num_vert = ((PyArrayObject*)pyobj_x)->dimensions[0];
    457         num_norms = ((PyArrayObject*)pyobj_norms)->dimensions[0];
    458         num_grid_val = ((PyArrayObject*)pyobj_grid_val)->dimensions[0];
    459 
    460         //printf("==== %d %d %d %d %d \n",num_norms,num_tri,num_vert,nrow,ncol);
     457    num_norms = ((PyArrayObject*)pyobj_norms)->dimensions[0];
     458    num_grid_val = ((PyArrayObject*)pyobj_grid_val)->dimensions[0];
     459
     460    //printf("==== %d %d %d %d %d \n",num_norms,num_tri,num_vert,nrow,ncol);
    461461
    462462        // init triangle array
  • trunk/anuga_core/source/anuga/file_conversion/sww2array.py

    r8780 r8847  
    2727
    2828# Default block size for sww2dem()
    29 DEFAULT_BLOCK_SIZE = 10000
     29DEFAULT_BLOCK_SIZE = 100000
    3030
    3131def sww2array(name_in,
     
    197197       
    198198        # Get slices of all required variables
    199         q_dict = {}
    200         for name in var_list:
    201             # check if variable has time axis
    202             if len(fid.variables[name].shape) == 2:
    203                 q_dict[name] = fid.variables[name][:,start_slice:end_slice]
    204             else:       # no time axis
    205                 q_dict[name] = fid.variables[name][start_slice:end_slice]
    206 
    207         # Evaluate expression with quantities found in SWW file
    208         res = apply_expression_to_dictionary(quantity, q_dict)
    209 
    210         if len(res.shape) == 2:
    211             new_res = num.zeros(res.shape[1], num.float)
    212             for k in xrange(res.shape[1]):
    213                 if type(reduction) is not types.BuiltinFunctionType:
    214                     new_res[k] = res[reduction,k]
    215                 else:
    216                     new_res[k] = reduction(res[:,k])
    217             res = new_res
     199        if type(reduction) is not types.BuiltinFunctionType:
     200            q_dict = {}
     201            for name in var_list:
     202                # check if variable has time axis
     203                if len(fid.variables[name].shape) == 2:
     204                    print 'avoiding large array'
     205                    q_dict[name] = fid.variables[name][reduction,start_slice:end_slice]
     206                else:       # no time axis
     207                    q_dict[name] = fid.variables[name][start_slice:end_slice]
     208
     209            # Evaluate expression with quantities found in SWW file
     210            res = apply_expression_to_dictionary(quantity, q_dict)
     211
     212#            if len(res.shape) == 2:
     213#                new_res = num.zeros(res.shape[1], num.float)
     214#                for k in xrange(res.shape[1]):
     215#                    if type(reduction) is not types.BuiltinFunctionType:
     216#                        new_res[k] = res[k]
     217#                    else:
     218#                        new_res[k] = reduction(res[:,k])
     219#                res = new_res
     220        else:
     221            q_dict = {}
     222            for name in var_list:
     223                # check if variable has time axis
     224                if len(fid.variables[name].shape) == 2:
     225                    q_dict[name] = fid.variables[name][:,start_slice:end_slice]
     226                else:       # no time axis
     227                    q_dict[name] = fid.variables[name][start_slice:end_slice]
     228
     229            # Evaluate expression with quantities found in SWW file
     230            res = apply_expression_to_dictionary(quantity, q_dict)
     231
     232            if len(res.shape) == 2:
     233                new_res = num.zeros(res.shape[1], num.float)
     234                for k in xrange(res.shape[1]):
     235                    if type(reduction) is not types.BuiltinFunctionType:
     236                        new_res[k] = res[reduction,k]
     237                    else:
     238                        new_res[k] = reduction(res[:,k])
     239                res = new_res
    218240
    219241        result[start_slice:end_slice] = res
     
    282304
    283305
    284 
     306    fid.close()
     307   
    285308    #print outside_indices
    286309
Note: See TracChangeset for help on using the changeset viewer.