Changeset 4278


Ignore:
Timestamp:
Feb 23, 2007, 3:48:22 PM (17 years ago)
Author:
nick
Message:

updated util.file_function so caching occurs at the interpolation_function and not at the _file_function. This caching of the instance object 'domain' was not allowing cache to work.

Location:
anuga_core/source/anuga/abstract_2d_finite_volumes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_util.py

    r4170 r4278  
    960960        domain.starttime = start
    961961        F = file_function(filename + '.tms', domain,
    962                           quantities = ['Attribute0', 'Attribute1', 'Attribute2'])
    963        
    964 
    965         #print F.T
     962                          quantities = ['Attribute0', 'Attribute1', 'Attribute2'],
     963                          use_cache=True)
     964       
     965
    966966        #print F.precomputed_values
    967967        #print 'F(60)', F(60)
  • anuga_core/source/anuga/abstract_2d_finite_volumes/util.py

    r4274 r4278  
    7070              'interpolation_points': interpolation_points,
    7171              'time_thinning': time_thinning,                   
    72               'verbose': verbose}
    73 
    74 
    75     # Call underlying engine with or without caching
    76     if use_cache is True:
    77         try:
    78             from caching import cache
    79         except:
    80             msg = 'Caching was requested, but caching module'+\
    81                   'could not be imported'
    82             raise msg
    83 
    84         f = cache(_file_function,
    85                   args, kwargs,
    86                   dependencies=[filename],
    87                   compression=False,                 
    88                   verbose=verbose)
    89 
    90     else:
    91         f = apply(_file_function,
     72              'verbose': verbose,
     73              'use_cache': use_cache
     74              }
     75
     76    #caching moved to deeper within the function to avoid caching an
     77    #instance of an object, which isn't generally good.
     78    f = apply(_file_function,
    9279                  args, kwargs)
    9380
     
    10592                   quantities=None,
    10693                   interpolation_points=None,
    107                    time_thinning=1,                                               
    108                    verbose=False):
     94                   time_thinning=1,
     95                   verbose=False,
     96                   use_cache=False):
    10997    """Internal function
    11098   
     
    146134                                        interpolation_points,
    147135                                        time_thinning=time_thinning,
    148                                         verbose=verbose)
     136                                        verbose=verbose,
     137                                        use_cache=use_cache)
    149138    else:
    150139        raise 'Must be a NetCDF File'
     
    157146                             interpolation_points=None,
    158147                             time_thinning=1,                             
    159                              verbose=False):
     148                             verbose=False,
     149                             use_cache=False):
    160150    """Read time history of spatial data from NetCDF sww file and
    161151    return a callable object f(t,x,y)
     
    325315        vertex_coordinates = triangles = interpolation_points = None         
    326316
    327 
    328     return Interpolation_function(time,
    329                                   quantities,
    330                                   quantity_names,
    331                                   vertex_coordinates,
    332                                   triangles,
    333                                   interpolation_points,
    334                                   time_thinning=time_thinning,
    335                                   verbose=verbose)
    336 
     317   
     318 
     319    args = (time, quantities, quantity_names, vertex_coordinates,
     320            triangles, interpolation_points, )
     321           
     322    kwargs = {'time_thinning': time_thinning,
     323              'verbose': verbose
     324              }
     325#    print'CACHING FROM UTIL.py for interpolation_function', use_cache
     326    from anuga.caching import myhash
     327    if use_cache is True:
     328        from caching import cache
     329       
     330        interpolation_function = cache(Interpolation_function,
     331                                       args, kwargs,
     332                                       verbose=verbose,
     333                                       compression=False)
     334    else:
     335        interpolation_function = apply(Interpolation_function,
     336                                       args, kwargs)
     337#    print 'myhash', myhash(interpolation_function)
     338    return interpolation_function
    337339
    338340
Note: See TracChangeset for help on using the changeset viewer.