def test_hecras_internal_boundary_function_values(self): self.hb = hecras_internal_boundary_function(self.input_hecras_file, verbose=False) # Stationary states # assert numpy.allclose(self.hb(-3., -3.), 0.) assert numpy.allclose(self.hb(-2.5, -2.5), 0.) assert numpy.allclose(self.hb(0., 0.), 0.) assert numpy.allclose(self.hb(1., 1.), 0.) assert numpy.allclose(self.hb(2.8, 2.8), 0.) assert numpy.allclose(self.hb(-2.146, -2.146), 0.) # Known values (looked up manually in table) # # Top of one nonfree-flow curve assert numpy.allclose(self.hb(-2.759, -2.947), 9.425) # Slightly above previous (i.e. free flow curve) assert numpy.allclose(self.hb(-2.747, -2.947), 9.736) # Value on most extreme nonfree flow curve assert numpy.allclose(self.hb(2.909, 2.894), 5.118) # Value on least-extreme nonfree flow curve assert numpy.allclose(self.hb(-3.26, -3.266), 0.27) # Value with hw below all curves assert numpy.allclose(self.hb(-4., -4.1), 0.) # Value below least-extreme nonfree flow curve, but hw still valid on # free flow curve assert numpy.allclose(self.hb(-2.747, -3.4), 9.736) # Near top of free flow curve assert numpy.allclose(self.hb(2.468, -1.4), 82.89) assert numpy.allclose(self.hb(2.468, -2.0), 82.89) assert numpy.allclose(self.hb(2.468, -5.0), 82.89) # Logical ordering assert self.hb(2.4, 2.0) > self.hb(2.2, 2.0) assert self.hb(1.5, 1.0) > self.hb(1.5, 1.01) # Things which should throw errors def tw_too_big(): return self.hb(9.00, 2.0) def hw_too_big(): return self.hb(10.00, 0.) self.assertRaises(Exception, lambda: tw_too_big()) self.assertRaises(Exception, lambda: hw_too_big()) # Check case where sign reversal is allowed self.hb.allow_sign_reversal = True Q1 = self.hb(-2.75, -2.95) Q2 = self.hb(-2.95, -2.75) assert numpy.allclose(Q1, -Q2) return
def test_hecras_internal_boundary_function_values(self): self.hb = hecras_internal_boundary_function(self.input_hecras_file, verbose=False) # Stationary states # assert numpy.allclose(self.hb(-3., -3.), 0.) assert numpy.allclose(self.hb(-2.5, -2.5), 0.) assert numpy.allclose(self.hb(0., 0.), 0.) assert numpy.allclose(self.hb(1., 1.), 0.) assert numpy.allclose(self.hb(2.8, 2.8), 0.) assert numpy.allclose(self.hb(-2.146, -2.146), 0.) # Known values (looked up manually in table) # # Top of one nonfree-flow curve assert numpy.allclose(self.hb(-2.759, -2.947), 9.425) # Slightly above previous (i.e. free flow curve) assert numpy.allclose(self.hb(-2.747, -2.947), 9.736) # Value on most extreme nonfree flow curve assert numpy.allclose(self.hb(2.909, 2.894), 5.118) # Value on least-extreme nonfree flow curve assert numpy.allclose(self.hb(-3.26, -3.266), 0.27) # Value with hw below all curves assert numpy.allclose(self.hb(-4., -4.1), 0.) # Value below least-extreme nonfree flow curve, but hw still valid on # free flow curve assert numpy.allclose(self.hb(-2.747, -3.4), 9.736) # Near top of free flow curve assert numpy.allclose(self.hb(2.468, -1.4), 82.89) assert numpy.allclose(self.hb(2.468, -2.0), 82.89) assert numpy.allclose(self.hb(2.468, -5.0), 82.89) # Logical ordering assert self.hb(2.4, 2.0) > self.hb(2.2, 2.0) assert self.hb(1.5, 1.0) > self.hb(1.5, 1.01) # Things which should throw errors def tw_too_big(): return self.hb(9.00, 2.0) def hw_too_big(): return self.hb(10.00, 0.) self.assertRaises(Exception, lambda: tw_too_big()) self.assertRaises(Exception, lambda: hw_too_big()) # Check case where sign reversal is allowed self.hb.allow_sign_reversal=True Q1 = self.hb( -2.75, -2.95) Q2 = self.hb( -2.95, -2.75) assert numpy.allclose(Q1, -Q2) return
def test_basic_properties(self): self.hb = hecras_internal_boundary_function(self.input_hecras_file, verbose=False) assert self.hb.name == self.input_hecras_file assert len(self.hb.hw_max_given_tw) == len(self.hb.nonfree_flow_tw) assert len(self.hb.nonfree_flow_curves) == len(self.hb.nonfree_flow_tw) return
def test_basic_properties(self): self.hb = hecras_internal_boundary_function(self.input_hecras_file, verbose=False) assert self.hb.name == self.input_hecras_file assert len(self.hb.hw_max_given_tw) == len(self.hb.nonfree_flow_tw) assert len(self.hb.nonfree_flow_curves) == len(self.hb.nonfree_flow_tw) return
def setup_bridges(domain, project): """ Extract bridge data from project class and apply the internal boundary operator Note that the bridge deck information is applied when setting the elevation """ bridge_data = project.bridge_data for i in range(len(bridge_data)): # Extract bridge parameters bd = bridge_data[i] label = bd[0] # bd[1] and bd[2] are used elsewhere to set deck elevation exchange_line_0 = su.read_polygon(bd[3]) exchange_line_1 = su.read_polygon(bd[4]) exchange_lines = [exchange_line_0, exchange_line_1] enquiry_gap = bd[5] #apron = bd[6] #assert apron==0.0, 'Apron must be zero until parallel apron issues fixed' internal_boundary_curve_file = bd[6] vertical_datum_offset = bd[7] smoothing_timescale = bd[8] # Function which computes Q rating_curve = hecras_internal_boundary_function( internal_boundary_curves_file=internal_boundary_curve_file, allow_sign_reversal=True, vertical_datum_offset=vertical_datum_offset) # Add operator as side-effect of this operation bridge = Internal_boundary_operator( domain, rating_curve, exchange_lines=exchange_lines, enquiry_gap=enquiry_gap, apron = 0.0, zero_outflow_momentum=False, smoothing_timescale=smoothing_timescale, logging=True, label=label, verbose=True) return
def setup_bridges(domain, project): """ Extract bridge data from project class and apply the internal boundary operator Note that the bridge deck information is applied when setting the elevation """ bridge_data = project.bridge_data for i in range(len(bridge_data)): # Extract bridge parameters bd = bridge_data[i] label = bd[0] # bd[1] and bd[2] are used elsewhere to set deck elevation exchange_line_0 = su.read_polygon(bd[3]) exchange_line_1 = su.read_polygon(bd[4]) exchange_lines = [exchange_line_0, exchange_line_1] enquiry_gap = bd[5] #apron = bd[6] #assert apron==0.0, 'Apron must be zero until parallel apron issues fixed' internal_boundary_curve_file = bd[6] vertical_datum_offset = bd[7] smoothing_timescale = bd[8] # Function which computes Q rating_curve = hecras_internal_boundary_function( internal_boundary_curves_file=internal_boundary_curve_file, allow_sign_reversal=True, vertical_datum_offset=vertical_datum_offset) # Add operator as side-effect of this operation bridge = Internal_boundary_operator( domain, rating_curve, exchange_lines=exchange_lines, enquiry_gap=enquiry_gap, apron=0.0, zero_outflow_momentum=False, smoothing_timescale=smoothing_timescale, logging=True, label=label, verbose=True) return
indU=numpy.ceil(t_hour).astype(int) w1=(t_hour-1.0*indL) w2=(1.0*indU-t_hour) Qout=Qdata[indL]*w2+Qdata[indU]*w1 return Qout Inlet_operator(domain, line1, Qin) # Set up bridge bridge_in = [ [floodplain_width/2. - chan_width/2.+0.01, bridge_ds-0.01],\ [floodplain_width/2. + chan_width/2.-0.01, bridge_ds-0.01] ] bridge_out = [ [floodplain_width/2. - chan_width/2.+0.01, bridge_us+0.01],\ [floodplain_width/2. + chan_width/2.-0.01, bridge_us+0.01] ] hecras_discharge_function = hecras_internal_boundary_function( 'hecras_bridge_table_high_deck.csv', allow_sign_reversal=True) bridge = Internal_boundary_operator( domain, hecras_discharge_function, exchange_lines=[bridge_in, bridge_out], enquiry_gap=0.01, use_velocity_head=False, smoothing_timescale=30.0, logging=verbose) #------------------------------------------------------------------------------ # # Setup boundary conditions #
indL = numpy.floor(t_hour).astype(int) indU = numpy.ceil(t_hour).astype(int) w1 = (t_hour - 1.0 * indL) w2 = (1.0 * indU - t_hour) Qout = Qdata[indL] * w2 + Qdata[indU] * w1 return Qout Inlet_operator(domain, line1, Qin) # Set up bridge bridge_in = [ [floodplain_width/2. - chan_width/2.+0.01, bridge_ds-0.01],\ [floodplain_width/2. + chan_width/2.-0.01, bridge_ds-0.01] ] bridge_out = [ [floodplain_width/2. - chan_width/2.+0.01, bridge_us+0.01],\ [floodplain_width/2. + chan_width/2.-0.01, bridge_us+0.01] ] hecras_discharge_function = hecras_internal_boundary_function( 'hecras_bridge_table_high_deck.csv', allow_sign_reversal=True) bridge = Internal_boundary_operator(domain, hecras_discharge_function, exchange_lines=[bridge_in, bridge_out], enquiry_gap=0.01, use_velocity_head=False, smoothing_timescale=30.0, logging=verbose) #------------------------------------------------------------------------------ # # Setup boundary conditions # #------------------------------------------------------------------------------