File size: 2,969 Bytes
a358a71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2bedf16
 
 
 
a358a71
 
2bedf16
 
 
 
 
a358a71
 
 
 
 
 
 
 
 
 
 
2bedf16
 
 
a358a71
 
 
2bedf16
a358a71
2bedf16
a358a71
 
 
2bedf16
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import streamlit as st
import numpy as np

def get_fluid_properties(fluid):
    """Returns density (kg/m^3) and viscosity (Pa.s) of the fluid."""
    properties = {
        "Water": {"density": 1000, "viscosity": 0.001},
        "Oil": {"density": 800, "viscosity": 0.05},
        "Air": {"density": 1.2, "viscosity": 1.8e-5},
    }
    return properties.get(fluid, {"density": None, "viscosity": None})

def calculate_reynolds_number(density, velocity, diameter, viscosity):
    """Calculates the Reynolds number."""
    return (density * velocity * diameter) / viscosity

def calculate_pressure_drop(diameter, flow_rate, density, viscosity, length=1.0):
    """Calculates pressure drop in a straight pipe."""
    # Calculate velocity
    area = np.pi * (diameter / 2) ** 2
    velocity = flow_rate / area

    # Reynolds number
    reynolds = calculate_reynolds_number(density, velocity, diameter, viscosity)

    # Friction factor
    if reynolds < 2000:
        # Laminar flow
        friction_factor = 64 / reynolds
    else:
        # Turbulent flow (Blasius correlation)
        friction_factor = 0.3164 / (reynolds ** 0.25)

    # Pressure drop (Darcy-Weisbach equation)
    pressure_drop = (friction_factor * length * density * velocity**2) / (2 * diameter)
    return pressure_drop, reynolds

# Streamlit App
st.title("Pressure Drop Calculator for Straight Pipe")
st.write("""
This tool calculates the pressure drop in a straight pipe for both laminar and turbulent flow conditions. 
Provide the necessary inputs below, and the app will determine the pressure drop and Reynolds number.
""")

# Inputs
st.sidebar.header("Input Parameters")
diameter = st.sidebar.slider("Pipe Diameter (m)", min_value=0.01, max_value=1.0, value=0.1, step=0.01)
flow_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/s
fluid = st.sidebar.selectbox("Fluid Type", ["Water", "Oil", "Air"])
pipe_length = st.sidebar.slider("Pipe Length (m)", min_value=0.1, max_value=100.0, value=10.0, step=0.1)

# Get fluid properties
fluid_props = get_fluid_properties(fluid)
if fluid_props["density"] and fluid_props["viscosity"]:
    density = fluid_props["density"]
    viscosity = fluid_props["viscosity"]

    # Calculate pressure drop
    pressure_drop, reynolds = calculate_pressure_drop(diameter, flow_rate, density, viscosity, pipe_length)

    # Output results
    st.subheader("Results")
    st.write(f"**Reynolds Number:** {reynolds:.2f}")
    st.write(f"**Pressure Drop:** {pressure_drop:.2f} Pa")

    # Flow type
    if reynolds < 2000:
        st.success("Flow Type: Laminar")
    else:
        st.success("Flow Type: Turbulent")
else:
    st.error("Invalid fluid selected or missing properties.")

st.write("""
---
### How to Use
1. Adjust the input parameters using the sidebar.
2. View the calculated pressure drop and Reynolds number.

**Note:** Ensure all inputs are within valid physical ranges.
""")