CoolFace
Apppublic

HMZaheer/PressureDropCalculations

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py82 linesDownload Raw Back to root
1import streamlit as st2import numpy as np3 4def 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 13def calculate_reynolds_number(density, velocity, diameter, viscosity):14    """Calculates the Reynolds number."""15    return (density * velocity * diameter) / viscosity16 17def calculate_pressure_drop(diameter, flow_rate, density, viscosity, length=1.0):18    """Calculates pressure drop in a straight pipe."""19    # Calculate velocity20    area = np.pi * (diameter / 2) ** 221    velocity = flow_rate / area22 23    # Reynolds number24    reynolds = calculate_reynolds_number(density, velocity, diameter, viscosity)25 26    # Friction factor27    if reynolds < 2000:28        # Laminar flow29        friction_factor = 64 / reynolds30    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, reynolds37 38# Streamlit App39st.title("Pressure Drop Calculator for Straight Pipe")40st.write("""41This tool calculates the pressure drop in a straight pipe for both laminar and turbulent flow conditions. 42Provide the necessary inputs below, and the app will determine the pressure drop and Reynolds number.43""")44 45# Inputs46st.sidebar.header("Input Parameters")47diameter = st.sidebar.slider("Pipe Diameter (m)", min_value=0.01, max_value=1.0, value=0.1, step=0.01)48flow_rate = st.sidebar.slider("Flow Rate (L/s)", min_value=0.001, max_value=100.0, value=1.0, step=0.1) / 1000  # Convert to m^3/s49fluid = st.sidebar.selectbox("Fluid Type", ["Water", "Oil", "Air"])50pipe_length = st.sidebar.slider("Pipe Length (m)", min_value=0.1, max_value=100.0, value=10.0, step=0.1)51 52# Get fluid properties53fluid_props = get_fluid_properties(fluid)54if fluid_props["density"] and fluid_props["viscosity"]:55    density = fluid_props["density"]56    viscosity = fluid_props["viscosity"]57 58    # Calculate pressure drop59    pressure_drop, reynolds = calculate_pressure_drop(diameter, flow_rate, density, viscosity, pipe_length)60 61    # Output results62    st.subheader("Results")63    st.write(f"**Reynolds Number:** {reynolds:.2f}")64    st.write(f"**Pressure Drop:** {pressure_drop:.2f} Pa")65 66    # Flow type67    if reynolds < 2000:68        st.success("Flow Type: Laminar")69    else:70        st.success("Flow Type: Turbulent")71else:72    st.error("Invalid fluid selected or missing properties.")73 74st.write("""75---76### How to Use771. Adjust the input parameters using the sidebar.782. View the calculated pressure drop and Reynolds number.79 80**Note:** Ensure all inputs are within valid physical ranges.81""")82