Ignore:
Timestamp:
Aug 28, 2007, 2:23:35 PM (17 years ago)
Author:
ole
Message:

Implemented optimisation excluding dry cells from flux calculation.
All tests pass and the script run_okushiri_profile.py reports an improvement
in compute_fluxes from 11.25s to 8.58s or 24% faster.
The overall computation was about 40s, so this optimisation improved the
total running time for the problem in question by 7%.

This partially addresses ticket:135

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/shallow_water/test_shallow_water_domain.py

    r4684 r4685  
    229229        domain.compute_fluxes()
    230230       
    231         print domain.get_quantity('stage').explicit_update
     231        #print domain.get_quantity('stage').explicit_update
    232232        # FIXME (Ole): TODO the general case
    233233        #assert allclose(domain.get_quantity('stage').explicit_update[1], ........??)
     
    13061306
    13071307    #####################################################
    1308     def test_initial_condition(self):
    1309         """Test that initial condition is output at time == 0
     1308
     1309    def test_flux_optimisation(self):
     1310        """test_flux_optimisation
     1311        Test that fluxes are correctly computed using
     1312        dry and still cell exclusions
    13101313        """
    13111314
     
    13441347        domain.set_boundary({'exterior': Reflective_boundary(domain)})
    13451348
     1349
     1350        #  Check that update arrays are initialised to zero
     1351        assert allclose(domain.get_quantity('stage').explicit_update, 0)
     1352        assert allclose(domain.get_quantity('xmomentum').explicit_update, 0)
     1353        assert allclose(domain.get_quantity('ymomentum').explicit_update, 0)               
     1354
     1355
     1356        # Get true values
     1357        domain.optimise_dry_cells = False
     1358        domain.compute_fluxes()
     1359        stage_ref = copy.copy(domain.get_quantity('stage').explicit_update)
     1360        xmom_ref = copy.copy(domain.get_quantity('xmomentum').explicit_update)
     1361        ymom_ref = copy.copy(domain.get_quantity('ymomentum').explicit_update)       
     1362
     1363        # Try with flux optimisation
     1364        domain.optimise_dry_cells = True
     1365        domain.compute_fluxes()
     1366
     1367        assert allclose(stage_ref, domain.get_quantity('stage').explicit_update)
     1368        assert allclose(xmom_ref, domain.get_quantity('xmomentum').explicit_update)
     1369        assert allclose(ymom_ref, domain.get_quantity('ymomentum').explicit_update)
     1370       
     1371   
     1372       
     1373    def test_initial_condition(self):
     1374        """test_initial_condition
     1375        Test that initial condition is output at time == 0 and that
     1376        computed values change as system evolves
     1377        """
     1378
     1379        from anuga.config import g
     1380        import copy
     1381
     1382        a = [0.0, 0.0]
     1383        b = [0.0, 2.0]
     1384        c = [2.0, 0.0]
     1385        d = [0.0, 4.0]
     1386        e = [2.0, 2.0]
     1387        f = [4.0, 0.0]
     1388
     1389        points = [a, b, c, d, e, f]
     1390        #bac, bce, ecf, dbe
     1391        vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]]
     1392
     1393        domain = Domain(points, vertices)
     1394
     1395        #Set up for a gradient of (3,0) at mid triangle (bce)
     1396        def slope(x, y):
     1397            return 3*x
     1398
     1399        h = 0.1
     1400        def stage(x,y):
     1401            return slope(x,y)+h
     1402
     1403        domain.set_quantity('elevation', slope)
     1404        domain.set_quantity('stage', stage)
     1405
     1406        # Allow slope limiters to work (FIXME (Ole): Shouldn't this be automatic in ANUGA?)     
     1407        domain.distribute_to_vertices_and_edges()       
     1408
     1409        initial_stage = copy.copy(domain.quantities['stage'].vertex_values)
     1410
     1411        domain.set_boundary({'exterior': Reflective_boundary(domain)})
     1412
     1413        domain.optimise_dry_cells = True
    13461414        #Evolution
    1347         for t in domain.evolve(yieldstep = 1.0, finaltime = 2.0):
     1415        for t in domain.evolve(yieldstep = 0.5, finaltime = 2.0):
    13481416            stage = domain.quantities['stage'].vertex_values
    13491417
     
    13521420            else:
    13531421                assert not allclose(stage, initial_stage)
     1422
    13541423
    13551424        os.remove(domain.get_name() + '.sww')
     
    47994868       
    48004869if __name__ == "__main__":
    4801     suite = unittest.makeSuite(Test_Shallow_Water,'test_flux_computation')   
     4870
     4871    suite = unittest.makeSuite(Test_Shallow_Water,'test')   
    48024872    #suite = unittest.makeSuite(Test_Shallow_Water,'test_tight_slope_limiters')
    48034873    #suite = unittest.makeSuite(Test_Shallow_Water,'test_get_maximum_inundation_from_sww')
Note: See TracChangeset for help on using the changeset viewer.