source: anuga_validation/okushiri_2005/test_caching_of_set_quantity.py @ 6498

Last change on this file since 6498 was 6237, checked in by ole, 16 years ago

Comments regarding ticket:314 and cleanup

File size: 3.3 KB
RevLine 
[6237]1"""This script tests that caching works for set_quantity using point data from a file.
2First cache is cleared, then set_quantity is run twice checking that
3fitting is evaluated only first time and that the result from cache on the
4second round is correct.
[5857]5
[6237]6This script depends on  Benchmark_2.msh and Benchmark_2_Bathymetry.pts
[5857]7"""
[6237]8# FIXME(Ole): This needs to become a unit test - in automated validation tests under Okushiri.
[5857]9
[6237]10# FIXME(Ole): This won't work until ticket:314 has been fixed.
[6196]11
[5857]12# Module imports
13from anuga.shallow_water import Domain
[6232]14from anuga.caching import cache
15from anuga.fit_interpolate.fit import _fit_to_mesh
[5857]16import project
[6232]17import Numeric as num
[6237]18import time
[5857]19
[6237]20internal_verbose = True # Verbose used in set_quantity and passed into fit_to_mesh
[5857]21
[6232]22filename=project.bathymetry_filename
23alpha=0.02
24from anuga.config import points_file_block_line_size as max_read_lines
25
[5857]26#-------------------------
27# Create Domain from mesh
28#-------------------------
[6232]29domain = cache(Domain, (project.mesh_filename, {'verbose': True}), verbose=False)
[5857]30
[6232]31# Clear caching of underlying function                                           
32args = (filename, )
33kwargs = {'vertex_coordinates': None,
34          'triangles': None,
35          'mesh': domain.mesh,
36          'point_attributes': None,
37          'alpha': alpha,
38          'verbose': internal_verbose,
[6237]39          'acceptable_overshoot': 1.01, # This is the default value in _fit_to_mesh - actually, not implemented. Remove!
[6232]40          'mesh_origin': None,
41          'data_origin': None,
42          'max_read_lines': max_read_lines,
43          'attribute_name': None 
44          }
[5857]45
[6232]46
47cache(_fit_to_mesh,
48      args, 
49      kwargs,
50      verbose=False,
51      dependencies=[filename],
52      clear=True)
53
54# Check that cache is empty     
55flag = cache(_fit_to_mesh,
56             args, 
57             kwargs,
58             verbose=False,
59             dependencies=[filename],
60             test=True)
61assert flag is None
62
63
64
[5857]65#-------------------------
66# Initial Conditions
67#-------------------------
[6232]68#print 'Set elevation and cache'
[6237]69t0 = time.time()
[5857]70domain.set_quantity('elevation',
[6232]71                    filename=filename,
[5857]72                    alpha=0.02,                   
[6232]73                    verbose=internal_verbose,
[5857]74                    use_cache=True)
[6237]75compute_time = time.time()-t0
[6232]76                   
77ref = domain.get_quantity('elevation').get_values()                   
[5857]78
[6232]79# Check that cache is now present (and correct)
80flag = cache(_fit_to_mesh,
81             args, 
82             kwargs,
83             verbose=False,
84             dependencies=[filename],
85             test=True)
86assert flag is not None
87res = domain.get_quantity('elevation').get_values()                                       
88assert num.allclose(res, ref)
89
90# Now check this using the high level call
[6237]91
92print 'Try to read in via cache'
93t0 = time.time()
[5857]94domain.set_quantity('elevation',
[6232]95                    filename=filename,
[5857]96                    alpha=0.02,                   
[6232]97                    verbose=internal_verbose,
[5857]98                    use_cache=True)
[6237]99cache_time = time.time()-t0                   
[6232]100                   
101res = domain.get_quantity('elevation').get_values()                                       
102assert num.allclose(res, ref)
[6237]103
104print 'cache_time', cache_time
105print 'compute_time', compute_time
106assert cache_time < compute_time/10
Note: See TracBrowser for help on using the repository browser.