source: trunk/anuga_core/source/anuga/structures/boyd_box_operator.py @ 8001

Last change on this file since 8001 was 8001, checked in by habili, 14 years ago

using "import anuga"

File size: 12.6 KB
Line 
1import anuga
2import math
3import types
4
5class Boyd_box_operator(anuga.Structure_operator):
6    """Culvert flow - transfer water from one rectangular box to another.
7    Sets up the geometry of problem
8   
9    This is the base class for culverts. Inherit from this class (and overwrite
10    compute_discharge method for specific subclasses)
11   
12    Input: Two points, pipe_size (either diameter or width, height),
13    mannings_rougness,
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                 verbose=False):
30                     
31        anuga.Structure_operator.__init__(self,
32                                          domain,
33                                          end_point0, 
34                                          end_point1,
35                                          width,
36                                          height,
37                                          apron,
38                                          manning,
39                                          enquiry_gap,                                                       
40                                          description,
41                                          verbose)           
42       
43       
44        if type(losses) == types.DictType:
45            self.sum_loss = sum(losses.values())
46        elif type(losses) == types.ListType:
47            self.sum_loss = sum(losses)
48        else:
49            self.sum_loss = losses
50       
51        self.use_momentum_jet = use_momentum_jet
52        self.use_velocity_head = use_velocity_head
53       
54        self.culvert_length = self.get_culvert_length()
55        self.culvert_width = self.get_culvert_width()
56        self.culvert_height = self.get_culvert_height()
57
58        self.max_velocity = 10.0
59        self.log_filename = None
60
61        self.inlets = self.get_inlets()
62
63
64        # Stats
65       
66        self.discharge = 0.0
67        self.velocity = 0.0
68       
69       
70    def __call__(self):
71       
72        timestep = self.domain.get_timestep()
73       
74        self.__determine_inflow_outflow()
75       
76        Q, barrel_speed, outlet_depth = self.__discharge_routine()
77
78        old_inflow_height = self.inflow.get_average_height()
79        old_inflow_xmom = self.inflow.get_average_xmom()
80        old_inflow_ymom = self.inflow.get_average_ymom()
81           
82        if old_inflow_height > 0.0 :
83                Qstar = Q/old_inflow_height
84        else:
85                Qstar = 0.0
86
87        factor = 1.0/(1.0 + Qstar*timestep/self.inflow.get_area())
88
89        new_inflow_height = old_inflow_height*factor
90        new_inflow_xmom = old_inflow_xmom*factor
91        new_inflow_ymom = old_inflow_ymom*factor
92           
93
94        self.inflow.set_heights(new_inflow_height)
95
96        #inflow.set_xmoms(Q/inflow.get_area())
97        #inflow.set_ymoms(0.0)
98
99
100        self.inflow.set_xmoms(new_inflow_xmom)
101        self.inflow.set_ymoms(new_inflow_ymom)
102
103
104        loss = (old_inflow_height - new_inflow_height)*self.inflow.get_area()
105
106           
107        # set outflow
108        if old_inflow_height > 0.0 :
109                timestep_star = timestep*new_inflow_height/old_inflow_height
110        else:
111            timestep_star = 0.0
112
113           
114        outflow_extra_height = Q*timestep_star/self.outflow.get_area()
115        outflow_direction = - self.outflow.outward_culvert_vector
116        outflow_extra_momentum = outflow_extra_height*barrel_speed*outflow_direction
117           
118
119        gain = outflow_extra_height*self.outflow.get_area()
120           
121        #print Q, Q*timestep, barrel_speed, outlet_depth, Qstar, factor, timestep_star
122        #print '  ', loss, gain
123
124        # Stats
125        self.discharge  = Q#outflow_extra_height*self.outflow.get_area()/timestep
126        self.velocity = barrel_speed#self.discharge/outlet_depth/self.width
127
128        new_outflow_height = self.outflow.get_average_height() + outflow_extra_height
129
130        if self.use_momentum_jet :
131            # FIXME (SR) Review momentum to account for possible hydraulic jumps at outlet
132            #new_outflow_xmom = outflow.get_average_xmom() + outflow_extra_momentum[0]
133            #new_outflow_ymom = outflow.get_average_ymom() + outflow_extra_momentum[1]
134
135            new_outflow_xmom = barrel_speed*new_outflow_height*outflow_direction[0]
136            new_outflow_ymom = barrel_speed*new_outflow_height*outflow_direction[1]
137
138        else:
139            #new_outflow_xmom = outflow.get_average_xmom()
140            #new_outflow_ymom = outflow.get_average_ymom()
141
142            new_outflow_xmom = 0.0
143            new_outflow_ymom = 0.0
144
145
146        self.outflow.set_heights(new_outflow_height)
147        self.outflow.set_xmoms(new_outflow_xmom)
148        self.outflow.set_ymoms(new_outflow_ymom)
149
150
151    def __determine_inflow_outflow(self):
152        # Determine flow direction based on total energy difference
153
154        if self.use_velocity_head:
155            self.delta_total_energy = self.inlets[0].get_enquiry_total_energy() - self.inlets[1].get_enquiry_total_energy()
156        else:
157            self.delta_total_energy = self.inlets[0].get_enquiry_stage() - self.inlets[1].get_enquiry_stage()
158
159
160        self.inflow  = self.inlets[0]
161        self.outflow = self.inlets[1]
162       
163
164        if self.delta_total_energy < 0:
165            self.inflow  = self.inlets[1]
166            self.outflow = self.inlets[0]
167            self.delta_total_energy = -self.delta_total_energy
168
169   
170    def __discharge_routine(self):
171
172        local_debug ='false'
173       
174        if self.inflow.get_enquiry_height() > 0.01: #this value was 0.01:
175            if local_debug =='true':
176                anuga.log.critical('Specific E & Deltat Tot E = %s, %s'
177                             % (str(self.inflow.get_enquiry_specific_energy()),
178                                str(self.delta_total_energy)))
179                anuga.log.critical('culvert type = %s' % str(culvert_type))
180            # Water has risen above inlet
181
182            if self.log_filename is not None:
183                s = 'Specific energy  = %f m' % self.inflow.get_enquiry_specific_energy()
184                log_to_file(self.log_filename, s)
185
186            msg = 'Specific energy at inlet is negative'
187            assert self.inflow.get_enquiry_specific_energy() >= 0.0, msg
188
189            if self.use_velocity_head :
190                self.driving_energy = self.inflow.get_enquiry_specific_energy()
191            else:
192                self.driving_energy = self.inflow.get_enquiry_height()
193
194            height = self.culvert_height
195            width = self.culvert_width
196            flow_width = self.culvert_width
197            # intially assume the culvert flow is controlled by the inlet
198            # check unsubmerged and submerged condition and use Min Q
199            # but ensure the correct flow area and wetted perimeter are used
200            Q_inlet_unsubmerged = 0.544*anuga.g**0.5*width*self.driving_energy**1.50 # Flow based on Inlet Ctrl Inlet Unsubmerged
201            Q_inlet_submerged = 0.702*anuga.g**0.5*width*height**0.89*self.driving_energy**0.61  # Flow based on Inlet Ctrl Inlet Submerged
202
203            # FIXME(Ole): Are these functions really for inlet control?
204            if Q_inlet_unsubmerged < Q_inlet_submerged:
205                Q = Q_inlet_unsubmerged
206                dcrit = (Q**2/anuga.g/width**2)**0.333333
207                if dcrit > height:
208                    dcrit = height
209                    flow_area = width*dcrit
210                    perimeter= 2.0*(width+dcrit)
211                else: # dcrit < height
212                    flow_area = width*dcrit
213                    perimeter= 2.0*dcrit+width
214                outlet_culvert_depth = dcrit
215                case = 'Inlet unsubmerged Box Acts as Weir'
216            else: # Inlet Submerged but check internal culvert flow depth
217                Q = Q_inlet_submerged
218                dcrit = (Q**2/anuga.g/width**2)**0.333333
219                if dcrit > height:
220                    dcrit = height
221                    flow_area = width*dcrit
222                    perimeter= 2.0*(width+dcrit)
223                else: # dcrit < height
224                    flow_area = width*dcrit
225                    perimeter= 2.0*dcrit+width
226                outlet_culvert_depth = dcrit
227                case = 'Inlet submerged Box Acts as Orifice'
228
229            dcrit = (Q**2/anuga.g/width**2)**0.333333
230            # May not need this .... check if same is done above
231            outlet_culvert_depth = dcrit
232            if outlet_culvert_depth > height:
233                outlet_culvert_depth = height  # Once again the pipe is flowing full not partfull
234                flow_area = width*height  # Cross sectional area of flow in the culvert
235                perimeter = 2*(width+height)
236                case = 'Inlet CTRL Outlet unsubmerged PIPE PART FULL'
237            else:
238                flow_area = width * outlet_culvert_depth
239                perimeter = width+2*outlet_culvert_depth
240                case = 'INLET CTRL Culvert is open channel flow we will for now assume critical depth'
241            # Initial Estimate of Flow for Outlet Control using energy slope
242            #( may need to include Culvert Bed Slope Comparison)
243            hyd_rad = flow_area/perimeter
244            culvert_velocity = math.sqrt(self.delta_total_energy/((self.sum_loss/2/anuga.g)+(self.manning**2*self.culvert_length)/hyd_rad**1.33333))
245            Q_outlet_tailwater = flow_area * culvert_velocity
246           
247           
248            if self.delta_total_energy < self.driving_energy:
249                # Calculate flows for outlet control
250
251                # Determine the depth at the outlet relative to the depth of flow in the Culvert
252                if self.outflow.get_enquiry_height() > height:        # The Outlet is Submerged
253                    outlet_culvert_depth=height
254                    flow_area=width*height       # Cross sectional area of flow in the culvert
255                    perimeter=2.0*(width+height)
256                    case = 'Outlet submerged'
257                else:   # Here really should use the Culvert Slope to calculate Actual Culvert Depth & Velocity
258                    dcrit = (Q**2/anuga.g/width**2)**0.333333
259                    outlet_culvert_depth=dcrit   # For purpose of calculation assume the outlet depth = Critical Depth
260                    if outlet_culvert_depth > height:
261                        outlet_culvert_depth=height
262                        flow_area=width*height
263                        perimeter=2.0*(width+height)
264                        case = 'Outlet is Flowing Full'
265                    else:
266                        flow_area=width*outlet_culvert_depth
267                        perimeter=(width+2.0*outlet_culvert_depth)
268                        case = 'Outlet is open channel flow'
269
270                hyd_rad = flow_area/perimeter
271
272                if self.log_filename is not None:
273                    s = 'hydraulic radius at outlet = %f' % hyd_rad
274                    log_to_file(self.log_filename, s)
275
276                # Final Outlet control velocity using tail water
277                culvert_velocity = math.sqrt(self.delta_total_energy/((self.sum_loss/2/anuga.g)+(self.manning**2*self.culvert_length)/hyd_rad**1.33333))
278                Q_outlet_tailwater = flow_area * culvert_velocity
279
280                if self.log_filename is not None:
281                    s = 'Q_outlet_tailwater = %.6f' % Q_outlet_tailwater
282                    log_to_file(self.log_filename, s)
283                Q = min(Q, Q_outlet_tailwater)
284            else:
285                pass
286                #FIXME(Ole): What about inlet control?
287
288            culv_froude=math.sqrt(Q**2*flow_width/(anuga.g*flow_area**3))
289            if local_debug =='true':
290                anuga.log.critical('FLOW AREA = %s' % str(flow_area))
291                anuga.log.critical('PERIMETER = %s' % str(perimeter))
292                anuga.log.critical('Q final = %s' % str(Q))
293                anuga.log.critical('FROUDE = %s' % str(culv_froude))
294
295            # Determine momentum at the outlet
296            barrel_velocity = Q/(flow_area + anuga.velocity_protection/flow_area)
297
298        # END CODE BLOCK for DEPTH  > Required depth for CULVERT Flow
299
300        else: # self.inflow.get_enquiry_height() < 0.01:
301            Q = barrel_velocity = outlet_culvert_depth = 0.0
302
303        # Temporary flow limit
304        if barrel_velocity > self.max_velocity:
305            barrel_velocity = self.max_velocity
306            Q = flow_area * barrel_velocity
307
308        return Q, barrel_velocity, outlet_culvert_depth
309       
310       
311       
Note: See TracBrowser for help on using the repository browser.