source: trunk/anuga_core/source/anuga/structures/test_boyd_box_operator.py @ 8065

Last change on this file since 8065 was 8056, checked in by habili, 14 years ago

The variables end_points, exchange_lines and enquiry_points are now all user defined. Either end_points or exchange_lines must be defined. Use example in test_boyd_box_operator.py

File size: 12.4 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.structures.boyd_box_operator import Boyd_box_operator
10from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
11from anuga.shallow_water.shallow_water_domain import Domain
12from anuga.shallow_water.forcing import Rainfall, Inflow
13import numpy
14
15
16class Test_boyd_box_operator(unittest.TestCase):
17    """
18        Test the boyd box operator, in particular the discharge_routine!
19    """
20
21    def setUp(self):
22        pass
23
24    def tearDown(self):
25        pass
26
27
28    def test_boyd_non_skew(self):
29        """test_boyd_non_skew
30       
31        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson,
32        calculation code by MJ Boyd
33        """
34
35        stage_0 = 11.0
36        stage_1 = 10.0
37        elevation_0 = 10.0
38        elevation_1 = 10.0
39
40        culvert_length = 20.0
41        culvert_width = 3.66
42        culvert_height = 3.66
43        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
44        culvert_mannings = 0.013
45       
46        culvert_apron = 0.0
47        enquiry_gap = 10.0
48       
49        expected_Q = 4.55
50        expected_v = 2.3
51        expected_d = 0.54
52       
53
54        # Probably no need to change below here
55       
56        domain_length = 200.  #x-Dir
57        domain_width  = 200.  #y-dir
58        dx = dy = 5.0          # Resolution: Length of subdivisions on both axes
59
60
61        points, vertices, boundary = rectangular_cross(int(domain_length/dx), int(domain_width/dy),
62                                                        len1=domain_length, len2=domain_width)
63        domain = Domain(points, vertices, boundary)   
64        domain.set_name('Test_Outlet_Inlet')                 # Output name
65        domain.set_default_order(2)
66        domain.H0 = 0.01
67        domain.tight_slope_limiters = 1
68
69        print 'Size', len(domain)
70
71        #------------------------------------------------------------------------------
72        # Setup initial conditions
73        #------------------------------------------------------------------------------
74
75        def elevation(x, y):
76            """Set up a elevation
77            """
78           
79            z = numpy.zeros(x.shape,dtype='d')
80            z[:] = elevation_0
81           
82            numpy.putmask(z, x > domain_length/2, elevation_1)
83   
84            return z
85           
86        def stage(x,y):
87            """Set up stage
88            """
89            z = numpy.zeros(x.shape,dtype='d')
90            z[:] = stage_0
91           
92            numpy.putmask(z, x > domain_length/2, stage_1)
93
94            return z
95           
96        print 'Setting Quantities....'
97        domain.set_quantity('elevation', elevation)  # Use function for elevation
98        domain.set_quantity('stage',  stage)   # Use function for elevation
99
100
101        print 'Defining Structures'
102       
103        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
104        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
105       
106       
107        culvert = Boyd_box_operator(domain,
108                                    losses=culvert_losses,
109                                    width=culvert_width,
110                                    end_points=[ep0, ep1],
111                                    height=culvert_height,
112                                    apron=culvert_apron,
113                                    enquiry_gap=enquiry_gap,
114                                    use_momentum_jet=False,
115                                    use_velocity_head=False,
116                                    manning=culvert_mannings,
117                                    label='3.6x3.6RCBC',
118                                    verbose=False)
119
120        culvert.determine_inflow_outflow()
121       
122        ( Q, v, d ) = culvert.discharge_routine()
123       
124        print 'test_boyd_non_skew'
125        print 'Q: ', Q, 'expected_Q: ', expected_Q
126       
127
128        assert numpy.allclose(Q, expected_Q, rtol=1.0e-2) #inflow
129        assert numpy.allclose(v, expected_v, rtol=1.0e-2) #outflow velocity
130        assert numpy.allclose(d, expected_d, rtol=1.0e-2) #depth at outlet used to calc v
131       
132       
133    def test_boyd_skew(self):
134        """test_boyd_skew
135       
136        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson,
137        calculation code by MJ Boyd
138        """
139
140        stage_0 = 11.0
141        stage_1 = 10.0
142        elevation_0 = 10.0
143        elevation_1 = 10.0
144
145        culvert_length = 20.0
146        culvert_width = 3.66
147        culvert_height = 3.66
148        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
149        culvert_mannings = 0.013
150       
151        culvert_apron = 0.0
152        enquiry_gap = 10.0
153       
154        expected_Q = 4.55
155        expected_v = 2.3
156        expected_d = 0.54
157       
158
159        # Probably no need to change below here
160       
161        domain_length = 200.  #x-Dir
162        domain_width  = 200.  #y-dir
163        dx = dy = 5.0          # Resolution: Length of subdivisions on both axes
164
165
166        points, vertices, boundary = rectangular_cross(int(domain_length/dx), int(domain_width/dy),
167                                                        len1=domain_length, len2=domain_width)
168        domain = Domain(points, vertices, boundary)   
169        domain.set_name('Test_Outlet_Inlet')                 # Output name
170        domain.set_default_order(2)
171        domain.H0 = 0.01
172        domain.tight_slope_limiters = 1
173
174        print 'Size', len(domain)
175
176        #------------------------------------------------------------------------------
177        # Setup initial conditions
178        #------------------------------------------------------------------------------
179
180        def elevation(x, y):
181            """Set up a elevation
182            """
183           
184            z = numpy.zeros(x.shape,dtype='d')
185            z[:] = elevation_0
186           
187            numpy.putmask(z, x > domain_length/2, elevation_1)
188   
189            return z
190           
191        def stage(x,y):
192            """Set up stage
193            """
194            z = numpy.zeros(x.shape,dtype='d')
195            z[:] = stage_0
196           
197            numpy.putmask(z, x > domain_length/2, stage_1)
198
199            return z
200           
201        print 'Setting Quantities....'
202        domain.set_quantity('elevation', elevation)  # Use function for elevation
203        domain.set_quantity('stage',  stage)   # Use function for elevation
204
205
206        print 'Defining Structures'
207       
208        a = domain_length/2 - culvert_length/2
209        b = domain_length/2 + culvert_length/2
210       
211        el0 = numpy.array([[a, 100.0 - culvert_width/2], [a, 100.0 + culvert_width/2]])
212        el1 = numpy.array([[b, 100.0 - culvert_width/2], [b, 100.0 + culvert_width/2]])
213       
214        culvert = Boyd_box_operator(domain,
215                                    losses=culvert_losses,
216                                    width=culvert_width,
217                                    exchange_lines=[el0, el1],
218                                    height=culvert_height,
219                                    apron=culvert_apron,
220                                    enquiry_gap=enquiry_gap,
221                                    use_momentum_jet=False,
222                                    use_velocity_head=False,
223                                    manning=culvert_mannings,
224                                    label='3.6x3.6RCBC',
225                                    verbose=False)
226
227        culvert.determine_inflow_outflow()
228       
229        ( Q, v, d ) = culvert.discharge_routine()
230       
231        print 'test_boyd_skew'
232        print 'Q: ', Q, 'expected_Q: ', expected_Q
233
234        assert numpy.allclose(Q, expected_Q, rtol=1.0e-2) #inflow
235        assert numpy.allclose(v, expected_v, rtol=1.0e-2) #outflow velocity
236        assert numpy.allclose(d, expected_d, rtol=1.0e-2) #depth at outlet used to calc v         
237
238
239    def test_boyd_non_skew_enquiry_points(self):
240        """test_boyd_skew_enquiry_points
241       
242        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson,
243        calculation code by MJ Boyd
244        """
245
246        stage_0 = 11.0
247        stage_1 = 10.0
248        elevation_0 = 10.0
249        elevation_1 = 10.0
250
251        culvert_length = 20.0
252        culvert_width = 3.66
253        culvert_height = 3.66
254        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
255        culvert_mannings = 0.013
256       
257        culvert_apron = 0.0
258        enquiry_gap = 10.0
259       
260        expected_Q = 4.55
261        expected_v = 2.3
262        expected_d = 0.54
263       
264
265        # Probably no need to change below here
266       
267        domain_length = 200.  #x-Dir
268        domain_width  = 200.  #y-dir
269        dx = dy = 5.0          # Resolution: Length of subdivisions on both axes
270
271
272        points, vertices, boundary = rectangular_cross(int(domain_length/dx), int(domain_width/dy),
273                                                        len1=domain_length, len2=domain_width)
274        domain = Domain(points, vertices, boundary)   
275        domain.set_name('Test_Outlet_Inlet')                 # Output name
276        domain.set_default_order(2)
277        domain.H0 = 0.01
278        domain.tight_slope_limiters = 1
279
280        print 'Size', len(domain)
281
282        #------------------------------------------------------------------------------
283        # Setup initial conditions
284        #------------------------------------------------------------------------------
285
286        def elevation(x, y):
287            """Set up a elevation
288            """
289           
290            z = numpy.zeros(x.shape,dtype='d')
291            z[:] = elevation_0
292           
293            numpy.putmask(z, x > domain_length/2, elevation_1)
294   
295            return z
296           
297        def stage(x,y):
298            """Set up stage
299            """
300            z = numpy.zeros(x.shape,dtype='d')
301            z[:] = stage_0
302           
303            numpy.putmask(z, x > domain_length/2, stage_1)
304
305            return z
306           
307        print 'Setting Quantities....'
308        domain.set_quantity('elevation', elevation)  # Use function for elevation
309        domain.set_quantity('stage',  stage)   # Use function for elevation
310
311
312        print 'Defining Structures'
313       
314        a = domain_length/2 - culvert_length/2
315        b = domain_length/2 + culvert_length/2
316       
317        el0 = numpy.array([[a, 100.0 - culvert_width/2], [a, 100.0 + culvert_width/2]])
318        el1 = numpy.array([[b, 100.0 - culvert_width/2], [b, 100.0 + culvert_width/2]])
319       
320        enquiry_points = (numpy.array([85, 100]), numpy.array([115, 100]))
321       
322        culvert = Boyd_box_operator(domain,
323                                    losses=culvert_losses,
324                                    width=culvert_width,
325                                    exchange_lines=[el0, el1],
326                                    enquiry_points=enquiry_points,
327                                    height=culvert_height,
328                                    apron=culvert_apron,
329                                    enquiry_gap=enquiry_gap,
330                                    use_momentum_jet=False,
331                                    use_velocity_head=False,
332                                    manning=culvert_mannings,
333                                    label='3.6x3.6RCBC',
334                                    verbose=False)
335
336        culvert.determine_inflow_outflow()
337       
338        ( Q, v, d ) = culvert.discharge_routine()
339       
340        print test_boyd_non_skew_enquiry_points
341        print 'Q: ', Q, 'expected_Q: ', expected_Q
342
343        assert numpy.allclose(Q, expected_Q, rtol=1.0e-2) #inflow
344        assert numpy.allclose(v, expected_v, rtol=1.0e-2) #outflow velocity
345        assert numpy.allclose(d, expected_d, rtol=1.0e-2) #depth at outlet used to calc v         
346
347
348# =========================================================================
349if __name__ == "__main__":
350    suite = unittest.makeSuite(Test_boyd_box_operator, 'test')
351    runner = unittest.TextTestRunner()
352    runner.run(suite)
Note: See TracBrowser for help on using the repository browser.