Changeset 6232 for anuga_validation


Ignore:
Timestamp:
Jan 23, 2009, 2:44:41 AM (16 years ago)
Author:
ole
Message:

Improved test_caching_of_set_quantity - it still needs to be moved to validation suite.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_validation/okushiri_2005/test_caching_of_set_quantity.py

    r6196 r6232  
    2626# Module imports
    2727from anuga.shallow_water import Domain
     28from anuga.caching import cache
     29from anuga.fit_interpolate.fit import _fit_to_mesh
    2830import project
     31import Numeric as num
    2932
     33internal_verbose = False # Verbose used in set_quantity and passed into fit_to_mesh
     34
     35filename=project.bathymetry_filename
     36alpha=0.02
     37from anuga.config import points_file_block_line_size as max_read_lines
    3038
    3139#-------------------------
    3240# Create Domain from mesh
    3341#-------------------------
    34 domain = Domain(project.mesh_filename, use_cache=True, verbose=True)
     42domain = cache(Domain, (project.mesh_filename, {'verbose': True}), verbose=False)
     43
     44# Clear caching of underlying function                                           
     45args = (filename, )
     46kwargs = {'vertex_coordinates': None,
     47          'triangles': None,
     48          'mesh': domain.mesh,
     49          'point_attributes': None,
     50          'alpha': alpha,
     51          'verbose': internal_verbose,
     52          'acceptable_overshoot': 1.01, # This is the default value in _fit_to_mesh
     53          'mesh_origin': None,
     54          'data_origin': None,
     55          'max_read_lines': max_read_lines,
     56          'attribute_name': None
     57          }
     58
     59
     60cache(_fit_to_mesh,
     61      args,
     62      kwargs,
     63      verbose=False,
     64      dependencies=[filename],
     65      clear=True)
     66
     67# Check that cache is empty     
     68flag = cache(_fit_to_mesh,
     69             args,
     70             kwargs,
     71             verbose=False,
     72             dependencies=[filename],
     73             test=True)
     74assert flag is None
     75
    3576
    3677
     
    3879# Initial Conditions
    3980#-------------------------
    40 print 'Set elevation and cache'
     81#print 'Set elevation and cache'
    4182domain.set_quantity('elevation',
    42                     filename=project.bathymetry_filename,
     83                    filename=filename,
    4384                    alpha=0.02,                   
    44                     verbose=True,
     85                    verbose=internal_verbose,
    4586                    use_cache=True)
     87                   
     88ref = domain.get_quantity('elevation').get_values()                   
    4689
    47 print 'Try to read in via cache'
     90# Check that cache is now present (and correct)
     91flag = cache(_fit_to_mesh,
     92             args,
     93             kwargs,
     94             verbose=False,
     95             dependencies=[filename],
     96             test=True)
     97assert flag is not None
     98res = domain.get_quantity('elevation').get_values()                                       
     99assert num.allclose(res, ref)
     100
     101# Now check this using the high level call
     102#print 'Try to read in via cache'
    48103domain.set_quantity('elevation',
    49                     filename=project.bathymetry_filename,
     104                    filename=filename,
    50105                    alpha=0.02,                   
    51                     verbose=True,
     106                    verbose=internal_verbose,
    52107                    use_cache=True)
     108                   
     109res = domain.get_quantity('elevation').get_values()                                       
     110assert num.allclose(res, ref)
Note: See TracChangeset for help on using the changeset viewer.