source: trunk/anuga_core/source/anuga/structures/test_culvert_routines_box_1pct.py @ 7992

Last change on this file since 7992 was 7939, checked in by steve, 14 years ago

Adding in culvert routines into structures directory

File size: 13.7 KB
Line 
1#!/usr/bin/env python
2
3
4import unittest
5import os.path
6import sys
7
8from anuga.utilities.system_tools import get_pathname_from_package
9from anuga.culvert_flows.culvert_routines import boyd_generalised_culvert_model
10import numpy as num
11
12
13class Test_culvert_routines_box_1pct(unittest.TestCase):
14    """
15        This unit test sets up 6 tests for various culvert conditions for a Box Culvert on a 1% Slope
16    """
17
18    def setUp(self):
19        pass
20
21    def tearDown(self):
22        pass
23
24
25    def test_boyd_1(self):
26        """test_boyd_1
27       
28        This tests the Boyd routine with data obtained from ??? by Petar Milevski   
29        """
30        # FIXME(Ole): This test fails (20 Feb 2009)
31
32        g=9.81
33
34
35        inlet_depth=0.150
36        outlet_depth=0.15
37        inlet_velocity=1.00
38        outlet_velocity=0.5
39       
40        culvert_length=10.0
41        culvert_width=3.6
42        culvert_height=1.20
43       
44        culvert_type='box'
45        manning=0.013
46        sum_loss=1.5
47
48        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g
49        culvert_slope=1  # % Downward
50        z_in = 10.0
51        z_out = -culvert_length*culvert_slope/100
52        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
53        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
54        delta_total_energy = E_in-E_out
55        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g
56
57        Q, v, d = boyd_generalised_culvert_model(inlet_depth,
58                                                 outlet_depth,
59                                                 inlet_velocity,
60                                                 outlet_velocity,
61                                                 inlet_specific_energy, 
62                                                 delta_total_energy, 
63                                                 g,
64                                                 culvert_length,
65                                                 culvert_width,
66                                                 culvert_height,
67                                                 culvert_type,
68                                                 manning,
69                                                 sum_loss)
70       
71        #print ('%s,%.2f,%.2f,%.2f' %('ANUGAcalcsTEST01 Q-v-d',Q,v,d))
72        #print('%s,%.2f,%.2f,%.2f' %('Spreadsheet_Boydcalcs', 0.5526, 1.146, 0.1339))
73        assert num.allclose(Q, 0.5526, rtol=1.0e-1) #inflow
74        assert num.allclose(v, 1.146, rtol=1.0e-1) #outflow velocity
75        assert num.allclose(d, 0.1339, rtol=1.0e-1) #depth at outlet used to calc v
76       
77    def test_boyd_2(self):
78        """test_boyd_2
79       
80        This tests the Boyd routine with data obtained from ??? by Petar Milevski   
81        """
82        # FIXME(Ole): This test fails (20 Feb 2009)
83
84        g=9.81
85        culvert_slope=1  # Downward
86
87        inlet_depth=0.500
88        outlet_depth=0.700
89        inlet_velocity=1.50
90        outlet_velocity=0.50
91       
92        culvert_length=10.0
93        culvert_width=3.60
94        culvert_height=1.20
95       
96        culvert_type='box'
97        manning=0.013
98        sum_loss=1.5
99
100        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g
101        z_in = 0.0
102        z_out = -culvert_length*culvert_slope/100
103        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
104        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
105        delta_total_energy = E_in-E_out
106
107        Q, v, d = boyd_generalised_culvert_model(inlet_depth,
108                                                 outlet_depth,
109                                                 inlet_velocity,
110                                                 outlet_velocity,
111                                                 inlet_specific_energy, 
112                                                 delta_total_energy, 
113                                                 g,
114                                                 culvert_length,
115                                                 culvert_width,
116                                                 culvert_height,
117                                                 culvert_type,
118                                                 manning,
119                                                 sum_loss)
120       
121        #print ('%s,%.2f,%.2f,%.2f' %('ANUGAcalcsTEST02 Q-v-d',Q,v,d))
122        #print ('%s,%.2f,%.2f,%.2f' %('Spreadsheet_Boydcalcs', 0.224, 0.152, 0.409))
123        assert num.allclose(Q, 0.224, rtol=1.0e-1) #inflow
124        assert num.allclose(v, 0.152, rtol=1.0e-1) #outflow velocity
125        assert num.allclose(d, 0.409, rtol=1.0e-1) #depth at outlet used to calc v 
126
127    def test_boyd_3(self):
128        """test_boyd_3
129       
130        This tests the Boyd routine with data obtained from ??? by Petar Milevski   
131        """
132        # FIXME(Ole): This test fails (20 Feb 2009)
133
134        g=9.81
135        culvert_slope=1  # Downward
136
137        inlet_depth=1.800
138        outlet_depth=0.80
139        inlet_velocity=1.0
140        outlet_velocity=0.5
141       
142        culvert_length=10.0
143        culvert_width=3.60
144        culvert_height=1.20
145       
146        culvert_type='box'
147        manning=0.013
148        sum_loss=1.5
149
150        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g
151        z_in = 0.0
152        z_out = -culvert_length*culvert_slope/100
153        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
154        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
155        delta_total_energy = E_in-E_out
156
157        Q, v, d = boyd_generalised_culvert_model(inlet_depth,
158                                                 outlet_depth,
159                                                 inlet_velocity,
160                                                 outlet_velocity,
161                                                 inlet_specific_energy, 
162                                                 delta_total_energy, 
163                                                 g,
164                                                 culvert_length,
165                                                 culvert_width,
166                                                 culvert_height,
167                                                 culvert_type,
168                                                 manning,
169                                                 sum_loss)
170        #print ('%s,%.2f'%('SPEC_E = ',inlet_specific_energy))
171        #print ('%s,%.2f'%('Delta E = ',delta_total_energy))
172        #print ('%s,%.2f,%.2f,%.2f' %('ANUGAcalcsTEST03 Q-v-d',Q,v,d))
173        #print ('%s,%.2f,%.2f,%.2f' %('Spreadsheet_Boydcalcs', 13.554, 3.329, 1.131))
174        assert num.allclose(Q, 13.554, rtol=1.0e-2) #inflow
175        assert num.allclose(v, 3.329, rtol=1.0e-2) #outflow velocity
176        assert num.allclose(d, 1.131, rtol=1.0e-2) #depth at outlet used to calc v
177
178#NOTE FROM HERE DOWN THE UNITS TEST HAVE NOT BEEN AMENDED TO ALLOW VELOCITY COMPONENT TO BE USED. ONLY ABOVE 3 TESTS WORK. PM WILL FIX THE ONES BELOW WHEN THE ABOVE 3 ARE WORKING
179    def test_boyd_4(self):
180        """test_boyd_4
181       
182        This tests the Boyd routine with data obtained from ??? by Petar Milevski   
183        """
184        # FIXME(Ole): This test fails (20 Feb 2009)
185
186        g=9.81
187        culvert_slope=1  # Downward
188
189        inlet_depth=1.00
190        outlet_depth=0.8
191        inlet_velocity=1.0
192        outlet_velocity=0.5 
193        culvert_length=10.0
194        culvert_width=3.60
195        culvert_height=1.20
196       
197        culvert_type='box'
198        manning=0.013
199        sum_loss=1.5
200
201        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g
202        z_in = 10.0
203        z_out = 10.0-culvert_length*culvert_slope/100
204        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
205        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
206        delta_total_energy = E_in-E_out
207
208
209
210        Q, v, d = boyd_generalised_culvert_model(inlet_depth,
211                                                 outlet_depth,
212                                                 inlet_velocity,
213                                                 outlet_velocity,
214                                                 inlet_specific_energy, 
215                                                 delta_total_energy, 
216                                                 g,
217                                                 culvert_length,
218                                                 culvert_width,
219                                                 culvert_height,
220                                                 culvert_type,
221                                                 manning,
222                                                 sum_loss)       
223        #print ('%s,%.2f'%('SPEC_E = ',inlet_specific_energy))
224        #print ('%s,%.2f'%('Delta E = ',delta_total_energy))
225        #print ('%s,%.2f,%.2f,%.2f' %('ANUGAcalcsTEST04 Q-v-d',Q,v,d))
226        #print ('%s,%.2f,%.2f,%.2f' %('Spreadsheet_Boydcalcs', 5.164, 2.047, 0.70))
227        assert num.allclose(Q, 5.164, rtol=1.0e-2) #inflow
228        assert num.allclose(v, 2.047, rtol=1.0e-2) #outflow velocity
229        assert num.allclose(d, 0.70, rtol=1.0e-2) #depth at outlet used to calc v
230
231    def test_boyd_5(self):
232        """test_boyd_5
233       
234        This tests the Boyd routine with data obtained from ??? by Petar Milevski   
235        """
236        # FIXME(Ole): This test fails (20 Feb 2009)
237
238        g=9.81
239        culvert_slope=1  # Downward
240
241        inlet_depth=1.50
242        inlet_velocity= 1.0
243        outlet_depth=1.3
244        outlet_velocity=0.5
245        culvert_length=10.0
246        culvert_width=3.60
247        culvert_height=1.20
248       
249        culvert_type='box'
250        manning=0.013
251        sum_loss=1.5
252
253        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g
254        z_in = 10.0
255        z_out = 10.0-culvert_length*culvert_slope/100
256        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
257        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
258        delta_total_energy = E_in-E_out
259
260
261
262        Q, v, d = boyd_generalised_culvert_model(inlet_depth,
263                                                 outlet_depth,
264                                                 inlet_velocity,
265                                                 outlet_velocity,
266                                                 inlet_specific_energy, 
267                                                 delta_total_energy, 
268                                                 g,
269                                                 culvert_length,
270                                                 culvert_width,
271                                                 culvert_height,
272                                                 culvert_type,
273                                                 manning,
274                                                 sum_loss)       
275        #print ('%s,%.3f'%('SPEC_E = ',inlet_specific_energy))
276        #print ('%s,%.3f'%('Delta E = ',delta_total_energy))
277       
278        #print ('%s,%.3f,%.3f,%.3f' %('ANUGAcalcsTEST05Q-v-d',Q,v,d))
279        #print ('%s,%.3f,%.3f,%.3f' %('Spreadsheet_Boydcalcs',8.808, 2.039, 1.20))
280        assert num.allclose(Q, 8.808, rtol=1.0e-2) #inflow
281        assert num.allclose(v, 2.039, rtol=1.0e-2) #outflow velocity
282        assert num.allclose(d, 1.20, rtol=1.0e-2) #depth at outlet used to calc v
283
284
285    def test_boyd_6(self):
286        """test_boyd_6
287       
288        This tests the Boyd routine with data obtained from ??? by Petar Milevski   
289        """
290        # FIXME(Ole): This test fails (20 Feb 2009)
291
292        g=9.81
293        culvert_slope=1  # Downward
294
295        inlet_depth=1.50
296        inlet_velocity= 4.0
297        outlet_depth=0.8
298        outlet_velocity=4.0
299        culvert_length=10.0
300        culvert_width=3.60
301        culvert_height=1.20
302       
303        culvert_type='box'
304        manning=0.013
305        sum_loss=1.5
306
307        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g
308        z_in = 10.0
309        z_out = 10.0-culvert_length*culvert_slope/100
310        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
311        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
312        delta_total_energy = E_in-E_out
313
314
315
316        Q, v, d = boyd_generalised_culvert_model(inlet_depth,
317                                                 outlet_depth,
318                                                 inlet_velocity,
319                                                 outlet_velocity,
320                                                 inlet_specific_energy, 
321                                                 delta_total_energy, 
322                                                 g,
323                                                 culvert_length,
324                                                 culvert_width,
325                                                 culvert_height,
326                                                 culvert_type,
327                                                 manning,
328                                                 sum_loss)       
329        #print ('%s,%.3f'%('SPEC_E = ',inlet_specific_energy))
330        #print ('%s,%.3f'%('Delta E = ',delta_total_energy))
331       
332        #print ('%s,%.3f,%.3f,%.3f' %('ANUGAcalcsTEST06 Q-v-d',Q,v,d))
333        #print ('%s,%.3f,%.3f,%.3f' %('Spreadsheet_Boydcalcs',13.546, 3.136, 1.20))
334        assert num.allclose(Q, 13.546, rtol=1.0e-2) #inflow
335        assert num.allclose(v, 3.136, rtol=1.0e-2) #outflow velocity
336        assert num.allclose(d, 1.20, rtol=1.0e-2) #depth at outlet used to calc v
337
338# =========================================================================
339if __name__ == "__main__":
340    suite = unittest.makeSuite(Test_culvert_routines_box_1pct, 'test')
341    runner = unittest.TextTestRunner()
342    runner.run(suite)
Note: See TracBrowser for help on using the repository browser.