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

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