Changeset 5988


Ignore:
Timestamp:
Nov 20, 2008, 2:35:29 PM (15 years ago)
Author:
ole
Message:

Added unit test for forcing terms like Inflow and Rainfall to check that they get the correct time from domain including starttime.

File:
1 edited

Legend:

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

    r5879 r5988  
    24782478        # Setup only one forcing term, constant rainfall restricted to a polygon enclosing triangle #1 (bce)
    24792479        domain.forcing_terms = []
    2480         R = Rainfall(domain, rate=2.0, polygon = [[1,1], [2,1], [2,2], [1,2]])
     2480        R = Rainfall(domain,
     2481                     rate=2.0,
     2482                     polygon = [[1,1], [2,1], [2,2], [1,2]])
    24812483
    24822484        assert allclose(R.exchange_area, 1)
     
    24872489        #print domain.quantities['stage'].explicit_update
    24882490       
    2489         assert allclose(domain.quantities['stage'].explicit_update[1], 2.0/1000)
     2491        assert allclose(domain.quantities['stage'].explicit_update[1],
     2492                        2.0/1000)
    24902493        assert allclose(domain.quantities['stage'].explicit_update[0], 0)
    24912494        assert allclose(domain.quantities['stage'].explicit_update[2:], 0)       
     
    25192522        # Setup only one forcing term, time dependent rainfall restricted to a polygon enclosing triangle #1 (bce)
    25202523        domain.forcing_terms = []
    2521         R = Rainfall(domain, rate=lambda t: 3*t + 7, polygon = [[1,1], [2,1], [2,2], [1,2]])
     2524        R = Rainfall(domain,
     2525                     rate=lambda t: 3*t + 7,
     2526                     polygon = [[1,1], [2,1], [2,2], [1,2]])
    25222527
    25232528        assert allclose(R.exchange_area, 1)
     
    25312536        #print domain.quantities['stage'].explicit_update
    25322537       
    2533         assert allclose(domain.quantities['stage'].explicit_update[1], (3*domain.time+7)/1000)
     2538        assert allclose(domain.quantities['stage'].explicit_update[1],
     2539                        (3*domain.time+7)/1000)
    25342540        assert allclose(domain.quantities['stage'].explicit_update[0], 0)
    25352541        assert allclose(domain.quantities['stage'].explicit_update[2:], 0)       
    25362542       
     2543
     2544
     2545
     2546    def test_time_dependent_rainfall_using_starttime(self):
     2547
     2548        a = [0.0, 0.0]
     2549        b = [0.0, 2.0]
     2550        c = [2.0, 0.0]
     2551        d = [0.0, 4.0]
     2552        e = [2.0, 2.0]
     2553        f = [4.0, 0.0]
     2554
     2555        points = [a, b, c, d, e, f]
     2556        #bac, bce, ecf, dbe
     2557        vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]]
     2558
     2559
     2560        domain = Domain(points, vertices)
     2561
     2562        #Flat surface with 1m of water
     2563        domain.set_quantity('elevation', 0)
     2564        domain.set_quantity('stage', 1.0)
     2565        domain.set_quantity('friction', 0)
     2566
     2567        Br = Reflective_boundary(domain)
     2568        domain.set_boundary({'exterior': Br})
     2569
     2570        # Setup only one forcing term, time dependent rainfall restricted to a polygon enclosing triangle #1 (bce)
     2571        domain.forcing_terms = []
     2572        R = Rainfall(domain,
     2573                     rate=lambda t: 3*t + 7,
     2574                     polygon = [[1,1], [2,1], [2,2], [1,2]])
     2575
     2576        assert allclose(R.exchange_area, 1)
     2577       
     2578        domain.forcing_terms.append(R)
     2579
     2580        # This will test that time used in the forcing function takes
     2581        # startime into account.
     2582        domain.starttime = 5.0
     2583
     2584        domain.time = 7.
     2585
     2586        domain.compute_forcing_terms()
     2587        #print domain.quantities['stage'].explicit_update
     2588
     2589        #print domain.get_time()
     2590        assert allclose(domain.quantities['stage'].explicit_update[1],
     2591                        (3*domain.get_time()+7)/1000)
     2592        assert allclose(domain.quantities['stage'].explicit_update[1],
     2593                        (3*(domain.time + domain.starttime)+7)/1000)
     2594
     2595        # Using internal time her should fail
     2596        assert not allclose(domain.quantities['stage'].explicit_update[1],
     2597                        (3*domain.time+7)/1000)               
     2598
     2599        assert allclose(domain.quantities['stage'].explicit_update[0], 0)
     2600        assert allclose(domain.quantities['stage'].explicit_update[2:], 0)       
     2601       
     2602
     2603
    25372604
    25382605
     
    25742641       
    25752642        domain.forcing_terms = []
    2576         R = Rainfall(domain, rate=main_rate, polygon = [[1,1], [2,1], [2,2], [1,2]],
     2643        R = Rainfall(domain,
     2644                     rate=main_rate,
     2645                     polygon = [[1,1], [2,1], [2,2], [1,2]],
    25772646                     default_rate=5.0)
    25782647
     
    61686237    #suite = unittest.makeSuite(Test_Shallow_Water,'test_tight_slope_limiters')
    61696238    #suite = unittest.makeSuite(Test_Shallow_Water,'test_get_maximum_inundation_from_sww')
    6170     #suite = unittest.makeSuite(Test_Shallow_Water,'test_time_dependent_rainfall_restricted_by_polygon')   
     6239    #suite = unittest.makeSuite(Test_Shallow_Water,'test_time_dependent_rainfall_using_starttime')   
    61716240   
    61726241
Note: See TracChangeset for help on using the changeset viewer.