Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,64 +2,77 @@ import streamlit as st
|
|
| 2 |
|
| 3 |
# Constants
|
| 4 |
GRAVITY = 9.81 # Acceleration due to gravity in m/s²
|
| 5 |
-
|
| 6 |
EFFICIENCY = 0.7 # Default pump efficiency (70%)
|
| 7 |
|
| 8 |
# Function to calculate pump requirements
|
| 9 |
-
def calculate_pump_requirements(selected_distance, distance_value, fluid_density):
|
| 10 |
try:
|
| 11 |
# Convert inputs to numeric
|
| 12 |
distance_value = float(distance_value) # meters
|
| 13 |
fluid_density = float(fluid_density) # kg/m³
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
#
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Head Calculation
|
| 19 |
-
if selected_distance == "Vertical Distance (Height)"
|
| 20 |
-
|
| 21 |
-
else: # Horizontal distance with friction loss
|
| 22 |
-
static_head = 0
|
| 23 |
-
friction_loss = distance_value * 0.02 # Simplified friction loss in meters
|
| 24 |
-
total_head = friction_loss
|
| 25 |
total_head = static_head + (friction_loss if selected_distance == "Horizontal Distance" else 0)
|
| 26 |
|
| 27 |
# Hydraulic power
|
| 28 |
-
hydraulic_power = (flow_rate / 3600) *
|
| 29 |
|
| 30 |
# Input power
|
| 31 |
input_power = hydraulic_power / EFFICIENCY # Adjusted for efficiency
|
| 32 |
|
| 33 |
# Cavitation Check
|
| 34 |
-
npsha = static_head -
|
| 35 |
-
cavitation_risk = "Yes" if npsha <
|
| 36 |
|
| 37 |
-
# Suggested Pump Type
|
| 38 |
if total_head > 50:
|
| 39 |
pump_type = "Centrifugal Pump"
|
|
|
|
| 40 |
elif flow_rate > 100:
|
| 41 |
pump_type = "Axial Flow Pump"
|
|
|
|
| 42 |
else:
|
| 43 |
pump_type = "Mixed Flow Pump"
|
|
|
|
| 44 |
|
| 45 |
# Results
|
| 46 |
results = {
|
| 47 |
"Selected Distance": selected_distance,
|
| 48 |
"Flow Rate (m³/h)": round(flow_rate, 2),
|
|
|
|
| 49 |
"Total Head (m)": round(total_head, 2),
|
| 50 |
"Hydraulic Power (kW)": round(hydraulic_power, 2),
|
| 51 |
"Input Power (kW)": round(input_power, 2),
|
| 52 |
"Net Positive Suction Head Available (NPSHa)": round(npsha, 2),
|
| 53 |
"Cavitation Risk": cavitation_risk,
|
| 54 |
"Recommended Pump Type": pump_type,
|
|
|
|
| 55 |
}
|
| 56 |
return results
|
| 57 |
except ValueError:
|
| 58 |
-
return {"Error": "Invalid input. Please enter numeric values for
|
| 59 |
|
| 60 |
|
| 61 |
# Streamlit App GUI
|
| 62 |
-
st.title("Pump Design and Selection Tool")
|
| 63 |
st.subheader("Developed by Ahmad Hassan")
|
| 64 |
st.caption("Supervised by Dr. Hidayatullah Mahar")
|
| 65 |
|
|
@@ -81,6 +94,12 @@ elif fluid_type == "Diesel":
|
|
| 81 |
else:
|
| 82 |
density = st.text_input("Enter Custom Fluid Density (kg/m³):", "1000")
|
| 83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
# Distance Type Selection
|
| 85 |
selected_distance = st.selectbox(
|
| 86 |
"Select Distance Type:",
|
|
@@ -92,7 +111,7 @@ distance_value = st.text_input(f"Enter {selected_distance} (meters):", "50")
|
|
| 92 |
|
| 93 |
# Calculate Button
|
| 94 |
if st.button("Calculate Pump Requirements"):
|
| 95 |
-
results = calculate_pump_requirements(selected_distance, distance_value, density)
|
| 96 |
if "Error" in results:
|
| 97 |
st.error(results["Error"])
|
| 98 |
else:
|
|
@@ -104,8 +123,9 @@ if st.button("Calculate Pump Requirements"):
|
|
| 104 |
st.info(
|
| 105 |
"""
|
| 106 |
### How It Works:
|
| 107 |
-
- **Fluid Type**: Select
|
| 108 |
- **Distance Type**: Choose between vertical height or horizontal pipe length.
|
| 109 |
-
- **
|
|
|
|
| 110 |
"""
|
| 111 |
)
|
|
|
|
| 2 |
|
| 3 |
# Constants
|
| 4 |
GRAVITY = 9.81 # Acceleration due to gravity in m/s²
|
| 5 |
+
ATM_PRESSURE = 101.325 # Standard atmospheric pressure in kPa
|
| 6 |
EFFICIENCY = 0.7 # Default pump efficiency (70%)
|
| 7 |
|
| 8 |
# Function to calculate pump requirements
|
| 9 |
+
def calculate_pump_requirements(selected_distance, distance_value, fluid_density, viscosity, pipe_diameter, altitude, fluid_temp):
|
| 10 |
try:
|
| 11 |
# Convert inputs to numeric
|
| 12 |
distance_value = float(distance_value) # meters
|
| 13 |
fluid_density = float(fluid_density) # kg/m³
|
| 14 |
+
viscosity = float(viscosity) # cP (centipoise)
|
| 15 |
+
pipe_diameter = float(pipe_diameter) # mm
|
| 16 |
+
altitude = float(altitude) # meters
|
| 17 |
+
fluid_temp = float(fluid_temp) # °C
|
| 18 |
|
| 19 |
+
# Convert pipe diameter from mm to meters
|
| 20 |
+
pipe_diameter_m = pipe_diameter / 1000
|
| 21 |
+
|
| 22 |
+
# Adjust fluid properties based on temperature (simplified model)
|
| 23 |
+
density_temp_factor = 1 - ((fluid_temp - 25) * 0.0001) # Example adjustment
|
| 24 |
+
adjusted_density = fluid_density * density_temp_factor
|
| 25 |
+
|
| 26 |
+
# Calculate flow velocity (assumed flow rate based on transport demand)
|
| 27 |
+
flow_rate = distance_value * 0.05 # m³/h (simplified)
|
| 28 |
+
flow_velocity = (flow_rate / 3600) / (3.14 * (pipe_diameter_m / 2) ** 2) # m/s
|
| 29 |
|
| 30 |
# Head Calculation
|
| 31 |
+
static_head = distance_value if selected_distance == "Vertical Distance (Height)" else 0
|
| 32 |
+
friction_loss = (distance_value * viscosity * flow_velocity) / (1000 * pipe_diameter_m) # Simplified
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
total_head = static_head + (friction_loss if selected_distance == "Horizontal Distance" else 0)
|
| 34 |
|
| 35 |
# Hydraulic power
|
| 36 |
+
hydraulic_power = (flow_rate / 3600) * adjusted_density * GRAVITY * total_head / 1000 # kW
|
| 37 |
|
| 38 |
# Input power
|
| 39 |
input_power = hydraulic_power / EFFICIENCY # Adjusted for efficiency
|
| 40 |
|
| 41 |
# Cavitation Check
|
| 42 |
+
npsha = static_head - (ATM_PRESSURE - (altitude * 0.012)) / 9.81 # Simplified
|
| 43 |
+
cavitation_risk = "Yes" if npsha < 5 else "No"
|
| 44 |
|
| 45 |
+
# Suggested Pump Type and Material
|
| 46 |
if total_head > 50:
|
| 47 |
pump_type = "Centrifugal Pump"
|
| 48 |
+
material = "Stainless Steel"
|
| 49 |
elif flow_rate > 100:
|
| 50 |
pump_type = "Axial Flow Pump"
|
| 51 |
+
material = "Plastic or Composite Material"
|
| 52 |
else:
|
| 53 |
pump_type = "Mixed Flow Pump"
|
| 54 |
+
material = "Cast Iron"
|
| 55 |
|
| 56 |
# Results
|
| 57 |
results = {
|
| 58 |
"Selected Distance": selected_distance,
|
| 59 |
"Flow Rate (m³/h)": round(flow_rate, 2),
|
| 60 |
+
"Flow Velocity (m/s)": round(flow_velocity, 2),
|
| 61 |
"Total Head (m)": round(total_head, 2),
|
| 62 |
"Hydraulic Power (kW)": round(hydraulic_power, 2),
|
| 63 |
"Input Power (kW)": round(input_power, 2),
|
| 64 |
"Net Positive Suction Head Available (NPSHa)": round(npsha, 2),
|
| 65 |
"Cavitation Risk": cavitation_risk,
|
| 66 |
"Recommended Pump Type": pump_type,
|
| 67 |
+
"Recommended Material": material,
|
| 68 |
}
|
| 69 |
return results
|
| 70 |
except ValueError:
|
| 71 |
+
return {"Error": "Invalid input. Please enter numeric values for all fields."}
|
| 72 |
|
| 73 |
|
| 74 |
# Streamlit App GUI
|
| 75 |
+
st.title("Enhanced Pump Design and Selection Tool")
|
| 76 |
st.subheader("Developed by Ahmad Hassan")
|
| 77 |
st.caption("Supervised by Dr. Hidayatullah Mahar")
|
| 78 |
|
|
|
|
| 94 |
else:
|
| 95 |
density = st.text_input("Enter Custom Fluid Density (kg/m³):", "1000")
|
| 96 |
|
| 97 |
+
# Input Parameters
|
| 98 |
+
viscosity = st.text_input("Enter Fluid Viscosity (cP):", "1") # Centipoise
|
| 99 |
+
pipe_diameter = st.text_input("Enter Pipe Diameter (mm):", "50") # mm
|
| 100 |
+
fluid_temp = st.text_input("Enter Fluid Temperature (°C):", "25")
|
| 101 |
+
altitude = st.text_input("Enter Altitude Above Sea Level (meters):", "0")
|
| 102 |
+
|
| 103 |
# Distance Type Selection
|
| 104 |
selected_distance = st.selectbox(
|
| 105 |
"Select Distance Type:",
|
|
|
|
| 111 |
|
| 112 |
# Calculate Button
|
| 113 |
if st.button("Calculate Pump Requirements"):
|
| 114 |
+
results = calculate_pump_requirements(selected_distance, distance_value, density, viscosity, pipe_diameter, altitude, fluid_temp)
|
| 115 |
if "Error" in results:
|
| 116 |
st.error(results["Error"])
|
| 117 |
else:
|
|
|
|
| 123 |
st.info(
|
| 124 |
"""
|
| 125 |
### How It Works:
|
| 126 |
+
- **Fluid Type**: Select or provide custom density.
|
| 127 |
- **Distance Type**: Choose between vertical height or horizontal pipe length.
|
| 128 |
+
- **Additional Parameters**: Adjust for fluid viscosity, pipe diameter, and altitude.
|
| 129 |
+
- **Pump Parameters**: Calculates flow velocity, head, power, cavitation risk, and recommends pump type/material.
|
| 130 |
"""
|
| 131 |
)
|