1 | import anuga |
---|
2 | import math |
---|
3 | |
---|
4 | class Boyd_box_operator(anuga.Structure_operator): |
---|
5 | """Culvert flow - transfer water from one rectangular box to another. |
---|
6 | Sets up the geometry of problem |
---|
7 | |
---|
8 | This is the base class for culverts. Inherit from this class (and overwrite |
---|
9 | compute_discharge method for specific subclasses) |
---|
10 | |
---|
11 | Input: Two points, pipe_size (either diameter or width, height), |
---|
12 | mannings_rougness, |
---|
13 | """ |
---|
14 | |
---|
15 | |
---|
16 | def __init__(self, |
---|
17 | domain, |
---|
18 | end_point0, |
---|
19 | end_point1, |
---|
20 | losses, |
---|
21 | width, |
---|
22 | height=None, |
---|
23 | apron=None, |
---|
24 | manning=0.013, |
---|
25 | enquiry_gap=0.2, |
---|
26 | use_momentum_jet=True, |
---|
27 | use_velocity_head=True, |
---|
28 | description=None, |
---|
29 | label=None, |
---|
30 | structure_type='boyd_box', |
---|
31 | logging=False, |
---|
32 | verbose=False): |
---|
33 | |
---|
34 | |
---|
35 | anuga.Structure_operator.__init__(self, |
---|
36 | domain, |
---|
37 | end_point0, |
---|
38 | end_point1, |
---|
39 | width, |
---|
40 | height, |
---|
41 | apron, |
---|
42 | manning, |
---|
43 | enquiry_gap, |
---|
44 | description, |
---|
45 | label, |
---|
46 | structure_type, |
---|
47 | logging, |
---|
48 | verbose) |
---|
49 | |
---|
50 | |
---|
51 | if isinstance(losses, dict): |
---|
52 | self.sum_loss = sum(losses.values()) |
---|
53 | elif isinstance(losses, list): |
---|
54 | self.sum_loss = sum(losses) |
---|
55 | else: |
---|
56 | self.sum_loss = losses |
---|
57 | |
---|
58 | self.use_momentum_jet = use_momentum_jet |
---|
59 | self.use_velocity_head = use_velocity_head |
---|
60 | |
---|
61 | self.culvert_length = self.get_culvert_length() |
---|
62 | self.culvert_width = self.get_culvert_width() |
---|
63 | self.culvert_height = self.get_culvert_height() |
---|
64 | |
---|
65 | self.max_velocity = 10.0 |
---|
66 | |
---|
67 | self.inlets = self.get_inlets() |
---|
68 | |
---|
69 | |
---|
70 | # Stats |
---|
71 | |
---|
72 | self.discharge = 0.0 |
---|
73 | self.velocity = 0.0 |
---|
74 | |
---|
75 | self.case = 'N/A' |
---|
76 | |
---|
77 | |
---|
78 | def discharge_routine(self): |
---|
79 | |
---|
80 | local_debug ='false' |
---|
81 | |
---|
82 | if self.inflow.get_enquiry_height() > 0.01: #this value was 0.01: We should call this Enquiry Depth |
---|
83 | if local_debug =='true': |
---|
84 | anuga.log.critical('Specific E & Deltat Tot E = %s, %s' |
---|
85 | % (str(self.inflow.get_enquiry_specific_energy()), |
---|
86 | str(self.delta_total_energy))) |
---|
87 | anuga.log.critical('culvert type = %s' % str(culvert_type)) |
---|
88 | # Water has risen above inlet |
---|
89 | |
---|
90 | |
---|
91 | |
---|
92 | msg = 'Specific energy at inlet is negative' |
---|
93 | assert self.inflow.get_enquiry_specific_energy() >= 0.0, msg |
---|
94 | |
---|
95 | if self.use_velocity_head : |
---|
96 | self.driving_energy = self.inflow.get_enquiry_specific_energy() |
---|
97 | else: |
---|
98 | self.driving_energy = self.inflow.get_enquiry_height() |
---|
99 | |
---|
100 | height = self.culvert_height |
---|
101 | width = self.culvert_width |
---|
102 | flow_width = self.culvert_width |
---|
103 | |
---|
104 | # intially assume the culvert flow is controlled by the inlet |
---|
105 | # check unsubmerged and submerged condition and use Min Q |
---|
106 | # but ensure the correct flow area and wetted perimeter are used |
---|
107 | if self.driving_energy < height: |
---|
108 | # Inlet Unsubmerged |
---|
109 | self.case = 'Inlet unsubmerged Box Acts as Weir' |
---|
110 | Q_inlet = 0.544*anuga.g**0.5*width*self.driving_energy**1.50 # Flow based on Inlet Ctrl Inlet Unsubmerged |
---|
111 | V_inlet = Q_inlet/(width*self.driving_energy) |
---|
112 | elif (self.driving_energy > height) and (self.driving_energy < 1.93*height): |
---|
113 | # Inlet in Transition Zone by Boyd New equation |
---|
114 | self.case = 'Inlet in Transition between Weir & Orifice' |
---|
115 | Q_inlet = 0.54286*anuga.g**0.5*width*height**0.5*self.driving_energy |
---|
116 | dcrit = (Q_inlet**2/anuga.g/width**2)**0.333333 # Based on Inlet Control |
---|
117 | if dcrit < height: |
---|
118 | V_inlet = Q_inlet/(width*dcrit) # Full Box Velocity |
---|
119 | else: |
---|
120 | V_inlet = Q_inlet/(width*height) # Full Box Velocity |
---|
121 | |
---|
122 | else: |
---|
123 | # Inlet Submerged |
---|
124 | self.case = 'Inlet Submerged Box Acts as Orifice' |
---|
125 | Q_inlet = 0.702*anuga.g**0.5*width*height**0.89*self.driving_energy**0.61 # Flow based on Inlet Ctrl Inlet Submerged |
---|
126 | V_inlet = Q_inlet/(width*height) # Full Box Velocity |
---|
127 | |
---|
128 | Q = Q_inlet |
---|
129 | dcrit = (Q**2/anuga.g/width**2)**0.333333 # Based on Inlet Control |
---|
130 | # |
---|
131 | # May not need this .... check if same is done above Might move this block Yet ??? |
---|
132 | outlet_culvert_depth = dcrit |
---|
133 | |
---|
134 | if outlet_culvert_depth > height: |
---|
135 | outlet_culvert_depth = height # Once again the pipe is flowing full not partfull |
---|
136 | flow_area = width*height # Cross sectional area of flow in the culvert |
---|
137 | perimeter = 2*(width+height) |
---|
138 | self.case = 'Inlet CTRL Outlet unsubmerged PIPE PART FULL' |
---|
139 | else: |
---|
140 | flow_area = width * outlet_culvert_depth |
---|
141 | perimeter = width+2*outlet_culvert_depth |
---|
142 | self.case = 'INLET CTRL Culvert is open channel flow we will for now assume critical depth' |
---|
143 | # Initial Estimate of Flow for Outlet Control using energy slope |
---|
144 | #( may need to include Culvert Bed Slope Comparison) |
---|
145 | hyd_rad = flow_area/perimeter |
---|
146 | |
---|
147 | |
---|
148 | # NEED TO DETERMINE INTERNAL BARREL VELOCITY Could you Direct Step Method or Standard Step to compute Profile & Friction loss more accurately |
---|
149 | # For Now Assume Normal Depth in the Pipe if Part full |
---|
150 | #culvert_velocity = math.sqrt(self.delta_total_energy/((self.sum_loss/2/anuga.g)+(self.manning**2*self.culvert_length)/hyd_rad**1.33333)) |
---|
151 | # Calculate Culvert velocity Based on the greater of the Pipe Slope, or the Slope of the Energy Line |
---|
152 | if pipe_slope > energy_line_slope: |
---|
153 | slope = pipe_slope |
---|
154 | else: |
---|
155 | slope = energy_line_slope |
---|
156 | |
---|
157 | # Here need to iterate Depth or use Table |
---|
158 | while Qpartfull < Q: |
---|
159 | for i in numpy.arange(0.01, self.get_culvert_height(), 0.01): |
---|
160 | partfull_Area= partfull_depth*width |
---|
161 | partfull_Perimeter= width+2*partfull_depth |
---|
162 | partfull_Hyd_Rad = partfull_Area/Partfull_Perimeter |
---|
163 | Vpartfull = Partfull_Hyd_Rad**(2/3)*slope**0.5/self.manning |
---|
164 | Qpartfull = Vpartfull*partfull_Area |
---|
165 | if partfull_depth < dcrit: |
---|
166 | flow_type = 'Super-critical in Barrel' |
---|
167 | elif partfull_depth > dcrit: |
---|
168 | flow_type = 'Sub-critical in Barrel' |
---|
169 | else: #partfull = dcrit |
---|
170 | flow_type = 'Critical Depth in Barrel' |
---|
171 | |
---|
172 | #culvert_velocity = math.sqrt(self.delta_total_energy/((self.manning**2*self.culvert_length)/hyd_rad**1.33333)) # Based only on Friction Loss |
---|
173 | #Q_outlet_tailwater = flow_area * culvert_velocity |
---|
174 | |
---|
175 | |
---|
176 | if self.delta_total_energy < self.driving_energy: # wE SHOULD DO THIS ANYWAY NOT ONLY FOR THIS CONDITION OTHER WISE MIGHT MISS oUTLET CONTROL SOMETIMES |
---|
177 | # Calculate flows for outlet control |
---|
178 | |
---|
179 | # Determine the depth at the outlet relative to the depth of flow in the Culvert |
---|
180 | if self.outflow.get_enquiry_height() > height: # The Outlet is Submerged |
---|
181 | outlet_culvert_depth=height |
---|
182 | flow_area=width*height # Cross sectional area of flow in the culvert |
---|
183 | perimeter=2.0*(width+height) |
---|
184 | self.case = 'Outlet submerged Culvert Flowing Full' |
---|
185 | else: # Here really should use the Culvert Slope to calculate Actual Culvert Depth & Velocity |
---|
186 | dcrit = (Q**2/anuga.g/width**2)**0.333333 |
---|
187 | outlet_culvert_depth=dcrit # For purpose of calculation assume the outlet depth = Critical Depth |
---|
188 | if outlet_culvert_depth > height: |
---|
189 | outlet_culvert_depth=height |
---|
190 | flow_area=width*height |
---|
191 | perimeter=2.0*(width+height) |
---|
192 | self.case = 'Outlet is Flowing Full' |
---|
193 | else: |
---|
194 | flow_area=width*outlet_culvert_depth |
---|
195 | perimeter=(width+2.0*outlet_culvert_depth) |
---|
196 | self.case = 'Outlet is open channel flow' |
---|
197 | |
---|
198 | hyd_rad = flow_area/perimeter |
---|
199 | |
---|
200 | |
---|
201 | |
---|
202 | # Rename this next one V_outlet |
---|
203 | culvert_velocity = math.sqrt(self.delta_total_energy/((self.sum_loss/2/anuga.g)+(self.manning**2*self.culvert_length)/hyd_rad**1.33333)) |
---|
204 | Q_outlet_tailwater = flow_area * culvert_velocity |
---|
205 | |
---|
206 | # Final Outlet control velocity using tail water |
---|
207 | # Determine HEad Loss based on Inlet, Barrel and Outlet Velocities |
---|
208 | |
---|
209 | |
---|
210 | #FIXME SR: Is this code used? |
---|
211 | Inlet_Loss = Vinlet**2/(2*g)* Inlet_Loss_Coeff |
---|
212 | Barrel_Loss = self.culvert.length*Vpartfull**2/(partfull_Hyd_Rad**(4/3)) |
---|
213 | Bend_Loss = Vpartfull**2/(2*g)* Bend_Loss_Coeff |
---|
214 | #Other_Loss ??? |
---|
215 | Exit_Loss = culvert_velocity**2/(2*g)*Exit_Loss_Coeff |
---|
216 | Total_Loss = Inlet_Loss+Barrel_Loss+Bend_Loss+Exit_Loss |
---|
217 | |
---|
218 | |
---|
219 | Q = min(Q, Q_outlet_tailwater) |
---|
220 | else: |
---|
221 | pass |
---|
222 | #FIXME(Ole): What about inlet control? |
---|
223 | |
---|
224 | culv_froude=math.sqrt(Q**2*flow_width/(anuga.g*flow_area**3)) |
---|
225 | if local_debug =='true': |
---|
226 | anuga.log.critical('FLOW AREA = %s' % str(flow_area)) |
---|
227 | anuga.log.critical('PERIMETER = %s' % str(perimeter)) |
---|
228 | anuga.log.critical('Q final = %s' % str(Q)) |
---|
229 | anuga.log.critical('FROUDE = %s' % str(culv_froude)) |
---|
230 | |
---|
231 | # Determine momentum at the outlet |
---|
232 | barrel_velocity = Q/(flow_area + anuga.velocity_protection/flow_area) |
---|
233 | |
---|
234 | # END CODE BLOCK for DEPTH > Required depth for CULVERT Flow |
---|
235 | |
---|
236 | else: # self.inflow.get_enquiry_height() < 0.01: |
---|
237 | Q = barrel_velocity = outlet_culvert_depth = 0.0 |
---|
238 | |
---|
239 | # Temporary flow limit |
---|
240 | if barrel_velocity > self.max_velocity: |
---|
241 | barrel_velocity = self.max_velocity |
---|
242 | Q = flow_area * barrel_velocity |
---|
243 | |
---|
244 | return Q, barrel_velocity, outlet_culvert_depth |
---|
245 | |
---|