source: anuga_validation/okushiri_2005/test_caching_of_set_quantity.py @ 7256

Last change on this file since 7256 was 7040, checked in by rwilson, 15 years ago

Merges from numpy branch to Numeric trunk.

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