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()