File size: 1,545 Bytes
8f76ca8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import math

# Title and Description
st.title("🔧 Pipe Sizing Helper")
st.write("""
This app helps you determine the required pipe diameter based on the flow rate and fluid velocity.  
Simply input the flow rate (in cubic meters per second) and velocity (in meters per second) to get the pipe diameter.
""")

# Sidebar Instructions
st.sidebar.title("How to Use")
st.sidebar.write("""
1. Enter the flow rate of the fluid in m³/s.  
2. Enter the velocity of the fluid in m/s.  
3. Click **Calculate** to get the required pipe diameter.  
4. Reset inputs using the **Clear Inputs** button.
""")

# User Inputs
st.subheader("Input Parameters")
flow_rate = st.number_input("Flow Rate (Q) in m³/s:", min_value=0.0, format="%.6f", step=0.01)
velocity = st.number_input("Fluid Velocity (v) in m/s:", min_value=0.1, format="%.2f", step=0.1)

# Calculate Button
if st.button("Calculate"):
    if flow_rate <= 0:
        st.error("Flow rate must be greater than zero!")
    elif velocity <= 0:
        st.error("Velocity must be greater than zero!")
    else:
        # Calculate pipe diameter
        diameter = math.sqrt((4 * flow_rate) / (math.pi * velocity))
        diameter_mm = diameter * 1000  # Convert to mm
        st.subheader("Results")
        st.write(f"**Required Pipe Diameter:** {diameter:.4f} meters ({diameter_mm:.2f} mm)")

# Reset Inputs
if st.button("Clear Inputs"):
    flow_rate = 0.0
    velocity = 0.0
    st.experimental_rerun()

# Footer
st.write("---")
st.markdown("💡 **Developed by Abdullah**")