[7177] | 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.culvert_flows.culvert_routines import boyd_generalised_culvert_model |
---|
[7193] | 10 | import numpy as num |
---|
[7177] | 11 | |
---|
| 12 | |
---|
| 13 | class Test_culvert_routines_pipe_1pct(unittest.TestCase): |
---|
| 14 | """ |
---|
| 15 | This unit test sets up 6 tests for various culvert conditions for a Circular Pipe Culvert on a 1.0% 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=0.0 |
---|
| 42 | culvert_height=1.20 |
---|
| 43 | |
---|
| 44 | culvert_type='circle' |
---|
| 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.0 # % 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.113, 0.297, 0.443)) |
---|
| 73 | assert num.allclose(Q, 0.113, rtol=1.0e-1) #inflow |
---|
| 74 | assert num.allclose(v, 0.297, rtol=1.0e-1) #outflow velocity |
---|
| 75 | assert num.allclose(d, 0.443, 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.5 |
---|
| 90 | outlet_velocity=0.50 |
---|
| 91 | |
---|
| 92 | culvert_length=10.0 |
---|
| 93 | culvert_width=0.0 |
---|
| 94 | culvert_height=1.20 |
---|
| 95 | culvert_width=0.0 |
---|
| 96 | culvert_type='circle' |
---|
| 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,%.3f,%.3f,%.3f' %('ANUGAcalcsTEST02 Q-v-d',Q,v,d)) |
---|
| 122 | #print ('%s,%.3f,%.3f,%.3f' %('Spreadsheet_Boydcalcs', 0.108, 0.152, 0.721)) |
---|
| 123 | assert num.allclose(Q, 0.108, rtol=1.0e-1) #inflow |
---|
| 124 | assert num.allclose(v, 0.152, rtol=1.0e-1) #outflow velocity |
---|
| 125 | assert num.allclose(d, 0.721, 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 | |
---|
| 144 | culvert_height=1.20 |
---|
| 145 | culvert_width=0.0 |
---|
| 146 | culvert_type='circle' |
---|
| 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', 3.441, 3.042, 1.2)) |
---|
| 174 | assert num.allclose(Q, 3.441, rtol=1.0e-2) #inflow |
---|
| 175 | assert num.allclose(v, 3.042, rtol=1.0e-2) #outflow velocity |
---|
| 176 | assert num.allclose(d, 1.2, 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.9 |
---|
| 191 | inlet_velocity=1.0 |
---|
| 192 | outlet_velocity=0.5 |
---|
| 193 | culvert_length=10.0 |
---|
| 194 | culvert_width=0.0 |
---|
| 195 | culvert_height=1.20 |
---|
| 196 | |
---|
| 197 | culvert_type='circle' |
---|
| 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', 1.559, 1.694, 0.91)) |
---|
| 227 | assert num.allclose(Q, 1.559, rtol=1.0e-2) #inflow |
---|
| 228 | assert num.allclose(v, 1.694, rtol=1.0e-2) #outflow velocity |
---|
| 229 | assert num.allclose(d, 0.91, 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=0.0 |
---|
| 247 | culvert_height=1.20 |
---|
| 248 | |
---|
| 249 | culvert_type='circle' |
---|
| 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' %('ANUGAcalcsTEST05 Q-v-d',Q,v,d)) |
---|
| 279 | #print ('%s,%.3f,%.3f,%.3f' %('Spreadsheet_Boydcalcs',2.258, 1.996, 1.20)) |
---|
| 280 | assert num.allclose(Q, 2.258, rtol=1.0e-2) #inflow |
---|
| 281 | assert num.allclose(v, 1.996, 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 | def test_boyd_6(self): |
---|
| 285 | """test_boyd_6 |
---|
| 286 | |
---|
| 287 | This tests the Boyd routine with data obtained from ??? by Petar Milevski |
---|
| 288 | """ |
---|
| 289 | # FIXME(Ole): This test fails (20 Feb 2009) |
---|
| 290 | |
---|
| 291 | g=9.81 |
---|
| 292 | culvert_slope=1 # Downward |
---|
| 293 | |
---|
| 294 | inlet_depth=1.50 |
---|
| 295 | inlet_velocity= 4.0 |
---|
| 296 | outlet_depth=0.80 |
---|
| 297 | outlet_velocity=4.0 |
---|
| 298 | culvert_length=10.0 |
---|
| 299 | culvert_height=1.20 |
---|
| 300 | culvert_width=0.0 |
---|
| 301 | culvert_type='circle' |
---|
| 302 | manning=0.013 |
---|
| 303 | sum_loss=1.5 |
---|
| 304 | |
---|
| 305 | inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g |
---|
| 306 | z_in = 10.0 |
---|
| 307 | z_out = 10.0-culvert_length*culvert_slope/100 |
---|
| 308 | E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g |
---|
| 309 | E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g |
---|
| 310 | delta_total_energy = E_in-E_out |
---|
| 311 | |
---|
| 312 | |
---|
| 313 | |
---|
| 314 | Q, v, d = boyd_generalised_culvert_model(inlet_depth, |
---|
| 315 | outlet_depth, |
---|
| 316 | inlet_velocity, |
---|
| 317 | outlet_velocity, |
---|
| 318 | inlet_specific_energy, |
---|
| 319 | delta_total_energy, |
---|
| 320 | g, |
---|
| 321 | culvert_length, |
---|
| 322 | culvert_width, |
---|
| 323 | culvert_height, |
---|
| 324 | culvert_type, |
---|
| 325 | manning, |
---|
| 326 | sum_loss) |
---|
| 327 | #print ('%s,%.3f,%.3f,%.3f' %('ANUGAcalcsTEST06 Q-v-d',Q,v,d)) |
---|
| 328 | #print ('%s,%.3f,%.3f,%.3f' %('Spreadsheet_Boydcalcs',3.472, 3.070, 1.20)) |
---|
| 329 | assert num.allclose(Q, 3.472, rtol=1.0e-2) #inflow |
---|
| 330 | assert num.allclose(v, 3.070, rtol=1.0e-2) #outflow velocity |
---|
| 331 | assert num.allclose(d, 1.20, rtol=1.0e-2) #depth at outlet used to calc v |
---|
| 332 | # ========================================================================= |
---|
| 333 | # ========================================================================= |
---|
| 334 | |
---|
| 335 | if __name__ == "__main__": |
---|
| 336 | suite = unittest.makeSuite(Test_culvert_routines_pipe_1pct, 'test') |
---|
| 337 | runner = unittest.TextTestRunner() |
---|
| 338 | runner.run(suite) |
---|