Ignore:
Timestamp:
Apr 14, 2010, 6:53:12 PM (14 years ago)
Author:
hudson
Message:

Ticket 344 completed and unit tests pass.
Stripped out a heap of tabs and replaced them with 4 spaces.
Removed some redundant imports and deprecated functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/fit_interpolate/interpolate.py

    r7682 r7685  
    155155                                 use_cache=use_cache,
    156156                                 verbose=verbose,
    157                                                                 output_centroids=output_centroids)
     157                                output_centroids=output_centroids)
    158158
    159159    return result
     
    230230                    start_blocking_len=500000,
    231231                    verbose=False,
    232                                         output_centroids=False):
     232                    output_centroids=False):
    233233        """Interpolate mesh data f to determine values, z, at points.
    234234
     
    324324    # @param use_cache True if caching should be used to accelerate the calculations
    325325    # @param verbose True if this function is verbose.
    326     # @return ??
     326    # @return interpolated f
    327327    def interpolate_block(self, f, point_coordinates,
    328328                          use_cache=False, verbose=False, output_centroids=False):
     
    407407    ##
    408408    # @brief Get interpolated data at given points.
    409         #        Applies a transform to all points to calculate the
    410         #        interpolated values. Points outside the mesh are returned as NaN.
    411         # @note self._A matrix must be valid
     409    #        Applies a transform to all points to calculate the
     410    #        interpolated values. Points outside the mesh are returned as NaN.
     411    # @note self._A matrix must be valid
    412412    # @param f Array of arbitrary data
    413413    # @param verbose True if this function is to be verbose.
     
    431431    # @brief Build NxM interpolation matrix.
    432432    # @param point_coordinates Points to sample at
    433         # @param output_centroids set to True to always sample from the centre
    434         #                         of the intersected triangle, instead of the intersection
    435         #                         point.
     433    # @param output_centroids set to True to always sample from the centre
     434    #                         of the intersected triangle, instead of the intersection
     435    #                         point.
    436436    # @param verbose True if this function is to be verbose.
    437437    # @return Interpolation matrix A, plus lists of the points inside and outside the mesh
    438         #         and the list of centroids, if requested.
     438    #         and the list of centroids, if requested.
    439439    def _build_interpolation_matrix_A(self,
    440440                                      point_coordinates,
     
    464464        if verbose: log.critical('Getting indices inside mesh boundary')
    465465
    466         inside_poly_indices, outside_poly_indices = \
     466        # Quick test against boundary, but will not deal with holes in the mesh
     467        inside_boundary_indices, outside_poly_indices = \
    467468            in_and_outside_polygon(point_coordinates,
    468469                                   self.mesh.get_boundary_polygon(),
     
    474475
    475476        # Since you can block, throw a warning, not an error.
    476         if verbose and 0 == len(inside_poly_indices):
     477        if verbose and 0 == len(inside_boundary_indices):
    477478            log.critical('WARNING: No points within the mesh!')
    478479
     
    485486        A = Sparse(n,m)
    486487
    487         n = len(inside_poly_indices)
     488        n = len(inside_boundary_indices)
    488489
    489490        centroids = []
    490                
     491       
     492        inside_poly_indices = []
     493       
    491494        # Compute matrix elements for points inside the mesh
    492495        if verbose: log.critical('Building interpolation matrix from %d points'
    493496                                 % n)
    494497
    495         for d, i in enumerate(inside_poly_indices):
     498        for d, i in enumerate(inside_boundary_indices):
    496499            # For each data_coordinate point
    497500            if verbose and d%((n+10)/10)==0: log.critical('Doing %d of %d'
     
    501504            element_found, sigma0, sigma1, sigma2, k = \
    502505                           search_tree_of_vertices(self.root, x)
     506                       
     507        # Update interpolation matrix A if necessary
     508            if element_found is True:
     509
     510                if verbose:
     511                    print 'Point is within mesh:', d, i           
    503512           
    504             # Update interpolation matrix A if necessary
    505             if element_found is True:
     513                inside_poly_indices.append(i)
     514               
    506515                # Assign values to matrix A
    507516                j0 = self.mesh.triangles[k,0] # Global vertex id for sigma0
     
    509518                j2 = self.mesh.triangles[k,2] # Global vertex id for sigma2
    510519                js = [j0, j1, j2]
    511                                
     520               
    512521                if output_centroids is False:
    513522                    # Weight each vertex according to its distance from x
     
    516525                        A[i, j] = sigmas[j]
    517526                else:
    518                                     # If centroids are needed, weight all 3 vertices equally
     527                    # If centroids are needed, weight all 3 vertices equally
    519528                    for j in js:
    520529                        A[i, j] = 1.0/3.0
    521                     centroids.append(self.mesh.centroid_coordinates[k])                                         
     530                    centroids.append(self.mesh.centroid_coordinates[k])                       
    522531            else:
    523                  # Mesh has a hole - move this point to the outside list
    524 #                 num.delete(inside_poly_indices,[i], axis=0)
    525                  num.append(outside_poly_indices, [i], axis=0)
    526 #                msg = 'Could not find triangle for point', x
    527 #                raise Exception(msg)
     532                if verbose:
     533                    log.critical('Mesh has a hole - moving this point to outside list')
     534
     535                # This is a numpy arrays, so we need to do a slow transfer
     536                outside_poly_indices = num.append(outside_poly_indices, [i], axis=0)
    528537
    529538        return A, inside_poly_indices, outside_poly_indices, centroids
     
    775784                 verbose=False,
    776785                 gauge_neighbour_id=None,
    777                                 output_centroids=False):
     786                output_centroids=False):
    778787        """Initialise object and build spatial interpolation if required
    779788
     
    10031012                                                      verbose=False,
    10041013                                                      output_centroids=output_centroids)
    1005                         self.centroids = interpol.centroids                                                                                                              
     1014                        self.centroids = interpol.centroids                                                         
    10061015                    elif triangles is None and vertex_coordinates is not None:
    10071016                        result = interpolate_polyline(Q,
     
    10121021
    10131022                    #assert len(result), len(interpolation_points)
    1014                     self.precomputed_values[name][i, :] = result                                                                       
    1015                                        
     1023                    self.precomputed_values[name][i, :] = result                                   
     1024                   
    10161025            # Report
    10171026            if verbose:
    1018                 log.critical(self.statistics())                 
     1027                log.critical(self.statistics())           
    10191028        else:
    10201029            # Store quantitites as is
Note: See TracChangeset for help on using the changeset viewer.