import streamlit as st # Constants G = 9.80665 # gravitational acceleration m/s^2 DEFAULT_DENSITY_WATER = 1000.0 # kg/m^3 st.set_page_config(page_title="Pump Power Calculator", layout="centered") st.title("Pump Power Calculator") st.write("Calculate pump shaft/motor power from flow, head, fluid density and efficiency.") # Inputs: flow st.header("Flow") flow_value = st.number_input("Flow value", min_value=0.0, value=10.0, format="%.6f") flow_unit = st.selectbox("Flow unit", ["m³/s", "m³/h", "L/s", "L/min", "m³/hr"]) # choices # Inputs: head st.header("Head") head_value = st.number_input("Head value", min_value=0.0, value=15.0, format="%.6f") head_unit = st.selectbox("Head unit", ["m", "ft"]) # Fluid properties & efficiencies st.header("Fluid & Efficiency") density = st.number_input("Fluid density (kg/m³)", min_value=0.0, value=DEFAULT_DENSITY_WATER, format="%.2f") efficiency_percent = st.number_input("Pump efficiency (%)", min_value=0.1, max_value=100.0, value=75.0, format="%.2f") motor_efficiency_percent = st.number_input("Motor efficiency (%) (optional)", min_value=0.1, max_value=100.0, value=95.0, format="%.2f") # Convert flow to m^3/s def flow_to_m3s(value, unit): unit = unit.lower() if unit in ("m³/s", "m3/s"): return value if unit in ("m³/h", "m3/h", "m³/hr", "m3/hr", "m³/hour"): return value / 3600.0 if unit in ("l/s", "lps", "l / s"): return value / 1000.0 if unit in ("l/min", "lpm", "l / min"): return value / 1000.0 / 60.0 # fallback return value # Convert head to meters def head_to_meters(value, unit): unit = unit.lower() if unit == "m": return value if unit == "ft": return value * 0.3048 return value Q_m3s = flow_to_m3s(flow_value, flow_unit) H_m = head_to_meters(head_value, head_unit) # Calculations efficiency = max(min(efficiency_percent / 100.0, 1.0), 1e-6) motor_efficiency = max(min(motor_efficiency_percent / 100.0, 1.0), 1e-6) # Hydraulic power (W): P_h = rho * g * Q * H P_h_W = density * G * Q_m3s * H_m # Pump shaft power required (accounting for pump efficiency) P_shaft_W = P_h_W / efficiency if efficiency > 0 else float("inf") # Motor input power (accounting for motor efficiency) P_motor_W = P_shaft_W / motor_efficiency if motor_efficiency > 0 else float("inf") # Present results st.header("Results") col1, col2 = st.columns(2) with col1: st.metric("Hydraulic power (W)", f"{P_h_W:,.2f} W") st.metric("Hydraulic power (kW)", f"{P_h_W/1000.0:,.4f} kW") with col2: st.metric("Shaft power required (kW)", f"{P_shaft_W/1000.0:,.4f} kW") st.metric("Motor input power (kW)", f"{P_motor_W/1000.0:,.4f} kW") st.write("---") st.subheader("Notes & formulae") st.markdown( """ - Hydraulic power (W) = ρ * g * Q * H - ρ = fluid density (kg/m³) - g = 9.80665 m/s² - Q = flow (m³/s) - H = head (m) - Shaft power = Hydraulic power / Pump efficiency - Motor input power = Shaft power / Motor efficiency **Unit conversions are handled automatically** for the common flow and head units in the form controls above. """ ) st.subheader("Example quick check") st.write( f"For Q = {flow_value} {flow_unit}, H = {head_value} {head_unit}, ρ = {density} kg/m³, " f"pump eff = {efficiency_percent}%, motor eff = {motor_efficiency_percent}%" )