Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,29 +2,33 @@ import streamlit as st
|
|
| 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,
|
| 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 |
-
#
|
| 23 |
-
|
| 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
|
|
@@ -33,15 +37,11 @@ def calculate_pump_requirements(selected_distance, distance_value, fluid_density
|
|
| 33 |
total_head = static_head + (friction_loss if selected_distance == "Horizontal Distance" else 0)
|
| 34 |
|
| 35 |
# Hydraulic power
|
| 36 |
-
hydraulic_power = (flow_rate / 3600) *
|
| 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"
|
|
@@ -61,8 +61,6 @@ def calculate_pump_requirements(selected_distance, distance_value, fluid_density
|
|
| 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 |
}
|
|
@@ -82,23 +80,16 @@ fluid_type = st.selectbox(
|
|
| 82 |
["Water", "Oil", "Gasoline", "Diesel", "Custom"]
|
| 83 |
)
|
| 84 |
|
| 85 |
-
#
|
| 86 |
-
if fluid_type == "
|
| 87 |
-
density = 1000 # kg/m³
|
| 88 |
-
elif fluid_type == "Oil":
|
| 89 |
-
density = 850 # kg/m³
|
| 90 |
-
elif fluid_type == "Gasoline":
|
| 91 |
-
density = 750 # kg/m³
|
| 92 |
-
elif fluid_type == "Diesel":
|
| 93 |
-
density = 830 # kg/m³
|
| 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(
|
|
@@ -111,7 +102,7 @@ distance_value = st.text_input(f"Enter {selected_distance} (meters):", "50")
|
|
| 111 |
|
| 112 |
# Calculate Button
|
| 113 |
if st.button("Calculate Pump Requirements"):
|
| 114 |
-
results = calculate_pump_requirements(selected_distance, distance_value,
|
| 115 |
if "Error" in results:
|
| 116 |
st.error(results["Error"])
|
| 117 |
else:
|
|
@@ -123,9 +114,9 @@ if st.button("Calculate Pump Requirements"):
|
|
| 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
|
| 129 |
-
- **Pump Parameters**: Calculates flow velocity, head, power,
|
| 130 |
"""
|
| 131 |
)
|
|
|
|
| 2 |
|
| 3 |
# Constants
|
| 4 |
GRAVITY = 9.81 # Acceleration due to gravity in m/s²
|
|
|
|
| 5 |
EFFICIENCY = 0.7 # Default pump efficiency (70%)
|
| 6 |
|
| 7 |
+
# Viscosity and Density for Different Fluids (Predefined)
|
| 8 |
+
FLUID_PROPERTIES = {
|
| 9 |
+
"Water": {"density": 1000, "viscosity": 1}, # kg/m³, cP
|
| 10 |
+
"Oil": {"density": 850, "viscosity": 100},
|
| 11 |
+
"Gasoline": {"density": 750, "viscosity": 0.6},
|
| 12 |
+
"Diesel": {"density": 830, "viscosity": 3},
|
| 13 |
+
"Custom": {"density": None, "viscosity": None},
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
# Function to calculate pump requirements
|
| 17 |
+
def calculate_pump_requirements(selected_distance, distance_value, fluid_properties, pipe_diameter):
|
| 18 |
try:
|
| 19 |
+
# Extract fluid properties
|
| 20 |
+
density = fluid_properties["density"]
|
| 21 |
+
viscosity = fluid_properties["viscosity"]
|
| 22 |
+
|
| 23 |
# Convert inputs to numeric
|
| 24 |
distance_value = float(distance_value) # meters
|
|
|
|
|
|
|
| 25 |
pipe_diameter = float(pipe_diameter) # mm
|
|
|
|
|
|
|
| 26 |
|
| 27 |
# Convert pipe diameter from mm to meters
|
| 28 |
pipe_diameter_m = pipe_diameter / 1000
|
| 29 |
|
| 30 |
+
# Calculate flow rate based on transport demand (simplified)
|
| 31 |
+
flow_rate = distance_value * 0.05 # m³/h
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
flow_velocity = (flow_rate / 3600) / (3.14 * (pipe_diameter_m / 2) ** 2) # m/s
|
| 33 |
|
| 34 |
# Head Calculation
|
|
|
|
| 37 |
total_head = static_head + (friction_loss if selected_distance == "Horizontal Distance" else 0)
|
| 38 |
|
| 39 |
# Hydraulic power
|
| 40 |
+
hydraulic_power = (flow_rate / 3600) * density * GRAVITY * total_head / 1000 # kW
|
| 41 |
|
| 42 |
# Input power
|
| 43 |
input_power = hydraulic_power / EFFICIENCY # Adjusted for efficiency
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
# Suggested Pump Type and Material
|
| 46 |
if total_head > 50:
|
| 47 |
pump_type = "Centrifugal Pump"
|
|
|
|
| 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 |
"Recommended Pump Type": pump_type,
|
| 65 |
"Recommended Material": material,
|
| 66 |
}
|
|
|
|
| 80 |
["Water", "Oil", "Gasoline", "Diesel", "Custom"]
|
| 81 |
)
|
| 82 |
|
| 83 |
+
# Get fluid properties
|
| 84 |
+
if fluid_type == "Custom":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
density = st.text_input("Enter Custom Fluid Density (kg/m³):", "1000")
|
| 86 |
+
viscosity = st.text_input("Enter Custom Fluid Viscosity (cP):", "1")
|
| 87 |
+
fluid_properties = {"density": float(density), "viscosity": float(viscosity)}
|
| 88 |
+
else:
|
| 89 |
+
fluid_properties = FLUID_PROPERTIES[fluid_type]
|
| 90 |
|
| 91 |
# Input Parameters
|
|
|
|
| 92 |
pipe_diameter = st.text_input("Enter Pipe Diameter (mm):", "50") # mm
|
|
|
|
|
|
|
| 93 |
|
| 94 |
# Distance Type Selection
|
| 95 |
selected_distance = st.selectbox(
|
|
|
|
| 102 |
|
| 103 |
# Calculate Button
|
| 104 |
if st.button("Calculate Pump Requirements"):
|
| 105 |
+
results = calculate_pump_requirements(selected_distance, distance_value, fluid_properties, pipe_diameter)
|
| 106 |
if "Error" in results:
|
| 107 |
st.error(results["Error"])
|
| 108 |
else:
|
|
|
|
| 114 |
st.info(
|
| 115 |
"""
|
| 116 |
### How It Works:
|
| 117 |
+
- **Fluid Type**: Select or provide custom density and viscosity.
|
| 118 |
- **Distance Type**: Choose between vertical height or horizontal pipe length.
|
| 119 |
+
- **Additional Parameters**: Adjust for pipe diameter and distance.
|
| 120 |
+
- **Pump Parameters**: Calculates flow velocity, head, power, and recommends pump type/material.
|
| 121 |
"""
|
| 122 |
)
|