source: trunk/anuga_core/source/anuga/structures/testing_culvert.py @ 8097

Last change on this file since 8097 was 8097, checked in by habili, 13 years ago

Updating of code and test case

File size: 5.2 KB
Line 
1import os.path
2import sys
3
4from anuga.utilities.system_tools import get_pathname_from_package
5from anuga.geometry.polygon_function import Polygon_function
6       
7from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
8from anuga.abstract_2d_finite_volumes.quantity import Quantity
9
10import anuga
11
12from anuga.structures.boyd_pipe_operator import Boyd_pipe_operator
13from anuga.structures.inlet_operator import Inlet_operator
14                           
15#from anuga.culvert_flows.culvert_routines import boyd_generalised_culvert_model
16     
17from math import pi, pow, sqrt
18
19import numpy as num
20
21
22
23
24
25"""test_that_culvert_runs_rating
26
27This test exercises the culvert and checks values outside rating curve
28are dealt with       
29"""
30
31path = get_pathname_from_package('anuga.culvert_flows')   
32
33length = 40.
34width = 15.
35
36dx = dy = 0.5          # Resolution: Length of subdivisions on both axes
37
38points, vertices, boundary = rectangular_cross(int(length/dx),
39                                               int(width/dy),
40                                               len1=length, 
41                                               len2=width)
42domain = anuga.Domain(points, vertices, boundary)   
43domain.set_starttime(10)
44domain.set_name('Test_culvert')                 # Output name
45domain.set_default_order(2)
46#domain.set_beta(1.5)
47
48
49#----------------------------------------------------------------------
50# Setup initial conditions
51#----------------------------------------------------------------------
52
53def topography(x, y):
54    """Set up a weir
55   
56    A culvert will connect either side
57    """
58    # General Slope of Topography
59    z=-x/1000
60   
61    N = len(x)
62    for i in range(N):
63
64       # Sloping Embankment Across Channel
65        if 5.0 < x[i] < 10.1:
66            # Cut Out Segment for Culvert face               
67            if  1.0+(x[i]-5.0)/5.0 <  y[i]  < 4.0 - (x[i]-5.0)/5.0: 
68               z[i]=z[i]
69            else:
70               z[i] +=  0.5*(x[i] -5.0)    # Sloping Segment  U/S Face
71        if 10.0 < x[i] < 12.1:
72           z[i] +=  2.5                    # Flat Crest of Embankment
73        if 12.0 < x[i] < 14.5:
74            # Cut Out Segment for Culvert face               
75            if  2.0-(x[i]-12.0)/2.5 <  y[i]  < 3.0 + (x[i]-12.0)/2.5:
76               z[i]=z[i]
77            else:
78               z[i] +=  2.5-1.0*(x[i] -12.0) # Sloping D/S Face
79                   
80       
81    return z
82
83
84domain.set_quantity('elevation', topography) 
85domain.set_quantity('friction', 0.01)         # Constant friction
86domain.set_quantity('stage',
87                    expression='elevation')   # Dry initial condition
88
89filename=os.path.join(path, 'example_rating_curve.csv')
90
91end_point0 = num.array([9.0, 2.5])
92end_point1 = num.array([13.0, 2.5])
93
94Boyd_pipe_operator(domain,
95                    #end_point0=[9.0, 2.5],
96                    #end_point1=[13.0, 2.5],
97                    #exchange_line0=[[9.0, 1.75],[9.0, 3.25]],
98                    #exchange_line1=[[13.0, 1.75],[13.0, 3.25]],
99                    losses=1.5,
100                    end_points=[end_point0, end_point1],
101                    diameter=1.5,
102                    apron=0.5,
103                    use_momentum_jet=True, 
104                    use_velocity_head=False,
105                    manning=0.013,
106                    verbose=False)
107
108
109line = [[0.0, 5.0], [0.0, 10.0]]
110Q = 5.0
111#Inlet_operator(domain, line, Q)
112
113
114
115
116##-----------------------------------------------------------------------
117## Setup boundary conditions
118##-----------------------------------------------------------------------
119
120## Inflow based on Flow Depth and Approaching Momentum
121Bi = anuga.Dirichlet_boundary([2.0, 0.0, 0.0])
122Br = anuga.Reflective_boundary(domain)              # Solid reflective wall
123#Bo = anuga.Dirichlet_boundary([-5, 0, 0])           # Outflow
124
125## Upstream and downstream conditions that will exceed the rating curve
126## I.e produce delta_h outside the range [0, 10] specified in the the
127## file example_rating_curve.csv
128#Btus = anuga.Time_boundary(domain, \
129            #lambda t: [100*num.sin(2*pi*(t-4)/10), 0.0, 0.0])
130#Btds = anuga.Time_boundary(domain, \
131            #lambda t: [-5*(num.cos(2*pi*(t-4)/20)), 0.0, 0.0])
132#domain.set_boundary({'left': Btus, 'right': Btds, 'top': Br, 'bottom': Br})
133domain.set_boundary({'left': Bi, 'right': Br, 'top': Br, 'bottom': Br})
134
135
136##-----------------------------------------------------------------------
137## Evolve system through time
138##-----------------------------------------------------------------------
139
140#min_delta_w = sys.maxint
141#max_delta_w = -min_delta_w
142for t in domain.evolve(yieldstep=1.0, finaltime=50.0):
143    domain.write_time()
144
145    #if domain.get_time() > 150.5 and domain.ge t_time() < 151.5 :
146        #Bi = anuga.Dirichlet_boundary([0.0, 0.0, 0.0])
147        #domain.set_boundary({'left': Bi, 'right': Br, 'top': Br, 'bottom': Br})
148
149    #delta_w = culvert.inlet.stage - culvert.outlet.stage
150   
151    #if delta_w > max_delta_w: max_delta_w = delta_w
152    #if delta_w < min_delta_w: min_delta_w = delta_w           
153   
154    pass
155
156## Check that extreme values in rating curve have been exceeded
157## so that we know that condition has been exercised
158#assert min_delta_w < 0
159#assert max_delta_w > 10       
160
161
162#os.remove('Test_culvert.sww')
Note: See TracBrowser for help on using the repository browser.