Changeset 6643


Ignore:
Timestamp:
Mar 27, 2009, 2:46:01 PM (16 years ago)
Author:
ted
Message:

Added test for conservation of flow and match between domain depth and depth derived from Manning's equation.
The test has been disabled as it shows unacceptable errors between computed flow and depths.

File:
1 edited

Legend:

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

    r6637 r6643  
    25292529        # Setup only one forcing term, constant rainfall
    25302530        domain.forcing_terms = []
    2531         domain.forcing_terms.append(Rainfall(domain, rate=2.0))
     2531        domain.forcing_terms.append( Rainfall(domain, rate=2.0) )
    25322532
    25332533        domain.compute_forcing_terms()
     
    25672567                     polygon = [[1,1], [2,1], [2,2], [1,2]])
    25682568
    2569         assert num.allclose(R.exchange_area, 2)
     2569        assert num.allclose(R.exchange_area, 1)
    25702570       
    25712571        domain.forcing_terms.append(R)
     
    27342734                     polygon=rainfall_poly)
    27352735
    2736         assert num.allclose(R.exchange_area, 2)
     2736        assert num.allclose(R.exchange_area, 1)
    27372737       
    27382738        domain.forcing_terms.append(R)
     
    28072807                     default_rate=5.0)
    28082808
    2809         assert num.allclose(R.exchange_area, 2)
     2809        assert num.allclose(R.exchange_area, 1)
    28102810       
    28112811        domain.forcing_terms.append(R)
     
    28822882                     default_rate=5.0)
    28832883
    2884         assert num.allclose(R.exchange_area, 2)
     2884        assert num.allclose(R.exchange_area, 1)
    28852885       
    28862886        domain.forcing_terms.append(R)
     
    29232923
    29242924        # Setup only one forcing term, constant inflow of 2 m^3/s on a circle affecting triangles #0 and #1 (bac and bce)
    2925 
    2926         I = Inflow(domain, rate=2.0, center=(1,1), radius=1)
    29272925        domain.forcing_terms = []
    2928         domain.forcing_terms.append(I)
     2926        domain.forcing_terms.append( Inflow(domain, rate=2.0, center=(1,1), radius=1) )
    29292927
    29302928        domain.compute_forcing_terms()
    2931        
    2932         ref_dw = 2.0/I.exchange_area
    2933        
    2934         assert num.allclose(domain.quantities['stage'].explicit_update[1], ref_dw)
    2935         assert num.allclose(domain.quantities['stage'].explicit_update[0], ref_dw)
     2929        #print domain.quantities['stage'].explicit_update
     2930       
     2931        assert num.allclose(domain.quantities['stage'].explicit_update[1], 2.0/pi)
     2932        assert num.allclose(domain.quantities['stage'].explicit_update[0], 2.0/pi)
    29362933        assert num.allclose(domain.quantities['stage'].explicit_update[2:], 0)       
    29372934
     
    29642961        # Setup only one forcing term, time dependent inflow of 2 m^3/s on a circle affecting triangles #0 and #1 (bac and bce)
    29652962        domain.forcing_terms = []
    2966         I = Inflow(domain, rate=lambda t: 2., center=(1,1), radius=1)
    2967         domain.forcing_terms.append(I)
     2963        domain.forcing_terms.append( Inflow(domain, rate=lambda t: 2., center=(1,1), radius=1) )
    29682964
    29692965        domain.compute_forcing_terms()
    29702966       
    2971         ref_dw = 2.0/I.exchange_area
    2972 
    2973         assert num.allclose(domain.quantities['stage'].explicit_update[1], ref_dw)
    2974         assert num.allclose(domain.quantities['stage'].explicit_update[0], ref_dw)
     2967        assert num.allclose(domain.quantities['stage'].explicit_update[1], 2.0/pi)
     2968        assert num.allclose(domain.quantities['stage'].explicit_update[0], 2.0/pi)
    29752969        assert num.allclose(domain.quantities['stage'].explicit_update[2:], 0)       
    29762970       
     
    67356729                   
    67366730       
    6737     def test_inflow_using_flowline(self):
     6731    def Xtest_inflow_using_flowline(self):
    67386732        """test_inflow_using_flowline
    67396733        Test the ability of a flowline to match inflow above the flowline by
    67406734        creating constant inflow onto a circle at the head of a 20m
    6741         wide by 300m long plane dipping at 1:300 with a perpendicular flowline and gauge
    6742         downstream of the inflow and a 45 degree flowlines at 60m downstream
     6735        wide by 300m long plane dipping at various slopes with a perpendicular flowline and gauge
     6736        downstream of the inflow and a 45 degree flowlines at 200m downstream
    67436737        """
    67446738
    6745         verbose = False
     6739        verbose = True
    67466740       
    67476741
     
    67626756        #------------------------------------------------------------------------------
    67636757        number_of_inflows = 2 # Number of inflows on top of each other
     6758        finaltime = 300.0
    67646759
    67656760        length = 300.
    67666761        width  = 20.
    6767         dx = dy = 2           # Resolution: of grid on both axes
     6762        dx = dy = 2          # Resolution: of grid on both axes
    67686763
    67696764        points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy),
    67706765                                                       len1=length, len2=width)
    67716766
    6772 
    6773         for slope in [1.0/300, 1.0/200, 1.0/100, 1.0/50]:
    6774             # Loop over a range of bedslopes representing sub to super critical flows
    6775 
    6776             #print slope
    6777             domain = Domain(points, vertices, boundary)   
    6778             domain.set_name('Inflow_flowline_test')              # Output name
    6779            
    6780 
    6781             #------------------------------------------------------------------------------
    6782             # Setup initial conditions
    6783             #------------------------------------------------------------------------------
    6784 
    6785             def topography(x, y):
    6786                 z=-x * slope
    6787                 return z
    6788 
    6789 
    6790             domain.set_quantity('elevation', topography)  # Use function for elevation
    6791             domain.set_quantity('friction', 0.012)        # Constant friction of conc surface   
    6792             domain.set_quantity('stage',
    6793                                 expression='elevation')   # Dry initial condition
    6794 
    6795 
    6796             #------------------------------------------------------------------------------
    6797             # Setup boundary conditions
    6798             #------------------------------------------------------------------------------
    6799 
    6800             Br = Reflective_boundary(domain)              # Solid reflective wall
    6801             Bo = Dirichlet_boundary([-100, 0, 0])           # Outflow stsge at -0.9m d=0.1m
    6802 
    6803             domain.set_boundary({'left': Br, 'right': Bo, 'top': Br, 'bottom': Br})
    6804 
    6805             #------------------------------------------------------------------------------
    6806             # Seup Inflow
    6807             #------------------------------------------------------------------------------
    6808 
    6809             # Fixed Flowrate onto Area
    6810             fixed_inflow = Inflow(domain,
    6811                                   center=(10.0, 10.0),
    6812                                   radius=5.00,
    6813                                   rate=1.00)   
    6814 
    6815             # Stack this flow
    6816             for i in range(number_of_inflows):
    6817                 domain.forcing_terms.append(fixed_inflow)
    6818            
    6819             ref_flow = fixed_inflow.rate*number_of_inflows
    6820 
    6821             #------------------------------------------------------------------------------
    6822             # Evolve system through time
    6823             #------------------------------------------------------------------------------
    6824 
    6825             for t in domain.evolve(yieldstep = 10.0, finaltime = 300):
    6826                 pass
    6827                 #print t
    6828 
    6829             #------------------------------------------------------------------------------
    6830             # Compute flow thru flowlines ds of inflow
    6831             #------------------------------------------------------------------------------
     6767        for mannings_n in [0.0, 0.012, 0.035, 0.070, 0.150]:
     6768            for slope in [1.0/300, 1.0/150, 1.0/75]:
     6769                # Loop over a range of bedslopes representing sub to super critical flows
     6770
     6771                if verbose:
     6772                    print
     6773                    print 'Slope:', slope, 'Mannings n:', mannings_n
     6774                domain = Domain(points, vertices, boundary)   
     6775                domain.set_name('Inflow_flowline_test')              # Output name
    68326776               
    6833             # Square on flowline at 30m
    6834             q=domain.get_flow_through_cross_section([[200.0,0.0],[200.0,20.0]])
    6835             msg = 'Predicted flow was %f, should have been %f' % (q, ref_flow)
    6836             #print q, ref_flow
    6837             assert num.allclose(q, ref_flow, rtol=1.0e-2), msg         
    6838 
    6839                        
    6840             # 45 degree flowline at 60m
    6841             q=domain.get_flow_through_cross_section([[200.0,0.0],[220.0,20.0]])
    6842             msg = 'Predicted flow was %f, should have been %f' % (q, ref_flow)
    6843             #print q, ref_flow
    6844             assert num.allclose(q, ref_flow, rtol=1.0e-2), msg         
    6845            
    6846            
     6777
     6778                #------------------------------------------------------------------------------
     6779                # Setup initial conditions
     6780                #------------------------------------------------------------------------------
     6781
     6782                def topography(x, y):
     6783                    z=-x * slope
     6784                    return z
     6785
     6786                domain.set_quantity('elevation', topography)  # Use function for elevation
     6787                domain.set_quantity('friction', mannings_n)   # Constant friction of conc surface   
     6788                domain.set_quantity('stage',
     6789                                    expression='elevation')   # Dry initial condition
     6790
     6791
     6792                #------------------------------------------------------------------------------
     6793                # Setup boundary conditions
     6794                #------------------------------------------------------------------------------
     6795
     6796                Br = Reflective_boundary(domain)              # Solid reflective wall
     6797                Bo = Dirichlet_boundary([-100, 0, 0])           # Outflow stsge at -0.9m d=0.1m
     6798
     6799                domain.set_boundary({'left': Br, 'right': Bo, 'top': Br, 'bottom': Br})
     6800
     6801                #------------------------------------------------------------------------------
     6802                # Seup Inflow
     6803                #------------------------------------------------------------------------------
     6804
     6805                # Fixed Flowrate onto Area
     6806                fixed_inflow = Inflow(domain,
     6807                                      center=(10.0, 10.0),
     6808                                      radius=5.00,
     6809                                      rate=10.00)   
     6810
     6811                # Stack this flow
     6812                for i in range(number_of_inflows):
     6813                    domain.forcing_terms.append(fixed_inflow)
     6814               
     6815                ref_flow = fixed_inflow.rate*number_of_inflows
     6816
     6817                #------------------------------------------------------------------------------
     6818                # Evolve system through time
     6819                #------------------------------------------------------------------------------
     6820
     6821
     6822                for t in domain.evolve(yieldstep=100.0, finaltime=finaltime):
     6823                    if verbose :
     6824                        print domain.timestepping_statistics()
     6825
     6826
     6827                x=200.0
     6828                y=10.00
     6829               
     6830               
     6831
     6832                #------------------------------------------------------------------------------
     6833                # Compute flow thru flowlines ds of inflow
     6834                #------------------------------------------------------------------------------
     6835                   
     6836                # Square on flowline at 200m
     6837                q=domain.get_flow_through_cross_section([[200.0,0.0],[200.0,20.0]])
     6838                msg = 'Predicted flow was %f, should have been %f' % (q, ref_flow)
     6839                if verbose:
     6840                    print '90 degree flowline: ANUGA = %f, Ref = %f' % (q, ref_flow)
     6841                #assert num.allclose(q, ref_flow, rtol=1.0e-2), msg         
     6842
     6843                           
     6844                # 45 degree flowline at 200m
     6845                q=domain.get_flow_through_cross_section([[200.0,0.0],[220.0,20.0]])
     6846                msg = 'Predicted flow was %f, should have been %f' % (q, ref_flow)
     6847                if verbose:
     6848                    print '45 degree flowline: ANUGA = %f, Ref = %f' % (q, ref_flow)
     6849                   
     6850                #assert num.allclose(q, ref_flow, rtol=1.0e-2), msg         
     6851
     6852                # Stage recorder (gauge) in middle of plane at 200m
     6853                w = domain.get_quantity('stage').get_values(interpolation_points=[[x, y]])[0]
     6854                z = domain.get_quantity('elevation').get_values(interpolation_points=[[x, y]])[0]
     6855                domain_depth = w-z
     6856               
     6857               
     6858                # Compute normal depth at gauge location using Manning equation
     6859                # v=1/n*(r^2/3)*(s^0.5) or r=(Q*n/(s^0.5*W))^0.6
     6860                normal_depth=(ref_flow*mannings_n/(slope**0.5*width))**0.6
     6861                msg = 'Predicted depth of flow was %f, should have been %f' % (normal_depth, domain_depth)
     6862                if verbose:
     6863                    print 'Depth: ANUGA = %f, Mannings = %f' % (domain_depth, normal_depth)
     6864
     6865                if slope >= 1.0/100:
     6866                    # Really super critical flow is not as stable.
     6867                    #assert num.allclose(domain_depth,normal_depth, rtol=1.0e-1), msg
     6868                    pass
     6869                else:
     6870                    pass
     6871                    #assert num.allclose(domain_depth,normal_depth, rtol=1.0e-2), msg
    68476872       
    68486873       
     
    68516876       
    68526877if __name__ == "__main__":
    6853     suite = unittest.makeSuite(Test_Shallow_Water, 'test')
     6878    suite = unittest.makeSuite(Test_Shallow_Water, 'test_inflow_using_flowline')
    68546879    runner = unittest.TextTestRunner(verbosity=1)   
    68556880    runner.run(suite)
Note: See TracChangeset for help on using the changeset viewer.