Umar4321 commited on
Commit
953bd54
·
verified ·
1 Parent(s): bdeae98

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +88 -25
app.py CHANGED
@@ -1,37 +1,100 @@
1
- """
2
- Pump Power Calculator (Streamlit)
3
- Suitable for quick hydraulic/shaft/motor power estimates for pumps.
4
- - Deploy: push these files to a GitHub repo and create a Streamlit app on Hugging Face Spaces / Streamlit Community Cloud.
5
- - Run locally: `pip install -r requirements.txt` then `streamlit run app.py`
6
-
7
- Author: Generated by ChatGPT
8
- """
9
-
10
  import streamlit as st
11
- import math
12
- import io
13
- import csv
 
14
 
15
  st.set_page_config(page_title="Pump Power Calculator", layout="centered")
16
 
17
  st.title("Pump Power Calculator")
18
- st.markdown(
19
- "Calculate hydraulic power, shaft power (accounting for pump efficiency), and a recommended motor power "
20
- "including a service factor. Units supported for flow: m³/s, L/s, m³/h. Head in m or ft."
21
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
- # -------------------------
24
- # Inputs
25
- # -------------------------
26
- st.header("Input parameters")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
  col1, col2 = st.columns(2)
29
 
30
  with col1:
31
- flow_value = st.number_input("Flow rate (value)", min_value=0.0, value=5.0, step=0.1, format="%.6f")
32
- flow_unit = st.selectbox("Flow unit", ["L/s", "/s", "m³/h"], index=0)
33
- density = st.number_input("Fluid density (kg/m³)", min_value=0.0, value=1000.0, step=1.0)
34
 
35
  with col2:
36
- head_value = st.number_input("Head (value)", min_value=0.0, value=20.0, step=0.1, format="%.6f")
37
- head_unit = st.selectbox("Head unit", ["m"]()_
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+
3
+ # Constants
4
+ G = 9.80665 # gravitational acceleration m/s^2
5
+ DEFAULT_DENSITY_WATER = 1000.0 # kg/m^3
6
 
7
  st.set_page_config(page_title="Pump Power Calculator", layout="centered")
8
 
9
  st.title("Pump Power Calculator")
10
+ st.write("Calculate pump shaft/motor power from flow, head, fluid density and efficiency.")
11
+
12
+ # Inputs: flow
13
+ st.header("Flow")
14
+ flow_value = st.number_input("Flow value", min_value=0.0, value=10.0, format="%.6f")
15
+ flow_unit = st.selectbox("Flow unit", ["m³/s", "m³/h", "L/s", "L/min", "m³/hr"]) # choices
16
+
17
+ # Inputs: head
18
+ st.header("Head")
19
+ head_value = st.number_input("Head value", min_value=0.0, value=15.0, format="%.6f")
20
+ head_unit = st.selectbox("Head unit", ["m", "ft"])
21
+
22
+ # Fluid properties & efficiencies
23
+ st.header("Fluid & Efficiency")
24
+ density = st.number_input("Fluid density (kg/m³)", min_value=0.0, value=DEFAULT_DENSITY_WATER, format="%.2f")
25
+ efficiency_percent = st.number_input("Pump efficiency (%)", min_value=0.1, max_value=100.0, value=75.0, format="%.2f")
26
+ motor_efficiency_percent = st.number_input("Motor efficiency (%) (optional)", min_value=0.1, max_value=100.0, value=95.0, format="%.2f")
27
+
28
+ # Convert flow to m^3/s
29
+ def flow_to_m3s(value, unit):
30
+ unit = unit.lower()
31
+ if unit in ("m³/s", "m3/s"):
32
+ return value
33
+ if unit in ("m³/h", "m3/h", "m³/hr", "m3/hr", "m³/hour"):
34
+ return value / 3600.0
35
+ if unit in ("l/s", "lps", "l / s"):
36
+ return value / 1000.0
37
+ if unit in ("l/min", "lpm", "l / min"):
38
+ return value / 1000.0 / 60.0
39
+ # fallback
40
+ return value
41
+
42
+ # Convert head to meters
43
+ def head_to_meters(value, unit):
44
+ unit = unit.lower()
45
+ if unit == "m":
46
+ return value
47
+ if unit == "ft":
48
+ return value * 0.3048
49
+ return value
50
 
51
+ Q_m3s = flow_to_m3s(flow_value, flow_unit)
52
+ H_m = head_to_meters(head_value, head_unit)
53
+
54
+ # Calculations
55
+ efficiency = max(min(efficiency_percent / 100.0, 1.0), 1e-6)
56
+ motor_efficiency = max(min(motor_efficiency_percent / 100.0, 1.0), 1e-6)
57
+
58
+ # Hydraulic power (W): P_h = rho * g * Q * H
59
+ P_h_W = density * G * Q_m3s * H_m
60
+
61
+ # Pump shaft power required (accounting for pump efficiency)
62
+ P_shaft_W = P_h_W / efficiency if efficiency > 0 else float("inf")
63
+
64
+ # Motor input power (accounting for motor efficiency)
65
+ P_motor_W = P_shaft_W / motor_efficiency if motor_efficiency > 0 else float("inf")
66
+
67
+ # Present results
68
+ st.header("Results")
69
 
70
  col1, col2 = st.columns(2)
71
 
72
  with col1:
73
+ st.metric("Hydraulic power (W)", f"{P_h_W:,.2f} W")
74
+ st.metric("Hydraulic power (kW)", f"{P_h_W/1000.0:,.4f} kW")
 
75
 
76
  with col2:
77
+ st.metric("Shaft power required (kW)", f"{P_shaft_W/1000.0:,.4f} kW")
78
+ st.metric("Motor input power (kW)", f"{P_motor_W/1000.0:,.4f} kW")
79
+
80
+ st.write("---")
81
+ st.subheader("Notes & formulae")
82
+ st.markdown(
83
+ """
84
+ - Hydraulic power (W) = ρ * g * Q * H
85
+ - ρ = fluid density (kg/m³)
86
+ - g = 9.80665 m/s²
87
+ - Q = flow (m³/s)
88
+ - H = head (m)
89
+ - Shaft power = Hydraulic power / Pump efficiency
90
+ - Motor input power = Shaft power / Motor efficiency
91
+
92
+ **Unit conversions are handled automatically** for the common flow and head units in the form controls above.
93
+ """
94
+ )
95
+
96
+ st.subheader("Example quick check")
97
+ st.write(
98
+ f"For Q = {flow_value} {flow_unit}, H = {head_value} {head_unit}, ρ = {density} kg/m³, "
99
+ f"pump eff = {efficiency_percent}%, motor eff = {motor_efficiency_percent}%"
100
+ )