Changeset 4253


Ignore:
Timestamp:
Feb 12, 2007, 4:20:27 PM (18 years ago)
Author:
duncan
Message:

fiddling with cache calls for fit to mesh

Files:
4 edited

Legend:

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

    r4252 r4253  
    738738        coordinates = self.domain.get_nodes(absolute=True)
    739739        triangles = self.domain.triangles      #FIXME
    740 
    741 
    742         # Use caching at this level until loading has been fixed.
    743         if use_cache is True:
    744             from anuga.caching import cache
    745             vertex_attributes = cache(fit_to_mesh,
    746                                       (coordinates, triangles, filename),
    747                                       {'alpha': alpha,
    748                                        'attribute_name': attribute_name,
    749                                        'use_cache': False,
    750                                        'verbose': verbose,
    751                                        'max_read_lines':max_read_lines},
    752                                       verbose=verbose)
    753         else:
    754             vertex_attributes = fit_to_mesh(coordinates, triangles,filename,
    755                                             alpha=alpha,
    756                                             attribute_name=attribute_name,
    757                                             use_cache=use_cache,
    758                                             verbose=verbose,
    759                                              max_read_lines=max_read_lines)
    760            
    761                                
     740       
     741        vertex_attributes = fit_to_mesh(coordinates, triangles,filename,
     742                                        alpha=alpha,
     743                                        attribute_name=attribute_name,
     744                                        use_cache=use_cache,
     745                                        verbose=verbose,
     746                                        max_read_lines=max_read_lines)
     747                                           
    762748        #Call underlying method using array values
    763749        self.set_values_from_array(vertex_attributes,
    764750                                   location, indices, verbose)
    765 
    766         #geospatial_data = Geospatial_data(filename)
    767        
    768         #self.set_values_from_geospatial_data(geospatial_data,
    769         #                                     alpha,
    770          #                                    location, indices,
    771           #                                   verbose = verbose,
    772            #                                  use_cache = use_cache)
    773751
    774752   
  • anuga_core/source/anuga/fit_interpolate/fit.py

    r4252 r4253  
    433433                attribute_name=None,
    434434                use_cache = False):
     435    args = (vertex_coordinates, triangles, point_coordinates, )
     436    kwargs = {'point_attributes': point_attributes,
     437              'alpha': alpha,
     438              'verbose': verbose,
     439              'acceptable_overshoot': acceptable_overshoot,
     440              'mesh_origin': mesh_origin,
     441              'data_origin': data_origin,
     442              'max_read_lines': max_read_lines,
     443              'attribute_name': attribute_name
     444              }
     445    if use_cache is True:
     446        return cache(_fit_to_mesh,
     447                     args, kwargs,
     448                     verbose=verbose,
     449                     compression=False)
     450    else:
     451        return apply(_fit_to_mesh,
     452                     args, kwargs)
     453
     454def _fit_to_mesh(vertex_coordinates,
     455                triangles,
     456                point_coordinates, # this can also be a .csv/.txt file name
     457                point_attributes=None,
     458                alpha=DEFAULT_ALPHA,
     459                verbose=False,
     460                acceptable_overshoot=1.01,
     461                mesh_origin=None,
     462                data_origin=None,
     463                max_read_lines=None,
     464                attribute_name=None,
     465                use_cache = False):
    435466    """
    436467    Fit a smooth surface to a triangulation,
  • anuga_core/source/anuga/fit_interpolate/test_fit.py

    r4203 r4253  
    279279        os.remove(txt_file)
    280280       
     281    def cache_test_fit_to_mesh_pts(self):
     282        a = [-1.0, 0.0]
     283        b = [3.0, 4.0]
     284        c = [4.0,1.0]
     285        d = [-3.0, 2.0] #3
     286        e = [-1.0,-2.0]
     287        f = [1.0, -2.0] #5
     288
     289        vertices = [a, b, c, d,e,f]
     290        triangles = [[0,1,3], [1,0,2], [0,4,5], [0,5,2]] #abd bac aef afc
     291
     292
     293        fileName = tempfile.mktemp(".txt")
     294        file = open(fileName,"w")
     295        file.write(" x, y, elevation \n\
     296-2.0, 2.0, 0.\n\
     297-1.0, 1.0, 0.\n\
     2980.0, 2.0 , 2.\n\
     2991.0, 1.0 , 2.\n\
     300 2.0,  1.0 ,3. \n\
     301 0.0,  0.0 , 0.\n\
     302 1.0,  0.0 , 1.\n\
     303 0.0,  -1.0, -1.\n\
     304 -0.2, -0.5, -0.7\n\
     305 -0.9, -1.5, -2.4\n\
     306 0.5,  -1.9, -1.4\n\
     307 3.0,  1.0 , 4.\n")
     308        file.close()
     309        geo = Geospatial_data(fileName)
     310        fileName_pts = tempfile.mktemp(".pts")
     311        points = geo.get_data_points(absolute=True)
     312        atts = geo.get_attributes()
     313        f = fit_to_mesh(vertices, triangles,points,atts,
     314                                alpha=0.0, max_read_lines=2,
     315                        use_cache=True, verbose=True)
     316        answer = linear_function(vertices)
     317        #print "f\n",f
     318        #print "answer\n",answer
     319        assert allclose(f, answer)
     320        os.remove(fileName)
     321       
    281322    def test_fit_to_mesh_pts(self):
    282323        a = [-1.0, 0.0]
     
    311352        geo.export_points_file(fileName_pts)
    312353        f = fit_to_mesh(vertices, triangles,fileName_pts,
    313                                 alpha=0.0, max_read_lines=2) #,
    314                         #use_cache=True, verbose=True)
     354                                alpha=0.0, max_read_lines=2)
    315355        answer = linear_function(vertices)
    316356        #print "f\n",f
     
    319359        os.remove(fileName)
    320360        os.remove(fileName_pts)
    321        
     361        
    322362    def test_fit_to_mesh(self):
    323363
     
    729769if __name__ == "__main__":
    730770    suite = unittest.makeSuite(Test_Fit,'test')
    731     #suite = unittest.makeSuite(Test_Fit,'test_fit_to_mesh_UTM_file')
    732     #suite = unittest.makeSuite(Test_Fit,'test_smooth_attributes_to_mesh_one_point')
     771    #suite = unittest.makeSuite(Test_Fit,'cache_test_fit_to_mesh_pts')
     772    #suite = unittest.makeSuite(Test_Fit,'')
    733773    runner = unittest.TextTestRunner(verbosity=1)
    734774    runner.run(suite)
  • anuga_validation/automated_validation_tests/okushiri_tank_validation/loading_pts_test.py

    r4252 r4253  
    5050bathymetry_filename='Benchmark_2_Bathymetry_very_thin.pts'
    5151print 'Starting domain.set_quantity.  Loading ', bathymetry_filename
    52 s = "domain.set_quantity('elevation',filename=bathymetry_filename,alpha=0.02,verbose=True,use_cache=False)"
     52s = "domain.set_quantity('elevation',filename=bathymetry_filename,alpha=0.02,verbose=True,use_cache=True)"
    5353
    5454
     
    6262S = pstats.Stats(FN)
    6363#S.sort_stats('time').print_stats(20)
    64 s = S.sort_stats('cumulative').print_stats(30)
     64s = S.sort_stats('cumulative').print_stats(60)
    6565
    66 print s
     66#print s
Note: See TracChangeset for help on using the changeset viewer.