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
Line 
1"""This script tests that caching works for set_quantity using point
2data from a file.
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.
6
7This script depends on  Benchmark_2.msh and Benchmark_2_Bathymetry.pts
8"""
9# FIXME(Ole): This needs to become a unit test - in automated validation tests under Okushiri.
10
11# FIXME(Ole): This won't work until ticket:314 has been fixed.
12
13# Module imports
14from anuga.shallow_water import Domain
15from anuga.caching import cache
16from anuga.fit_interpolate.fit import _fit_to_mesh
17import project
18import Numeric as num
19import time
20
21internal_verbose = True # Verbose used in set_quantity and passed into fit_to_mesh
22
23filename=project.bathymetry_filename
24alpha=0.02
25from anuga.config import points_file_block_line_size as max_read_lines
26
27#-------------------------
28# Create Domain from mesh
29#-------------------------
30domain = cache(Domain, (project.mesh_filename, {'verbose': True}), verbose=False)
31
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,
40          'acceptable_overshoot': 1.01, # This is the default value in _fit_to_mesh - actually, not implemented. Remove!
41          'mesh_origin': None,
42          'data_origin': None,
43          'max_read_lines': max_read_lines,
44          'attribute_name': None 
45          }
46
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
66#-------------------------
67# Initial Conditions
68#-------------------------
69#print 'Set elevation and cache'
70t0 = time.time()
71domain.set_quantity('elevation',
72                    filename=filename,
73                    alpha=0.02,                   
74                    verbose=internal_verbose,
75                    use_cache=True)
76compute_time = time.time()-t0
77                   
78ref = domain.get_quantity('elevation').get_values()                   
79
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
92
93print 'Try to read in via cache'
94t0 = time.time()
95domain.set_quantity('elevation',
96                    filename=filename,
97                    alpha=0.02,                   
98                    verbose=internal_verbose,
99                    use_cache=True)
100cache_time = time.time()-t0                   
101                   
102res = domain.get_quantity('elevation').get_values()                                       
103assert num.allclose(res, ref)
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.