File size: 3,351 Bytes
bc38ea6
953bd54
 
 
 
bc38ea6
 
 
 
953bd54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bc38ea6
953bd54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bc38ea6
 
 
 
953bd54
 
bc38ea6
 
953bd54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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}%"
)