source: branches/numpy_anuga_validation/automated_validation_tests/flow_tests/test_inflow_using_flowline.py @ 6788

Last change on this file since 6788 was 6788, checked in by rwilson, 15 years ago

Added Patong and new flow tests. (Again?)

File size: 6.1 KB
Line 
1
2
3"""test_inflow_using_flowline
4Test the ability of a flowline to match inflow above the flowline by
5creating constant inflow onto a circle at the head of a 20m
6wide by 400m long plane dipping at various slopes with a perpendicular flowline and gauge
7downstream of the inflow and a 45 degree flowlines at 200m downstream
8"""
9
10verbose = True
11import numpy as num
12
13#------------------------------------------------------------------------------
14# Import necessary modules
15#------------------------------------------------------------------------------
16from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
17from anuga.shallow_water import Domain
18from anuga.shallow_water.shallow_water_domain import Reflective_boundary
19from anuga.shallow_water.shallow_water_domain import Dirichlet_boundary
20from anuga.shallow_water.shallow_water_domain import Transmissive_Momentum_Set_Stage_boundary
21from anuga.shallow_water.shallow_water_domain import Inflow
22from anuga.shallow_water.data_manager import get_flow_through_cross_section
23from anuga.abstract_2d_finite_volumes.util import sww2csv_gauges, csv2timeseries_graphs
24
25
26#------------------------------------------------------------------------------
27# Setup computational domain
28#------------------------------------------------------------------------------
29
30number_of_inflows = 2 # Number of inflows on top of each other
31finaltime = 1000.0
32
33length = 400.
34width  = 20.
35dx = dy = 2          # Resolution: of grid on both axes
36
37points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy),
38                                               len1=length, len2=width)
39
40for mannings_n in [0.150, 0.070, 0.035, 0.012]:
41    # Loop over a range of roughnesses 
42   
43    for slope in [1.0/300, 1.0/150, 1.0/75]:
44        # Loop over a range of bedslopes 
45       
46
47        domain = Domain(points, vertices, boundary)   
48        domain.set_name('inflow_flowline_test')              # Output name
49
50
51        #----------------------------------------------------------------------
52        # Setup initial conditions
53        #----------------------------------------------------------------------
54
55        def topography(x, y):
56            z=-x * slope
57            return z
58
59        domain.set_quantity('elevation', topography)  # Use function for elevation
60        domain.set_quantity('friction', mannings_n)   # Constant friction of conc surface   
61        domain.set_quantity('stage',
62                            expression='elevation')   # Dry initial condition
63
64
65        #----------------------------------------------------------------------
66        # Seup Inflow and compute flow characteristics
67        #----------------------------------------------------------------------
68
69        # Fixed Flowrate onto Area
70        fixed_inflow = Inflow(domain,
71                              center=(10.0, 10.0),
72                              radius=5.00,
73                              rate=10.00)   
74       
75        # Stack this flow
76        for i in range(number_of_inflows):
77            domain.forcing_terms.append(fixed_inflow)
78       
79        ref_flow = fixed_inflow.rate*number_of_inflows
80       
81        # Compute normal depth on plane using Mannings equation
82        # v=1/n*(r^2/3)*(s^0.5) or r=(Q*n/(s^0.5*W))^0.6
83        normal_depth=(ref_flow*mannings_n/(slope**0.5*width))**0.6
84        flow_velocity = ref_flow/(width*normal_depth)
85        froude_no = flow_velocity/(9.8*normal_depth)**0.5
86        if verbose:
87            print
88            print 'Slope:', slope, 'Mannings n:', mannings_n, 'Velocity:',flow_velocity,'Froude:',froude_no
89
90
91        #----------------------------------------------------------------------
92        # Setup boundary conditions
93        #----------------------------------------------------------------------
94
95        Br = Reflective_boundary(domain)              # Solid reflective wall
96        #Bo = Dirichlet_boundary([-(slope*length)+normal_depth, 0, 0])  # Outflow stage at normal depth
97        def normal_depth_stage_downstream(t):
98            return (-slope*length) + normal_depth
99        Bt = Transmissive_Momentum_Set_Stage_boundary(domain=domain,function=normal_depth_stage_downstream)
100        domain.set_boundary({'left': Br, 'right': Bt, 'top': Br, 'bottom': Br})
101
102        #----------------------------------------------------------------------
103        # Evolve system through time
104        #----------------------------------------------------------------------
105
106        x=200.0      # Reference location for flowlines and gauges
107        y=10.00
108       
109        for t in domain.evolve(yieldstep=100.0, finaltime=finaltime):
110            if verbose :
111                print domain.timestepping_statistics()
112
113
114        #----------------------------------------------------------------------
115        # Compute flow thru flowlines ds of inflow and check against normal depth
116        #----------------------------------------------------------------------
117
118        # Square on flowline at 200m
119        q=domain.get_flow_through_cross_section([[200.0,0.0],[200.0,20.0]])
120        msg = 'Predicted square on flow was %f, should have been %f' % (q, ref_flow)
121        if verbose:
122            print '90 degree flowline: ANUGA = %f, Ref = %f' % (q, ref_flow)
123        assert num.allclose(q, ref_flow, rtol=1.0e-2), msg         
124       
125        # 45 degree flowline at 200m
126        q=domain.get_flow_through_cross_section([[200.0,0.0],[220.0,20.0]])
127        msg = 'Predicted 45 flow was %f, should have been %f' % (q, ref_flow)
128        if verbose:
129            print '45 degree flowline: ANUGA = %f, Ref = %f' % (q, ref_flow)
130        assert num.allclose(q, ref_flow, rtol=1.0e-2), msg         
131
132
133       # Stage recorder (gauge) in middle of plane at 200m
134        w = domain.get_quantity('stage').get_values(interpolation_points=[[x, y]])[0]
135        z = domain.get_quantity('elevation').get_values(interpolation_points=[[x, y]])[0]
136        domain_depth = w-z
137       
138       
139        msg = 'Predicted depth of flow at 200m was %f, should have been %f' % (normal_depth, domain_depth)
140        if verbose:
141            print 'Depth at 200m: ANUGA = %f, Mannings = %f' % (domain_depth, normal_depth)
142        assert num.allclose(domain_depth,normal_depth, rtol=1.0e-2), msg
143
144
145
Note: See TracBrowser for help on using the repository browser.