Spaces:
Sleeping
Sleeping
File size: 2,993 Bytes
edcd635 e956a7f edcd635 2ff98a6 edcd635 e956a7f 2ff98a6 edcd635 2ff98a6 edcd635 e956a7f |
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 |
import streamlit as st
import math
import matplotlib.pyplot as plt
import numpy as np
def calculate_pipe_diameter(flow_rate, velocity):
"""Calculate the pipe diameter using the formula:
Diameter = sqrt((4 * Flow Rate) / (pi * Velocity))
"""
if velocity <= 0:
return None # Velocity must be greater than zero
diameter = math.sqrt((4 * flow_rate) / (math.pi * velocity))
return diameter
def main():
st.set_page_config(page_title="Pipe Sizing Helper", page_icon="🔧", layout="centered")
st.title("🔧 Pipe Sizing Helper")
st.write("This tool calculates the recommended pipe diameter based on flow rate and permissible velocity.")
# Input fields
flow_rate = st.number_input(
"Enter Flow Rate (m³/s):",
min_value=0.0,
format="%.4f",
help="The volumetric flow rate of the fluid (e.g., 0.1 for 0.1 m³/s)."
)
velocity = st.number_input(
"Enter Permissible Velocity (m/s):",
min_value=0.01,
format="%.2f",
help="The maximum allowable velocity of the fluid in the pipe."
)
# Button to calculate pipe diameter
calculate_button = st.button("🔄 Generate Pipe Diameter")
if calculate_button:
if velocity > 0:
diameter = calculate_pipe_diameter(flow_rate, velocity)
if diameter:
st.success(f"The recommended pipe diameter is {diameter:.4f} meters.")
else:
st.error("Invalid input. Please ensure flow rate and velocity are positive values.")
else:
st.error("Velocity must be greater than zero.")
# Graphical visualization
st.markdown("### Pipe Diameter Visualization")
st.write("This graph shows the relationship between pipe diameter and velocity for the specified flow rate.")
min_velocity = st.sidebar.number_input("Minimum Velocity (m/s):", min_value=0.01, value=0.5, step=0.1, format="%.2f")
max_velocity = st.sidebar.number_input("Maximum Velocity (m/s):", min_value=min_velocity + 0.1, value=5.0, step=0.1, format="%.2f")
velocities = np.linspace(min_velocity, max_velocity, 100)
diameters = [calculate_pipe_diameter(flow_rate, v) for v in velocities]
fig, ax = plt.subplots()
ax.plot(velocities, diameters, label="Pipe Diameter vs Velocity", color="blue")
ax.set_xlabel("Velocity (m/s)")
ax.set_ylabel("Pipe Diameter (m)")
ax.set_title("Recommended Pipe Diameter Across Velocity Range")
ax.grid(True)
ax.legend()
st.pyplot(fig)
# Sidebar for additional information
st.sidebar.header("About the App")
st.sidebar.markdown("This application helps you calculate the recommended pipe diameter for a given flow rate and velocity.")
st.sidebar.markdown("---")
st.sidebar.info("Uses basic fluid mechanics principles for pipe sizing calculations.")
# Footer
st.markdown("---")
st.markdown("**Developed by [Your Name]**")
if __name__ == "__main__":
main()
|