source: anuga_validation/okushiri_2005/test_caching_of_set_quantity.py @ 6550

Last change on this file since 6550 was 6550, checked in by ole, 15 years ago

Updated old caching test to work.

File size: 3.1 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
10# FIXME(Ole): This script is obsolete and has been moved into the
11# automatic validation unit test suite.
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 # Verbosity used within this function
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          'mesh_origin': None,
41          'data_origin': None,
42          'max_read_lines': max_read_lines,
43          'attribute_name': None 
44          }
45
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
65#-------------------------
66# Initial Conditions
67#-------------------------
68#print 'Set elevation and cache'
69t0 = time.time()
70domain.set_quantity('elevation',
71                    filename=filename,
72                    alpha=0.02,                   
73                    verbose=internal_verbose,
74                    use_cache=True)
75compute_time = time.time()-t0
76                   
77ref = domain.get_quantity('elevation').get_values()                   
78
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
91
92print 'Try to read in via cache'
93t0 = time.time()
94domain.set_quantity('elevation',
95                    filename=filename,
96                    alpha=0.02,                   
97                    verbose=internal_verbose,
98                    use_cache=True)
99cache_time = time.time()-t0                   
100                   
101res = domain.get_quantity('elevation').get_values()                                       
102assert num.allclose(res, ref)
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.