source: anuga_validation/automated_validation_tests/okushiri_tank_validation/test_caching_of_set_quantity.py @ 7666

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

Merged numpy branch back into the trunk.

In ~/sandpit/anuga/anuga_core/source
svn merge -r 6246:HEAD ../../branches/numpy .

In ~/sandpit/anuga/anuga_validation
svn merge -r 6417:HEAD ../branches/numpy_anuga_validation .

In ~/sandpit/anuga/misc
svn merge -r 6809:HEAD ../branches/numpy_misc .

For all merges, I used numpy version where conflicts existed

The suites test_all.py (in source/anuga) and validate_all.py passed using Python2.5 with numpy on my Ubuntu Linux box.

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# Module imports
11from anuga.shallow_water import Domain
12from anuga.caching import cache
13from anuga.fit_interpolate.fit import _fit_to_mesh
14import project
15import numpy as num
16import time
17
18internal_verbose = True # Verbosity used within this function
19
20filename=project.bathymetry_filename
21alpha=0.02
22from anuga.config import points_file_block_line_size as max_read_lines
23
24#-------------------------
25# Create Domain from mesh
26#-------------------------
27domain = cache(Domain, 
28               (project.mesh_filename, 
29                {'verbose': True}), 
30               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# Initial Conditions
66#-------------------------
67t0 = time.time()
68domain.set_quantity('elevation',
69                    filename=filename,
70                    alpha=0.02,                   
71                    verbose=internal_verbose,
72                    use_cache=True)
73compute_time = time.time()-t0
74                   
75ref = domain.get_quantity('elevation').get_values()                   
76
77# Check that cache is now present (and correct)
78flag = cache(_fit_to_mesh,
79             args, 
80             kwargs,
81             verbose=False,
82             dependencies=[filename],
83             test=True)
84             
85assert flag is not None
86res = domain.get_quantity('elevation').get_values()
87assert num.allclose(res, ref)
88
89# Now check this using the high level call
90print 'Try to read in via cache'
91t0 = time.time()
92domain.set_quantity('elevation',
93                    filename=filename,
94                    alpha=0.02,                   
95                    verbose=internal_verbose,
96                    use_cache=True)
97cache_time = time.time()-t0                   
98                   
99res = domain.get_quantity('elevation').get_values() 
100assert num.allclose(res, ref)
101
102print 'cache_time', cache_time
103print 'compute_time', compute_time
104
105msg = 'Caching did not speed things up as expected'
106msg += 'Compute time = %.f, Cache time = %.f' % (compute_time,
107                                                 cache_time)
108assert cache_time < compute_time/10, msg
Note: See TracBrowser for help on using the repository browser.