source: trunk/anuga_core/source/anuga/structures/testing_inlet_operator.py @ 8073

Last change on this file since 8073 was 8073, checked in by steve, 13 years ago

Added in a unit test for inlet operator

File size: 5.0 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_box_operator import Boyd_box_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_name('Testing_inlet_operator')                 # Output name
44domain.set_default_order(2)
45#domain.set_beta(1.5)
46
47
48#----------------------------------------------------------------------
49# Setup initial conditions
50#----------------------------------------------------------------------
51
52def topography(x, y):
53    """Set up a weir
54   
55    A culvert will connect either side
56    """
57    # General Slope of Topography
58    z=-x/1000
59   
60    N = len(x)
61    for i in range(N):
62
63       # Sloping Embankment Across Channel
64        if 5.0 < x[i] < 10.1:
65            # Cut Out Segment for Culvert face               
66            if  1.0+(x[i]-5.0)/5.0 <  y[i]  < 4.0 - (x[i]-5.0)/5.0: 
67               z[i]=z[i]
68            else:
69               z[i] +=  0.5*(x[i] -5.0)    # Sloping Segment  U/S Face
70        if 10.0 < x[i] < 12.1:
71           z[i] +=  2.5                    # Flat Crest of Embankment
72        if 12.0 < x[i] < 14.5:
73            # Cut Out Segment for Culvert face               
74            if  2.0-(x[i]-12.0)/2.5 <  y[i]  < 3.0 + (x[i]-12.0)/2.5:
75               z[i]=z[i]
76            else:
77               z[i] +=  2.5-1.0*(x[i] -12.0) # Sloping D/S Face
78                   
79       
80    return z
81
82
83domain.set_quantity('elevation', topography) 
84domain.set_quantity('friction', 0.01)         # Constant friction
85domain.set_quantity('stage',
86                    expression='elevation')   # Dry initial condition
87
88filename=os.path.join(path, 'example_rating_curve.csv')
89
90
91
92Boyd_box_operator(domain,
93                            end_points=[[9.0, 2.5],[13.0, 2.5]],
94                            losses=1.5,
95                            width=1.5,
96                            apron=5.0,
97                            use_momentum_jet=True,
98                            use_velocity_head=False,
99                            manning=0.013,
100                            verbose=False)
101
102
103line = [[0.0, 5.0], [0.0, 10.0]]
104Q = 5.0
105Inlet_operator(domain, line, Q)
106
107
108
109
110##-----------------------------------------------------------------------
111## Setup boundary conditions
112##-----------------------------------------------------------------------
113
114## Inflow based on Flow Depth and Approaching Momentum
115Bi = anuga.Dirichlet_boundary([2.0, 0.0, 0.0])
116Br = anuga.Reflective_boundary(domain)              # Solid reflective wall
117#Bo = anuga.Dirichlet_boundary([-5, 0, 0])           # Outflow
118
119## Upstream and downstream conditions that will exceed the rating curve
120## I.e produce delta_h outside the range [0, 10] specified in the the
121## file example_rating_curve.csv
122#Btus = anuga.Time_boundary(domain, \
123            #lambda t: [100*num.sin(2*pi*(t-4)/10), 0.0, 0.0])
124#Btds = anuga.Time_boundary(domain, \
125            #lambda t: [-5*(num.cos(2*pi*(t-4)/20)), 0.0, 0.0])
126#domain.set_boundary({'left': Btus, 'right': Btds, 'top': Br, 'bottom': Br})
127domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br})
128
129
130##-----------------------------------------------------------------------
131## Evolve system through time
132##-----------------------------------------------------------------------
133
134#min_delta_w = sys.maxint
135#max_delta_w = -min_delta_w
136for t in domain.evolve(yieldstep = 1.0, finaltime = 200):
137    domain.write_time()
138
139    #if domain.get_time() > 150.5 and domain.get_time() < 151.5 :
140        #Bi = anuga.Dirichlet_boundary([0.0, 0.0, 0.0])
141        #domain.set_boundary({'left': Bi, 'right': Br, 'top': Br, 'bottom': Br})
142
143    #delta_w = culvert.inlet.stage - culvert.outlet.stage
144   
145    #if delta_w > max_delta_w: max_delta_w = delta_w
146    #if delta_w < min_delta_w: min_delta_w = delta_w
147
148    print domain.volumetric_balance_statistics()
149   
150    pass
151
152## Check that extreme values in rating curve have been exceeded
153## so that we know that condition has been exercised
154#assert min_delta_w < 0
155#assert max_delta_w > 10       
156
157
158#os.remove('Test_culvert.sww')
Note: See TracBrowser for help on using the repository browser.