Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
def get_fluid_properties(fluid):
|
| 5 |
+
"""Returns density (kg/m^3) and viscosity (Pa.s) of the fluid."""
|
| 6 |
+
properties = {
|
| 7 |
+
"Water": {"density": 1000, "viscosity": 0.001},
|
| 8 |
+
"Oil": {"density": 800, "viscosity": 0.05},
|
| 9 |
+
"Air": {"density": 1.2, "viscosity": 1.8e-5},
|
| 10 |
+
}
|
| 11 |
+
return properties.get(fluid, {"density": None, "viscosity": None})
|
| 12 |
+
|
| 13 |
+
def calculate_reynolds_number(density, velocity, diameter, viscosity):
|
| 14 |
+
"""Calculates the Reynolds number."""
|
| 15 |
+
return (density * velocity * diameter) / viscosity
|
| 16 |
+
|
| 17 |
+
def calculate_pressure_drop(diameter, flow_rate, density, viscosity, length=1.0):
|
| 18 |
+
"""Calculates pressure drop in a straight pipe."""
|
| 19 |
+
# Calculate velocity
|
| 20 |
+
area = np.pi * (diameter / 2) ** 2
|
| 21 |
+
velocity = flow_rate / area
|
| 22 |
+
|
| 23 |
+
# Reynolds number
|
| 24 |
+
reynolds = calculate_reynolds_number(density, velocity, diameter, viscosity)
|
| 25 |
+
|
| 26 |
+
# Friction factor
|
| 27 |
+
if reynolds < 2000:
|
| 28 |
+
# Laminar flow
|
| 29 |
+
friction_factor = 64 / reynolds
|
| 30 |
+
else:
|
| 31 |
+
# Turbulent flow (Blasius correlation)
|
| 32 |
+
friction_factor = 0.3164 / (reynolds ** 0.25)
|
| 33 |
+
|
| 34 |
+
# Pressure drop (Darcy-Weisbach equation)
|
| 35 |
+
pressure_drop = (friction_factor * length * density * velocity**2) / (2 * diameter)
|
| 36 |
+
return pressure_drop, reynolds
|
| 37 |
+
|
| 38 |
+
# Streamlit App
|
| 39 |
+
st.title("Pressure Drop Calculator for Straight Pipe")
|
| 40 |
+
|
| 41 |
+
# Inputs
|
| 42 |
+
diameter = st.number_input("Pipe Diameter (m)", min_value=0.01, max_value=10.0, value=0.1, step=0.01)
|
| 43 |
+
flow_rate = st.number_input("Flow Rate (m^3/s)", min_value=0.0001, max_value=10.0, value=0.01, step=0.001)
|
| 44 |
+
fluid = st.selectbox("Fluid Type", ["Water", "Oil", "Air"])
|
| 45 |
+
pipe_length = st.number_input("Pipe Length (m)", min_value=0.1, max_value=1000.0, value=1.0, step=0.1)
|
| 46 |
+
|
| 47 |
+
# Get fluid properties
|
| 48 |
+
fluid_props = get_fluid_properties(fluid)
|
| 49 |
+
if fluid_props["density"] and fluid_props["viscosity"]:
|
| 50 |
+
density = fluid_props["density"]
|
| 51 |
+
viscosity = fluid_props["viscosity"]
|
| 52 |
+
|
| 53 |
+
# Calculate pressure drop
|
| 54 |
+
pressure_drop, reynolds = calculate_pressure_drop(diameter, flow_rate, density, viscosity, pipe_length)
|
| 55 |
+
|
| 56 |
+
# Output results
|
| 57 |
+
st.write("## Results")
|
| 58 |
+
st.write(f"Reynolds Number: {reynolds:.2f}")
|
| 59 |
+
st.write(f"Pressure Drop: {pressure_drop:.2f} Pa")
|
| 60 |
+
|
| 61 |
+
# Flow type
|
| 62 |
+
if reynolds < 2000:
|
| 63 |
+
st.write("Flow Type: Laminar")
|
| 64 |
+
else:
|
| 65 |
+
st.write("Flow Type: Turbulent")
|
| 66 |
+
else:
|
| 67 |
+
st.error("Invalid fluid selected or missing properties.")
|
| 68 |
+
|
| 69 |
+
# Deployment note
|
| 70 |
+
st.info("You can deploy this app on Hugging Face by packaging it as a repository with a `requirements.txt` file.")
|