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

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

Added in a unit test for inlet operator

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