import streamlit as st # Hazen-Williams equation: hf = 10.67 * (L / C^1.85) * (Q^1.85 / d^4.8655) def calculate_velocity(pipe_diameter, flow_rate): # Convert pipe diameter from inches to feet diameter_feet = pipe_diameter / 12 # Calculate the cross-sectional area of the pipe (A = π * r²) radius_feet = diameter_feet / 2 area = 3.1416 * (radius_feet ** 2) # Convert flow rate from gallons per minute (GPM) to cubic feet per second (CFS) flow_cfs = flow_rate / 448.831 # Calculate velocity (V = Q / A) if area > 0: velocity = flow_cfs / area return velocity else: return 0 def calculate_pressure_loss(pipe_diameter, flow_rate, pipe_length, c_value): # Convert pipe diameter from inches to feet diameter_feet = pipe_diameter / 12 # Convert flow rate from gallons per minute (GPM) to cubic feet per second (CFS) flow_cfs = flow_rate / 448.831 # Apply Hazen-Williams equation if diameter_feet > 0: hf = 10.67 * (pipe_length / (c_value ** 1.85)) * ((flow_cfs ** 1.85) / (diameter_feet ** 4.8655)) return hf else: return 0 # Streamlit app st.title("Pipe Velocity & Pressure Loss Calculator") st.markdown("**A comprehensive tool to calculate pipe velocity and pressure loss using the Hazen-Williams equation.**") st.header("Inputs") # User inputs pipe_diameter = st.number_input("Enter the pipe diameter (in inches):", min_value=0.0, step=0.1) flow_rate = st.number_input("Enter the flow rate (in gallons per minute):", min_value=0.0, step=0.1) pipe_length = st.number_input("Enter the pipe length (in feet):", min_value=0.0, step=1.0) c_value = st.selectbox("Select the Hazen-Williams friction coefficient (C):", [100, 120, 130, 140, 150]) elevation_requirement = st.number_input("Enter the total elevation requirement (in feet):", min_value=0.0, step=1.0) residual_pressure = st.number_input("Enter the residual pressure at the outlet (in psi):", min_value=0.0, step=0.1) # Calculate button if st.button("Calculate Results"): if pipe_diameter > 0 and flow_rate > 0 and pipe_length > 0: # Velocity calculation velocity = calculate_velocity(pipe_diameter, flow_rate) # Pressure loss calculation pressure_loss = calculate_pressure_loss(pipe_diameter, flow_rate, pipe_length, c_value) # Total pressure required (including elevation) total_pressure_required = pressure_loss + (elevation_requirement / 2.31) + residual_pressure # Display results st.success(f"Velocity in the pipe: {velocity:.2f} ft/s") st.success(f"Pressure loss due to friction: {pressure_loss:.2f} ft of water") st.success(f"Total pressure required: {total_pressure_required:.2f} psi") else: st.error("Please enter valid positive values for all inputs.")