Changeset 5868


Ignore:
Timestamp:
Oct 27, 2008, 5:55:58 PM (16 years ago)
Author:
ole
Message:

Added memory caching option for interpolation points.

Location:
anuga_core/source/anuga
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/culvert_flows/Test_Culvert_Flat_Water_Lev.py

    r5864 r5868  
    165165   
    166166   
    167 import sys; sys.exit()
     167#import sys; sys.exit()
    168168# Profiling code
    169169import time
  • anuga_core/source/anuga/fit_interpolate/interpolate.py

    r5864 r5868  
    109109   
    110110    """
    111    
     111
     112    # FIXME(Ole): Probably obsolete since I is precomputed and interpolate_block caches
     113       
    112114    from anuga.caching import cache
    113115   
     
    175177       
    176178        # Initialise variabels
    177         self._A_can_be_reused = False
    178         self._point_coordinates = None
     179        self._A_can_be_reused = False  # FIXME (Ole): Probably obsolete
     180        self._point_coordinates = None # FIXME (Ole): Probably obsolete
     181        self.interpolation_matrices = {} # Store precomputed matrices
    179182       
    180183        FitInterpolate.__init__(self,
     
    301304        # This really should use some kind of caching in cases where
    302305        # interpolation points are reused.
     306        #
     307        # This has now been addressed through an attempt in interpolate_block
    303308
    304309        #print "point_coordinates interpolate.interpolate", point_coordinates
     
    373378        See interpolate for doc info.
    374379        """
     380       
     381        # FIXME (Ole): I reckon we should change the interface so that
     382        # the user can specify the interpolation matrix instead of the
     383        # interpolation points to save time.
     384       
     385       
    375386        if isinstance(point_coordinates, Geospatial_data):
    376387            point_coordinates = point_coordinates.get_data_points(\
     
    379390        # Convert lists to Numeric arrays if necessary
    380391        point_coordinates = ensure_numeric(point_coordinates, Float)
    381         f = ensure_numeric(f, Float)       
    382 
    383         import sys
    384         if use_cache is True and sys.platform != 'win32':
    385             # FIXME (Ole): (Why doesn't this work on windoze?)
    386            
    387             X = cache(self._build_interpolation_matrix_A,
    388                       args=(point_coordinates,),
    389                       kwargs={'verbose': verbose},                       
    390                       verbose=verbose)       
    391         else:
     392        f = ensure_numeric(f, Float)               
     393
     394       
     395        # Hash point_coordinates to memory location and reuse if possible
     396        from anuga.caching import myhash
     397        from Numeric import alltrue
     398       
     399
     400        key = myhash(point_coordinates)
     401       
     402        reuse_A = False       
     403        if self.interpolation_matrices.has_key(key):
     404            X, stored_points = self.interpolation_matrices[key]
     405            if alltrue(stored_points == point_coordinates):
     406                reuse_A = True # Reuse interpolation matrix
     407               
     408        if reuse_A is False:
    392409            X = self._build_interpolation_matrix_A(point_coordinates,
    393                                                    verbose=verbose)   
     410                                                   verbose=verbose)
     411            self.interpolation_matrices[key] = (X, point_coordinates)
     412                                                       
    394413       
    395414        # Unpack result                                       
     
    412431        assert self._A.shape[1] == f.shape[0], msg
    413432
     433       
    414434        # Compute Matrix vector product and return
    415435        return self._get_point_data_z(f)
Note: See TracChangeset for help on using the changeset viewer.