[7960] | 1 | import os.path |
---|
| 2 | import sys |
---|
| 3 | |
---|
| 4 | from anuga.utilities.system_tools import get_pathname_from_package |
---|
| 5 | from anuga.geometry.polygon_function import Polygon_function |
---|
| 6 | |
---|
| 7 | from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross |
---|
| 8 | from anuga.abstract_2d_finite_volumes.quantity import Quantity |
---|
| 9 | |
---|
| 10 | import anuga |
---|
| 11 | |
---|
| 12 | from anuga.structures.culvert_operator import Generic_box_culvert |
---|
| 13 | |
---|
| 14 | #from anuga.culvert_flows.culvert_routines import boyd_generalised_culvert_model |
---|
| 15 | |
---|
| 16 | from math import pi, pow, sqrt |
---|
| 17 | |
---|
| 18 | import numpy as num |
---|
| 19 | |
---|
| 20 | |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | """test_that_culvert_runs_rating |
---|
| 25 | |
---|
| 26 | This test exercises the culvert and checks values outside rating curve |
---|
| 27 | are dealt with |
---|
| 28 | """ |
---|
| 29 | |
---|
| 30 | path = get_pathname_from_package('anuga.culvert_flows') |
---|
| 31 | |
---|
| 32 | length = 40. |
---|
| 33 | width = 5. |
---|
| 34 | |
---|
[7962] | 35 | dx = dy = 0.5 # Resolution: Length of subdivisions on both axes |
---|
[7960] | 36 | |
---|
| 37 | points, vertices, boundary = rectangular_cross(int(length/dx), |
---|
| 38 | int(width/dy), |
---|
| 39 | len1=length, |
---|
| 40 | len2=width) |
---|
| 41 | domain = anuga.Domain(points, vertices, boundary) |
---|
| 42 | domain.set_name('Test_culvert') # Output name |
---|
| 43 | domain.set_default_order(2) |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | #---------------------------------------------------------------------- |
---|
| 47 | # Setup initial conditions |
---|
| 48 | #---------------------------------------------------------------------- |
---|
| 49 | |
---|
| 50 | def topography(x, y): |
---|
| 51 | """Set up a weir |
---|
| 52 | |
---|
| 53 | A culvert will connect either side |
---|
| 54 | """ |
---|
| 55 | # General Slope of Topography |
---|
| 56 | z=-x/1000 |
---|
| 57 | |
---|
| 58 | N = len(x) |
---|
| 59 | for i in range(N): |
---|
| 60 | |
---|
| 61 | # Sloping Embankment Across Channel |
---|
| 62 | if 5.0 < x[i] < 10.1: |
---|
| 63 | # Cut Out Segment for Culvert face |
---|
| 64 | if 1.0+(x[i]-5.0)/5.0 < y[i] < 4.0 - (x[i]-5.0)/5.0: |
---|
| 65 | z[i]=z[i] |
---|
| 66 | else: |
---|
| 67 | z[i] += 0.5*(x[i] -5.0) # Sloping Segment U/S Face |
---|
| 68 | if 10.0 < x[i] < 12.1: |
---|
| 69 | z[i] += 2.5 # Flat Crest of Embankment |
---|
| 70 | if 12.0 < x[i] < 14.5: |
---|
| 71 | # Cut Out Segment for Culvert face |
---|
| 72 | if 2.0-(x[i]-12.0)/2.5 < y[i] < 3.0 + (x[i]-12.0)/2.5: |
---|
| 73 | z[i]=z[i] |
---|
| 74 | else: |
---|
| 75 | z[i] += 2.5-1.0*(x[i] -12.0) # Sloping D/S Face |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | return z |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | domain.set_quantity('elevation', topography) |
---|
| 82 | domain.set_quantity('friction', 0.01) # Constant friction |
---|
| 83 | domain.set_quantity('stage', |
---|
| 84 | expression='elevation') # Dry initial condition |
---|
| 85 | |
---|
| 86 | filename=os.path.join(path, 'example_rating_curve.csv') |
---|
[7962] | 87 | culvert1 = Generic_box_culvert(domain, |
---|
[7960] | 88 | end_point0=[9.0, 2.5], |
---|
| 89 | end_point1=[13.0, 2.5], |
---|
| 90 | width=1.00, |
---|
| 91 | verbose=False) |
---|
| 92 | |
---|
| 93 | |
---|
[7962] | 94 | #culvert2 = Generic_box_culvert(domain, |
---|
| 95 | # end_point0=[19.0, 2.5], |
---|
| 96 | # end_point1=[25.0, 2.5], |
---|
| 97 | # width=1.00, |
---|
| 98 | # verbose=False) |
---|
[7960] | 99 | |
---|
[7962] | 100 | |
---|
| 101 | |
---|
| 102 | |
---|
| 103 | #print domain.fractional_step_operators |
---|
| 104 | |
---|
| 105 | #domain.apply_fractional_steps() |
---|
| 106 | |
---|
[7960] | 107 | ##----------------------------------------------------------------------- |
---|
| 108 | ## Setup boundary conditions |
---|
| 109 | ##----------------------------------------------------------------------- |
---|
| 110 | |
---|
| 111 | ## Inflow based on Flow Depth and Approaching Momentum |
---|
[7962] | 112 | Bi = anuga.Dirichlet_boundary([1.0, 0.0, 0.0]) |
---|
| 113 | Br = anuga.Reflective_boundary(domain) # Solid reflective wall |
---|
[7960] | 114 | #Bo = anuga.Dirichlet_boundary([-5, 0, 0]) # Outflow |
---|
| 115 | |
---|
| 116 | ## Upstream and downstream conditions that will exceed the rating curve |
---|
| 117 | ## I.e produce delta_h outside the range [0, 10] specified in the the |
---|
| 118 | ## file example_rating_curve.csv |
---|
| 119 | #Btus = anuga.Time_boundary(domain, \ |
---|
| 120 | #lambda t: [100*num.sin(2*pi*(t-4)/10), 0.0, 0.0]) |
---|
| 121 | #Btds = anuga.Time_boundary(domain, \ |
---|
| 122 | #lambda t: [-5*(num.cos(2*pi*(t-4)/20)), 0.0, 0.0]) |
---|
| 123 | #domain.set_boundary({'left': Btus, 'right': Btds, 'top': Br, 'bottom': Br}) |
---|
[7962] | 124 | domain.set_boundary({'left': Bi, 'right': Br, 'top': Br, 'bottom': Br}) |
---|
[7960] | 125 | |
---|
| 126 | |
---|
| 127 | ##----------------------------------------------------------------------- |
---|
| 128 | ## Evolve system through time |
---|
| 129 | ##----------------------------------------------------------------------- |
---|
| 130 | |
---|
| 131 | #min_delta_w = sys.maxint |
---|
| 132 | #max_delta_w = -min_delta_w |
---|
[7962] | 133 | for t in domain.evolve(yieldstep = 1.0, finaltime = 300): |
---|
| 134 | domain.write_time() |
---|
[7960] | 135 | #delta_w = culvert.inlet.stage - culvert.outlet.stage |
---|
| 136 | |
---|
| 137 | #if delta_w > max_delta_w: max_delta_w = delta_w |
---|
| 138 | #if delta_w < min_delta_w: min_delta_w = delta_w |
---|
| 139 | |
---|
[7962] | 140 | pass |
---|
[7960] | 141 | |
---|
| 142 | ## Check that extreme values in rating curve have been exceeded |
---|
| 143 | ## so that we know that condition has been exercised |
---|
| 144 | #assert min_delta_w < 0 |
---|
| 145 | #assert max_delta_w > 10 |
---|
| 146 | |
---|
| 147 | |
---|
| 148 | #os.remove('Test_culvert.sww') |
---|