def discharge_routine(self): """ Get info from inlets and then call sequential function """ import pypar local_debug = False #Send attributes of both enquiry points to the master proc if self.myid == self.master_proc: if self.myid == self.enquiry_proc[0]: enq_total_energy0 = self.inlets[0].get_enquiry_total_energy() enq_stage0 = self.inlets[0].get_enquiry_stage() else: enq_total_energy0 = pypar.receive(self.enquiry_proc[0]) enq_stage0 = pypar.receive(self.enquiry_proc[0]) if self.myid == self.enquiry_proc[1]: enq_total_energy1 = self.inlets[1].get_enquiry_total_energy() enq_stage1 = self.inlets[1].get_enquiry_stage() else: enq_total_energy1 = pypar.receive(self.enquiry_proc[1]) enq_stage1 = pypar.receive(self.enquiry_proc[1]) else: if self.myid == self.enquiry_proc[0]: pypar.send(self.inlets[0].get_enquiry_total_energy(), self.master_proc) pypar.send(self.inlets[0].get_enquiry_stage(), self.master_proc) if self.myid == self.enquiry_proc[1]: pypar.send(self.inlets[1].get_enquiry_total_energy(), self.master_proc) pypar.send(self.inlets[1].get_enquiry_stage(), self.master_proc) # Determine the direction of the flow if self.myid == self.master_proc: if self.use_velocity_head: self.delta_total_energy = enq_total_energy0 - enq_total_energy1 else: self.delta_total_energy = enq_stage0 - enq_stage1 self.inflow_index = 0 self.outflow_index = 1 # master proc orders reversal if applicable if self.myid == self.master_proc: # May/June 2014 -- change the driving forces gradually, with forward euler timestepping # forward_Euler_smooth=True if(forward_Euler_smooth): # To avoid 'overshoot' we ensure ts<1. if(self.domain.timestep>0.): ts=self.domain.timestep/max(self.domain.timestep, self.smoothing_timescale,1.0e-06) else: # This case is included in the serial version, which ensures the unit tests pass # even when domain.timestep=0.0. # Note though the discontinuous behaviour as domain.timestep-->0. from above ts=1.0 self.smooth_delta_total_energy=self.smooth_delta_total_energy+\ ts*(self.delta_total_energy-self.smooth_delta_total_energy) else: # Use backward euler -- the 'sensible' ts limitation is different in this case # ts --> Inf is reasonable and corresponds to the 'nosmoothing' case ts=self.domain.timestep/max(self.smoothing_timescale, 1.0e-06) self.smooth_delta_total_energy = (self.smooth_delta_total_energy+ts*(self.delta_total_energy))/(1.+ts) # Reverse the inflow and outflow direction? if self.smooth_delta_total_energy < 0: self.inflow_index = 1 self.outflow_index = 0 #self.delta_total_energy = -self.delta_total_energy self.delta_total_energy = -self.smooth_delta_total_energy for i in self.procs: if i == self.master_proc: continue pypar.send(True, i) else: self.delta_total_energy = self.smooth_delta_total_energy for i in self.procs: if i == self.master_proc: continue pypar.send(False, i) #print "ZZZZ: Delta total energy = %f" %(self.delta_total_energy) else: reverse = pypar.receive(self.master_proc) if reverse: self.inflow_index = 1 self.outflow_index = 0 # Get attribute from inflow enquiry point if self.myid == self.master_proc: if self.myid == self.enquiry_proc[self.inflow_index]: inflow_enq_depth = self.inlets[self.inflow_index].get_enquiry_depth() inflow_enq_specific_energy = self.inlets[self.inflow_index].get_enquiry_specific_energy() else: inflow_enq_depth = pypar.receive(self.enquiry_proc[self.inflow_index]) inflow_enq_specific_energy = pypar.receive(self.enquiry_proc[self.inflow_index]) else: if self.myid == self.enquiry_proc[self.inflow_index]: pypar.send(self.inlets[self.inflow_index].get_enquiry_depth(), self.master_proc) pypar.send(self.inlets[self.inflow_index].get_enquiry_specific_energy(), self.master_proc) # Get attribute from outflow enquiry point if self.myid == self.master_proc: if self.myid == self.enquiry_proc[self.outflow_index]: outflow_enq_depth = self.inlets[self.outflow_index].get_enquiry_depth() else: outflow_enq_depth = pypar.receive(self.enquiry_proc[self.outflow_index]) #print "ZZZZZ: outflow_enq_depth = %f" %(outflow_enq_depth) else: if self.myid == self.enquiry_proc[self.outflow_index]: pypar.send(self.inlets[self.outflow_index].get_enquiry_depth(), self.master_proc) # Master proc computes return values if self.myid == self.master_proc: #inflow_enq_specific_energy if inflow_enq_depth > 0.01: #this value was 0.01: if local_debug: anuga.log.critical('Specific E & Deltat Tot E = %s, %s' % (str(inflow_enq_specific_energy), str(self.delta_total_energy))) anuga.log.critical('culvert type = %s' % str(culvert_type)) # Water has risen above inlet msg = 'Specific energy at inlet is negative' assert inflow_enq_specific_energy >= 0.0, msg if self.use_velocity_head : self.driving_energy = inflow_enq_specific_energy else: self.driving_energy = inflow_enq_depth Q, barrel_velocity, outlet_culvert_depth, flow_area, case = \ weir_orifice_trapezoid_function(depth =self.culvert_height, width =self.culvert_width, z1 =self.culvert_z1, z2 =self.culvert_z2, flow_width =self.culvert_width, length =self.culvert_length, blockage =self.culvert_blockage, barrels =self.culvert_barrels, #culvert_slope =self.culvert_slope, driving_energy =self.driving_energy, delta_total_energy =self.delta_total_energy, outlet_enquiry_depth=outflow_enq_depth, sum_loss =self.sum_loss, manning =self.manning) ################################################ # Smooth discharge. This can reduce oscillations # # NOTE: The sign of smooth_Q assumes that # self.inflow_index=0 and self.outflow_index=1 # , whereas the sign of Q is always positive Qsign=(self.outflow_index-self.inflow_index) # To adjust sign of Q if(forward_Euler_smooth): self.smooth_Q = self.smooth_Q +ts*(Q*Qsign-self.smooth_Q) else: # Try implicit euler method self.smooth_Q = (self.smooth_Q+ts*(Q*Qsign))/(1.+ts) if numpy.sign(self.smooth_Q)!=Qsign: # The flow direction of the 'instantaneous Q' based on the # 'smoothed delta_total_energy' is not the same as the # direction of smooth_Q. To prevent 'jumping around', let's # set Q to zero Q=0. else: Q = min(abs(self.smooth_Q), Q) #abs(self.smooth_Q) barrel_velocity=Q/flow_area # END CODE BLOCK for DEPTH > Required depth for CULVERT Flow else: # self.inflow.get_enquiry_depth() < 0.01: Q = barrel_velocity = outlet_culvert_depth = 0.0 case = 'Inlet dry' self.case = case # Temporary flow limit if barrel_velocity > self.max_velocity: barrel_velocity = self.max_velocity Q = flow_area * barrel_velocity return Q, barrel_velocity, outlet_culvert_depth else: return None, None, None
def test_weir_orifice_6(self): """test_weir_orifice 6 This tests the test_weir_orifice routine with data obtained from a spreadsheet to do the weir orfice calcs """ g = 9.81 culvert_slope = 10 # Downward inlet_depth = 12.0 outlet_depth = 10.0 inlet_velocity = 2.0 outlet_velocity = 2.5 culvert_length = 100.0 culvert_width = 10.0 culvert_height = 3.0 culvert_z1 = 2 culvert_z2 = 2 culvert_blockage = 0.0 culvert_type = 'trapezoid' manning = 0.015 sum_loss = 1.5 inlet_specific_energy = inlet_depth + 0.5 * inlet_velocity**2 / g z_in = 0.0 z_out = z_in - culvert_length * culvert_slope / 100 E_in = z_in + inlet_depth + 0.5 * inlet_velocity**2 / g E_out = z_out + outlet_depth + 0.5 * outlet_velocity**2 / g delta_total_energy = E_in - E_out # Values from Petars spreadsheet #Q_expected = 420.160 #v_expected = 11.470 #d_expected = 3.00 Q_expected = 419.95 v_expected = 8.75 d_expected = 3.00 if verbose: print 50 * '=' print 'UNITTEST ', inspect.stack()[0][3] print 'culvert_width ', culvert_width print 'culvert_depth ', culvert_height print 'culvert_blockage ', culvert_blockage print 'culvert_length ', culvert_length print 'inlet_depth ', inlet_depth print 'inlet_velocity ', inlet_velocity print 'outlet_depth ', outlet_depth print 'outlet_velocity ', outlet_velocity print 'sum_loss ', sum_loss print 'manning ', manning print ' ' print 'flow_width ', culvert_width print 'driving_energy ', inlet_specific_energy print 'delta_total_energy ', delta_total_energy Q, v, d, flow_area, case = weir_orifice_trapezoid_function( width=culvert_width, depth=culvert_height, blockage=culvert_blockage, z1=culvert_z1, z2=culvert_z2, flow_width=culvert_width, length=culvert_length, culvert_slope=culvert_slope, driving_energy=inlet_specific_energy, delta_total_energy=delta_total_energy, outlet_enquiry_depth=outlet_depth, sum_loss=sum_loss, manning=manning) if verbose: print('%s %.2f' % ('SPEC_E = ', inlet_specific_energy)) print('%s %.2f' % ('Delta E = ', delta_total_energy)) print('%s %.2f,%.2f,%.2f' % (' ANUGAcalcsTEST Q-v-d ', Q, v, d)) print('%s %.2f,%.2f,%.2f' % ('spreadsheet calculation ', Q_expected, v_expected, d_expected)) assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v
def discharge_routine(self): import pypar local_debug = False #Send attributes of both enquiry points to the master proc if self.myid == self.master_proc: if self.myid == self.enquiry_proc[0]: enq_total_energy0 = self.inlets[0].get_enquiry_total_energy() enq_stage0 = self.inlets[0].get_enquiry_stage() else: enq_total_energy0 = pypar.receive(self.enquiry_proc[0]) enq_stage0 = pypar.receive(self.enquiry_proc[0]) if self.myid == self.enquiry_proc[1]: enq_total_energy1 = self.inlets[1].get_enquiry_total_energy() enq_stage1 = self.inlets[1].get_enquiry_stage() else: enq_total_energy1 = pypar.receive(self.enquiry_proc[1]) enq_stage1 = pypar.receive(self.enquiry_proc[1]) else: if self.myid == self.enquiry_proc[0]: pypar.send(self.inlets[0].get_enquiry_total_energy(), self.master_proc) pypar.send(self.inlets[0].get_enquiry_stage(), self.master_proc) if self.myid == self.enquiry_proc[1]: pypar.send(self.inlets[1].get_enquiry_total_energy(), self.master_proc) pypar.send(self.inlets[1].get_enquiry_stage(), self.master_proc) # Determine the direction of the flow if self.myid == self.master_proc: if self.use_velocity_head: self.delta_total_energy = enq_total_energy0 - enq_total_energy1 else: self.delta_total_energy = enq_stage0 - enq_stage1 self.inflow_index = 0 self.outflow_index = 1 # master proc orders reversal if applicable if self.myid == self.master_proc: # Reverse the inflow and outflow direction? if self.delta_total_energy < 0: self.inflow_index = 1 self.outflow_index = 0 self.delta_total_energy = -self.delta_total_energy for i in self.procs: if i == self.master_proc: continue pypar.send(True, i) else: for i in self.procs: if i == self.master_proc: continue pypar.send(False, i) #print "ZZZZ: Delta total energy = %f" %(self.delta_total_energy) else: reverse = pypar.receive(self.master_proc) if reverse: self.inflow_index = 1 self.outflow_index = 0 # Get attribute from inflow enquiry point if self.myid == self.master_proc: if self.myid == self.enquiry_proc[self.inflow_index]: inflow_enq_depth = self.inlets[self.inflow_index].get_enquiry_depth() inflow_enq_specific_energy = self.inlets[self.inflow_index].get_enquiry_specific_energy() else: inflow_enq_depth = pypar.receive(self.enquiry_proc[self.inflow_index]) inflow_enq_specific_energy = pypar.receive(self.enquiry_proc[self.inflow_index]) else: if self.myid == self.enquiry_proc[self.inflow_index]: pypar.send(self.inlets[self.inflow_index].get_enquiry_depth(), self.master_proc) pypar.send(self.inlets[self.inflow_index].get_enquiry_specific_energy(), self.master_proc) # Get attribute from outflow enquiry point if self.myid == self.master_proc: if self.myid == self.enquiry_proc[self.outflow_index]: outflow_enq_depth = self.inlets[self.outflow_index].get_enquiry_depth() else: outflow_enq_depth = pypar.receive(self.enquiry_proc[self.outflow_index]) #print "ZZZZZ: outflow_enq_depth = %f" %(outflow_enq_depth) else: if self.myid == self.enquiry_proc[self.outflow_index]: pypar.send(self.inlets[self.outflow_index].get_enquiry_depth(), self.master_proc) # Master proc computes return values if self.myid == self.master_proc: #inflow_enq_specific_energy if inflow_enq_depth > 0.01: #this value was 0.01: if local_debug: anuga.log.critical('Specific E & Deltat Tot E = %s, %s' % (str(inflow_enq_specific_energy), str(self.delta_total_energy))) anuga.log.critical('culvert type = %s' % str(culvert_type)) # Water has risen above inlet msg = 'Specific energy at inlet is negative' assert inflow_enq_specific_energy >= 0.0, msg if self.use_velocity_head : self.driving_energy = inflow_enq_specific_energy else: self.driving_energy = inflow_enq_depth Q, barrel_velocity, outlet_culvert_depth, flow_area, case = \ weir_orifice_trapezoid_function(depth =self.culvert_height, width =self.culvert_width, z1 =self.culvert_z1, z2 =self.culvert_z2, flow_width =self.culvert_width, length =self.culvert_length, driving_energy =self.driving_energy, delta_total_energy =self.delta_total_energy, outlet_enquiry_depth=outflow_enq_depth, sum_loss =self.sum_loss, manning =self.manning) # END CODE BLOCK for DEPTH > Required depth for CULVERT Flow else: # self.inflow.get_enquiry_depth() < 0.01: Q = barrel_velocity = outlet_culvert_depth = 0.0 case = 'Inlet dry' self.case = case # Temporary flow limit if barrel_velocity > self.max_velocity: barrel_velocity = self.max_velocity Q = flow_area * barrel_velocity return Q, barrel_velocity, outlet_culvert_depth else: return None, None, None
def discharge_routine(self): import pypar local_debug = False #Send attributes of both enquiry points to the master proc if self.myid == self.master_proc: if self.myid == self.enquiry_proc[0]: enq_total_energy0 = self.inlets[0].get_enquiry_total_energy() enq_stage0 = self.inlets[0].get_enquiry_stage() else: enq_total_energy0 = pypar.receive(self.enquiry_proc[0]) enq_stage0 = pypar.receive(self.enquiry_proc[0]) if self.myid == self.enquiry_proc[1]: enq_total_energy1 = self.inlets[1].get_enquiry_total_energy() enq_stage1 = self.inlets[1].get_enquiry_stage() else: enq_total_energy1 = pypar.receive(self.enquiry_proc[1]) enq_stage1 = pypar.receive(self.enquiry_proc[1]) else: if self.myid == self.enquiry_proc[0]: pypar.send(self.inlets[0].get_enquiry_total_energy(), self.master_proc) pypar.send(self.inlets[0].get_enquiry_stage(), self.master_proc) if self.myid == self.enquiry_proc[1]: pypar.send(self.inlets[1].get_enquiry_total_energy(), self.master_proc) pypar.send(self.inlets[1].get_enquiry_stage(), self.master_proc) # Determine the direction of the flow if self.myid == self.master_proc: if self.use_velocity_head: self.delta_total_energy = enq_total_energy0 - enq_total_energy1 else: self.delta_total_energy = enq_stage0 - enq_stage1 self.inflow_index = 0 self.outflow_index = 1 # master proc orders reversal if applicable if self.myid == self.master_proc: # Reverse the inflow and outflow direction? if self.delta_total_energy < 0: self.inflow_index = 1 self.outflow_index = 0 self.delta_total_energy = -self.delta_total_energy for i in self.procs: if i == self.master_proc: continue pypar.send(True, i) else: for i in self.procs: if i == self.master_proc: continue pypar.send(False, i) #print "ZZZZ: Delta total energy = %f" %(self.delta_total_energy) else: reverse = pypar.receive(self.master_proc) if reverse: self.inflow_index = 1 self.outflow_index = 0 # Get attribute from inflow enquiry point if self.myid == self.master_proc: if self.myid == self.enquiry_proc[self.inflow_index]: inflow_enq_depth = self.inlets[ self.inflow_index].get_enquiry_depth() inflow_enq_specific_energy = self.inlets[ self.inflow_index].get_enquiry_specific_energy() else: inflow_enq_depth = pypar.receive( self.enquiry_proc[self.inflow_index]) inflow_enq_specific_energy = pypar.receive( self.enquiry_proc[self.inflow_index]) else: if self.myid == self.enquiry_proc[self.inflow_index]: pypar.send(self.inlets[self.inflow_index].get_enquiry_depth(), self.master_proc) pypar.send( self.inlets[ self.inflow_index].get_enquiry_specific_energy(), self.master_proc) # Get attribute from outflow enquiry point if self.myid == self.master_proc: if self.myid == self.enquiry_proc[self.outflow_index]: outflow_enq_depth = self.inlets[ self.outflow_index].get_enquiry_depth() else: outflow_enq_depth = pypar.receive( self.enquiry_proc[self.outflow_index]) #print "ZZZZZ: outflow_enq_depth = %f" %(outflow_enq_depth) else: if self.myid == self.enquiry_proc[self.outflow_index]: pypar.send(self.inlets[self.outflow_index].get_enquiry_depth(), self.master_proc) # Master proc computes return values if self.myid == self.master_proc: #inflow_enq_specific_energy if inflow_enq_depth > 0.01: #this value was 0.01: if local_debug: anuga.log.critical('Specific E & Deltat Tot E = %s, %s' % (str(inflow_enq_specific_energy), str(self.delta_total_energy))) anuga.log.critical('culvert type = %s' % str(culvert_type)) # Water has risen above inlet msg = 'Specific energy at inlet is negative' assert inflow_enq_specific_energy >= 0.0, msg if self.use_velocity_head: self.driving_energy = inflow_enq_specific_energy else: self.driving_energy = inflow_enq_depth Q, barrel_velocity, outlet_culvert_depth, flow_area, case = \ weir_orifice_trapezoid_function(depth =self.culvert_height, width =self.culvert_width, z1 =self.culvert_z1, z2 =self.culvert_z2, flow_width =self.culvert_width, length =self.culvert_length, driving_energy =self.driving_energy, delta_total_energy =self.delta_total_energy, outlet_enquiry_depth=outflow_enq_depth, sum_loss =self.sum_loss, manning =self.manning) # END CODE BLOCK for DEPTH > Required depth for CULVERT Flow else: # self.inflow.get_enquiry_depth() < 0.01: Q = barrel_velocity = outlet_culvert_depth = 0.0 case = 'Inlet dry' self.case = case # Temporary flow limit if barrel_velocity > self.max_velocity: barrel_velocity = self.max_velocity Q = flow_area * barrel_velocity return Q, barrel_velocity, outlet_culvert_depth else: return None, None, None
def test_weir_orifice_5(self): """test_weir_orifice 5 This tests the test_weir_orifice routine with data obtained from a spreadsheet to do the weir orfice calcs """ g = 9.81 culvert_slope = 1 # Downward inlet_depth = 12.0 outlet_depth = 10.0 inlet_velocity = 2.0 outlet_velocity = 2.5 culvert_length = 100.0 culvert_width = 10.0 culvert_height = 3.0 culvert_z1 = 2 culvert_z2 = 2 culvert_blockage = 0.0 culvert_barrels = 1.0 culvert_type = 'trapezoid' manning = 0.015 sum_loss = 1.5 inlet_specific_energy = inlet_depth + old_div(0.5 * inlet_velocity**2, g) z_in = 0.0 z_out = z_in - old_div(culvert_length * culvert_slope, 100) E_in = z_in + inlet_depth + old_div(0.5 * inlet_velocity**2, g) E_out = z_out + outlet_depth + old_div(0.5 * outlet_velocity**2, g) delta_total_energy = E_in - E_out # values from petars spreadsheet #Q_expected = 271.275 #v_expected = 5.652 #d_expected = 3.00 Q_expected = 279.38 v_expected = 5.82 d_expected = 3.00 if verbose: print(50 * '=') print('UNITTEST ', inspect.stack()[0][3]) print('culvert_width ', culvert_width) print('culvert_depth ', culvert_height) print('culvert_blockage ', culvert_blockage) print('culvert_length ', culvert_length) print('inlet_depth ', inlet_depth) print('inlet_velocity ', inlet_velocity) print('outlet_depth ', outlet_depth) print('outlet_velocity ', outlet_velocity) print('sum_loss ', sum_loss) print('manning ', manning) print(' ') print('flow_width ', culvert_width) print('driving_energy ', inlet_specific_energy) print('delta_total_energy ', delta_total_energy) Q, v, d, flow_area, case = weir_orifice_trapezoid_function( width=culvert_width, depth=culvert_height, blockage=culvert_blockage, barrels=culvert_barrels, z1=culvert_z1, z2=culvert_z2, flow_width=culvert_width, length=culvert_length, #culvert_slope = culvert_slope, driving_energy=inlet_specific_energy, delta_total_energy=delta_total_energy, outlet_enquiry_depth=outlet_depth, sum_loss=sum_loss, manning=manning) if verbose: print('%s %.2f' % ('SPEC_E = ', inlet_specific_energy)) print('%s %.2f' % ('Delta E = ', delta_total_energy)) print('%s %.2f,%.2f,%.2f' % (' ANUGAcalcsTEST Q-v-d ', Q, v, d)) print('%s %.2f,%.2f,%.2f' % ('spreadsheet calculation ', Q_expected, v_expected, d_expected)) assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v
def discharge_routine(self): """ Get info from inlets and then call sequential function """ import pypar local_debug = False #Send attributes of both enquiry points to the master proc if self.myid == self.master_proc: if self.myid == self.enquiry_proc[0]: enq_total_energy0 = self.inlets[0].get_enquiry_total_energy() enq_stage0 = self.inlets[0].get_enquiry_stage() else: enq_total_energy0 = pypar.receive(self.enquiry_proc[0]) enq_stage0 = pypar.receive(self.enquiry_proc[0]) if self.myid == self.enquiry_proc[1]: enq_total_energy1 = self.inlets[1].get_enquiry_total_energy() enq_stage1 = self.inlets[1].get_enquiry_stage() else: enq_total_energy1 = pypar.receive(self.enquiry_proc[1]) enq_stage1 = pypar.receive(self.enquiry_proc[1]) else: if self.myid == self.enquiry_proc[0]: pypar.send(self.inlets[0].get_enquiry_total_energy(), self.master_proc) pypar.send(self.inlets[0].get_enquiry_stage(), self.master_proc) if self.myid == self.enquiry_proc[1]: pypar.send(self.inlets[1].get_enquiry_total_energy(), self.master_proc) pypar.send(self.inlets[1].get_enquiry_stage(), self.master_proc) # Determine the direction of the flow if self.myid == self.master_proc: if self.use_velocity_head: self.delta_total_energy = enq_total_energy0 - enq_total_energy1 else: self.delta_total_energy = enq_stage0 - enq_stage1 self.inflow_index = 0 self.outflow_index = 1 # master proc orders reversal if applicable if self.myid == self.master_proc: # May/June 2014 -- change the driving forces gradually, with forward euler timestepping # forward_Euler_smooth = True if (forward_Euler_smooth): # To avoid 'overshoot' we ensure ts<1. if (self.domain.timestep > 0.): ts = self.domain.timestep / max(self.domain.timestep, self.smoothing_timescale, 1.0e-06) else: # This case is included in the serial version, which ensures the unit tests pass # even when domain.timestep=0.0. # Note though the discontinuous behaviour as domain.timestep-->0. from above ts = 1.0 self.smooth_delta_total_energy=self.smooth_delta_total_energy+\ ts*(self.delta_total_energy-self.smooth_delta_total_energy) else: # Use backward euler -- the 'sensible' ts limitation is different in this case # ts --> Inf is reasonable and corresponds to the 'nosmoothing' case ts = self.domain.timestep / max(self.smoothing_timescale, 1.0e-06) self.smooth_delta_total_energy = ( self.smooth_delta_total_energy + ts * (self.delta_total_energy)) / (1. + ts) # Reverse the inflow and outflow direction? if self.smooth_delta_total_energy < 0: self.inflow_index = 1 self.outflow_index = 0 #self.delta_total_energy = -self.delta_total_energy self.delta_total_energy = -self.smooth_delta_total_energy for i in self.procs: if i == self.master_proc: continue pypar.send(True, i) else: self.delta_total_energy = self.smooth_delta_total_energy for i in self.procs: if i == self.master_proc: continue pypar.send(False, i) #print "ZZZZ: Delta total energy = %f" %(self.delta_total_energy) else: reverse = pypar.receive(self.master_proc) if reverse: self.inflow_index = 1 self.outflow_index = 0 # Get attribute from inflow enquiry point if self.myid == self.master_proc: if self.myid == self.enquiry_proc[self.inflow_index]: inflow_enq_depth = self.inlets[ self.inflow_index].get_enquiry_depth() inflow_enq_specific_energy = self.inlets[ self.inflow_index].get_enquiry_specific_energy() else: inflow_enq_depth = pypar.receive( self.enquiry_proc[self.inflow_index]) inflow_enq_specific_energy = pypar.receive( self.enquiry_proc[self.inflow_index]) else: if self.myid == self.enquiry_proc[self.inflow_index]: pypar.send(self.inlets[self.inflow_index].get_enquiry_depth(), self.master_proc) pypar.send( self.inlets[ self.inflow_index].get_enquiry_specific_energy(), self.master_proc) # Get attribute from outflow enquiry point if self.myid == self.master_proc: if self.myid == self.enquiry_proc[self.outflow_index]: outflow_enq_depth = self.inlets[ self.outflow_index].get_enquiry_depth() else: outflow_enq_depth = pypar.receive( self.enquiry_proc[self.outflow_index]) #print "ZZZZZ: outflow_enq_depth = %f" %(outflow_enq_depth) else: if self.myid == self.enquiry_proc[self.outflow_index]: pypar.send(self.inlets[self.outflow_index].get_enquiry_depth(), self.master_proc) # Master proc computes return values if self.myid == self.master_proc: #inflow_enq_specific_energy if inflow_enq_depth > 0.01: #this value was 0.01: if local_debug: anuga.log.critical('Specific E & Deltat Tot E = %s, %s' % (str(inflow_enq_specific_energy), str(self.delta_total_energy))) anuga.log.critical('culvert type = %s' % str(culvert_type)) # Water has risen above inlet msg = 'Specific energy at inlet is negative' assert inflow_enq_specific_energy >= 0.0, msg if self.use_velocity_head: self.driving_energy = inflow_enq_specific_energy else: self.driving_energy = inflow_enq_depth Q, barrel_velocity, outlet_culvert_depth, flow_area, case = \ weir_orifice_trapezoid_function(depth =self.culvert_height, width =self.culvert_width, z1 =self.culvert_z1, z2 =self.culvert_z2, flow_width =self.culvert_width, length =self.culvert_length, blockage =self.culvert_blockage, barrels =self.culvert_barrels, #culvert_slope =self.culvert_slope, driving_energy =self.driving_energy, delta_total_energy =self.delta_total_energy, outlet_enquiry_depth=outflow_enq_depth, sum_loss =self.sum_loss, manning =self.manning) ################################################ # Smooth discharge. This can reduce oscillations # # NOTE: The sign of smooth_Q assumes that # self.inflow_index=0 and self.outflow_index=1 # , whereas the sign of Q is always positive Qsign = (self.outflow_index - self.inflow_index ) # To adjust sign of Q if (forward_Euler_smooth): self.smooth_Q = self.smooth_Q + ts * (Q * Qsign - self.smooth_Q) else: # Try implicit euler method self.smooth_Q = (self.smooth_Q + ts * (Q * Qsign)) / (1. + ts) if numpy.sign(self.smooth_Q) != Qsign: # The flow direction of the 'instantaneous Q' based on the # 'smoothed delta_total_energy' is not the same as the # direction of smooth_Q. To prevent 'jumping around', let's # set Q to zero Q = 0. else: Q = min(abs(self.smooth_Q), Q) #abs(self.smooth_Q) barrel_velocity = Q / flow_area # END CODE BLOCK for DEPTH > Required depth for CULVERT Flow else: # self.inflow.get_enquiry_depth() < 0.01: Q = barrel_velocity = outlet_culvert_depth = 0.0 case = 'Inlet dry' self.case = case # Temporary flow limit if barrel_velocity > self.max_velocity: barrel_velocity = self.max_velocity Q = flow_area * barrel_velocity return Q, barrel_velocity, outlet_culvert_depth else: return None, None, None
def test_weir_orifice_6(self): """test_weir_orifice 6 This tests the test_weir_orifice routine with data obtained from a spreadsheet to do the weir orfice calcs """ g=9.81 culvert_slope=10 # Downward inlet_depth=12.0 outlet_depth=10.0 inlet_velocity=2.0 outlet_velocity=2.5 culvert_length=100.0 culvert_width=10.0 culvert_height=3.0 culvert_z1=2 culvert_z2=2 culvert_blockage = 0.0 culvert_barrels = 1.0 culvert_type='trapezoid' manning=0.015 sum_loss=1.5 inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g z_in = 0.0 z_out = z_in-culvert_length*culvert_slope/100 E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g delta_total_energy = E_in-E_out # Values from Petars spreadsheet #Q_expected = 420.160 #v_expected = 11.470 #d_expected = 3.00 Q_expected = 419.95 v_expected = 8.75 d_expected = 3.00 if verbose: print 50*'=' print 'UNITTEST ',inspect.stack()[0][3] print 'culvert_width ',culvert_width print 'culvert_depth ',culvert_height print 'culvert_blockage ',culvert_blockage print 'culvert_length ' ,culvert_length print 'inlet_depth ', inlet_depth print 'inlet_velocity ', inlet_velocity print 'outlet_depth ', outlet_depth print 'outlet_velocity ', outlet_velocity print 'sum_loss ',sum_loss print 'manning ',manning print ' ' print 'flow_width ',culvert_width print 'driving_energy ',inlet_specific_energy print 'delta_total_energy ',delta_total_energy Q, v, d, flow_area, case= weir_orifice_trapezoid_function( width = culvert_width, depth = culvert_height, blockage = culvert_blockage, barrels = culvert_barrels, z1 = culvert_z1, z2 = culvert_z2, flow_width = culvert_width, length = culvert_length, #culvert_slope = culvert_slope, driving_energy = inlet_specific_energy, delta_total_energy = delta_total_energy, outlet_enquiry_depth = outlet_depth, sum_loss = sum_loss, manning = manning) if verbose: print ('%s %.2f'%('SPEC_E = ',inlet_specific_energy)) print ('%s %.2f'%('Delta E = ',delta_total_energy)) print ('%s %.2f,%.2f,%.2f' %(' ANUGAcalcsTEST Q-v-d ',Q,v,d)) print ('%s %.2f,%.2f,%.2f' %('spreadsheet calculation ', Q_expected, v_expected, d_expected)) assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v
def test_weir_orifice_6(self): """test_weir_orifice 6 This tests the test_weir_orifice routine with data obtained from a spreadsheet to do the weir orfice calcs """ g = 9.81 culvert_slope = 10 # Downward inlet_depth = 12.0 outlet_depth = 10.0 inlet_velocity = 2.0 outlet_velocity = 2.5 culvert_length = 100.0 culvert_width = 10.0 culvert_height = 3.0 culvert_z1 = 2 culvert_z2 = 2 culvert_type = "trapezoid" manning = 0.015 sum_loss = 1.5 inlet_specific_energy = inlet_depth + 0.5 * inlet_velocity ** 2 / g z_in = 0.0 z_out = z_in - culvert_length * culvert_slope / 100 E_in = z_in + inlet_depth + 0.5 * inlet_velocity ** 2 / g E_out = z_out + outlet_depth + 0.5 * outlet_velocity ** 2 / g delta_total_energy = E_in - E_out Q_expected = 1049.86 v_expected = 8.75 d_expected = 3.00 if verbose: print 50 * "=" print "UNITTEST ", inspect.stack()[0][3] print "width ", culvert_width print "depth ", culvert_height print "flow_width ", culvert_width print "length ", culvert_length print "driving_energy ", inlet_specific_energy print "delta_total_energy ", delta_total_energy print "outlet_enquiry_depth ", outlet_depth print "sum_loss ", sum_loss print "manning ", manning Q, v, d, flow_area, case = weir_orifice_trapezoid_function( culvert_width, culvert_height, culvert_width, culvert_slope, culvert_z1, culvert_z2, culvert_length, inlet_specific_energy, delta_total_energy, outlet_depth, sum_loss, manning, ) if verbose: print ("%s %.2f" % ("SPEC_E = ", inlet_specific_energy)) print ("%s %.2f" % ("Delta E = ", delta_total_energy)) print ("%s %.2f,%.2f,%.2f" % (" ANUGAcalcsTEST Q-v-d ", Q, v, d)) print ("%s %.2f,%.2f,%.2f" % ("spreadsheet calculation ", Q_expected, v_expected, d_expected)) assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) # inflow assert numpy.allclose(v, v_expected, rtol=1.0e-1) # outflow velocity assert numpy.allclose(d, d_expected, rtol=1.0e-1) # depth at outlet used to calc v
def test_weir_orifice_3(self): """test_weir_orifice 3 This tests the test_weir_orifice routine with data obtained from a spreadsheet to do the weir orfice calcs """ g = 9.81 culvert_slope = 1 # Downward inlet_depth = 6.15 outlet_depth = 2.02 inlet_velocity = 1.82 outlet_velocity = 8.82 culvert_length = 10.0 culvert_width = 10.0 culvert_height = 3.0 culvert_z1 = 2 culvert_z2 = 2 culvert_type = 'trapezoid' manning = 0.015 sum_loss = 1.5 inlet_specific_energy = inlet_depth + 0.5 * inlet_velocity**2 / g z_in = 0.0 z_out = z_in - culvert_length * culvert_slope / 100 E_in = z_in + inlet_depth + 0.5 * inlet_velocity**2 / g E_out = z_out + outlet_depth + 0.5 * outlet_velocity**2 / g delta_total_energy = E_in - E_out Q_expected = 6.44 v_expected = 2.33 d_expected = 0.24 if verbose: print 50 * '=' print 'UNITTEST ', inspect.stack()[0][3] print 'width ', culvert_width print 'depth ', culvert_height print 'flow_width ', culvert_width print 'length ', culvert_length print 'driving_energy ', inlet_specific_energy print 'delta_total_energy ', delta_total_energy print 'outlet_enquiry_depth ', outlet_depth print 'sum_loss ', sum_loss print 'manning ', manning Q, v, d, flow_area, case = weir_orifice_trapezoid_function( culvert_width, culvert_height, culvert_width, culvert_slope, culvert_z1, culvert_z2, culvert_length, inlet_specific_energy, delta_total_energy, outlet_depth, sum_loss, manning) if verbose: print('%s %.2f' % ('SPEC_E = ', inlet_specific_energy)) print('%s %.2f' % ('Delta E = ', delta_total_energy)) print('%s %.2f,%.2f,%.2f' % (' ANUGAcalcsTEST Q-v-d ', Q, v, d)) print('%s %.2f,%.2f,%.2f' % ('spreadsheet calculation ', Q_expected, v_expected, d_expected)) assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v