1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | |
---|
4 | import unittest |
---|
5 | import os.path |
---|
6 | import sys |
---|
7 | |
---|
8 | from anuga.utilities.system_tools import get_pathname_from_package |
---|
9 | from anuga.structures.boyd_box_operator import Boyd_box_operator |
---|
10 | from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross |
---|
11 | from anuga.shallow_water.shallow_water_domain import Domain |
---|
12 | from anuga.shallow_water.forcing import Rainfall, Inflow |
---|
13 | import numpy |
---|
14 | |
---|
15 | |
---|
16 | class 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_1(self): |
---|
29 | """test_boyd_1 |
---|
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.001 |
---|
47 | enquiry_gap = 1.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 = 10.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 | culvert = Boyd_box_operator(domain, |
---|
104 | label='3.6x3.6RCBC', |
---|
105 | end_point0=[domain_length/2-culvert_length/2, 100.0], |
---|
106 | end_point1=[domain_length/2+culvert_length/2, 100.0], |
---|
107 | losses=culvert_losses, |
---|
108 | width=culvert_width, |
---|
109 | height=culvert_height, |
---|
110 | apron=culvert_apron, |
---|
111 | enquiry_gap=enquiry_gap, |
---|
112 | use_momentum_jet=False, |
---|
113 | use_velocity_head=False, |
---|
114 | manning=culvert_mannings, |
---|
115 | verbose=False) |
---|
116 | |
---|
117 | |
---|
118 | culvert.determine_inflow_outflow() |
---|
119 | |
---|
120 | ( Q, v, d ) = culvert.discharge_routine() |
---|
121 | |
---|
122 | |
---|
123 | assert numpy.allclose(Q, expected_Q, rtol=1.0e-2) #inflow |
---|
124 | assert numpy.allclose(v, expected_v, rtol=1.0e-2) #outflow velocity |
---|
125 | assert numpy.allclose(d, expected_d, rtol=1.0e-2) #depth at outlet used to calc v |
---|
126 | |
---|
127 | |
---|
128 | # ========================================================================= |
---|
129 | if __name__ == "__main__": |
---|
130 | suite = unittest.makeSuite(Test_boyd_box_operator, 'test') |
---|
131 | runner = unittest.TextTestRunner() |
---|
132 | runner.run(suite) |
---|