source: anuga_validation/okushiri_2005/test_caching_of_set_quantity.py @ 6237

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

Comments regarding ticket:314 and cleanup

File size: 3.3 KB
Line 
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.
5
6This script depends on  Benchmark_2.msh and Benchmark_2_Bathymetry.pts
7"""
8# FIXME(Ole): This needs to become a unit test - in automated validation tests under Okushiri.
9
10# FIXME(Ole): This won't work until ticket:314 has been fixed.
11
12# Module imports
13from anuga.shallow_water import Domain
14from anuga.caching import cache
15from anuga.fit_interpolate.fit import _fit_to_mesh
16import project
17import Numeric as num
18import time
19
20internal_verbose = True # Verbose used in set_quantity and passed into fit_to_mesh
21
22filename=project.bathymetry_filename
23alpha=0.02
24from anuga.config import points_file_block_line_size as max_read_lines
25
26#-------------------------
27# Create Domain from mesh
28#-------------------------
29domain = cache(Domain, (project.mesh_filename, {'verbose': True}), verbose=False)
30
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,
39          'acceptable_overshoot': 1.01, # This is the default value in _fit_to_mesh - actually, not implemented. Remove!
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.