Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import math | |
| import numpy as np | |
| import plotly.graph_objects as go | |
| # Streamlit App Title | |
| st.title("Pipe Sizing Meter") | |
| st.write("Calculate the recommended pipe diameter based on flow rate and permissible velocity.") | |
| # Input Fields for Specific Flow Rate and Velocity | |
| flow_rate = st.number_input("Enter the Flow Rate (m³/s):", min_value=0.0, step=0.01) | |
| velocity = st.number_input("Enter the Permissible Flow Velocity (m/s):", min_value=0.0, step=0.01) | |
| # Calculate and Display Specific Diameter | |
| if flow_rate > 0 and velocity > 0: | |
| diameter = math.sqrt((4 * flow_rate) / (math.pi * velocity)) | |
| st.success(f"Recommended Pipe Diameter: {diameter:.3f} meters") | |
| else: | |
| st.warning("Please enter valid positive values for flow rate and velocity.") | |
| # Visualization Section | |
| st.header("Visualization: Pipe Diameter Across Flow Rate and Velocity Ranges") | |
| # Input Ranges for Visualization | |
| st.sidebar.header("Visualization Settings") | |
| flow_rate_min = st.sidebar.number_input("Minimum Flow Rate (m³/s):", min_value=0.0, value=0.01) | |
| flow_rate_max = st.sidebar.number_input("Maximum Flow Rate (m³/s):", min_value=0.0, value=1.0) | |
| velocity_min = st.sidebar.number_input("Minimum Velocity (m/s):", min_value=0.1, value=0.1) | |
| velocity_max = st.sidebar.number_input("Maximum Velocity (m/s):", min_value=0.1, value=5.0) | |
| # Generate Data for Visualization | |
| if flow_rate_min < flow_rate_max and velocity_min < velocity_max: | |
| flow_rates = np.linspace(flow_rate_min, flow_rate_max, 50) | |
| velocities = np.linspace(velocity_min, velocity_max, 50) | |
| flow_rate_grid, velocity_grid = np.meshgrid(flow_rates, velocities) | |
| # Calculate Diameters | |
| diameter_grid = np.sqrt((4 * flow_rate_grid) / (np.pi * velocity_grid)) | |
| # Create 3D Surface Plot | |
| fig = go.Figure(data=[go.Surface( | |
| z=diameter_grid, | |
| x=flow_rate_grid, | |
| y=velocity_grid, | |
| colorscale='Viridis' | |
| )]) | |
| fig.update_layout( | |
| title="Pipe Diameter vs Flow Rate and Velocity", | |
| scene=dict( | |
| xaxis_title="Flow Rate (m³/s)", | |
| yaxis_title="Velocity (m/s)", | |
| zaxis_title="Pipe Diameter (m)" | |
| ) | |
| ) | |
| # Display Plot | |
| st.plotly_chart(fig) | |
| else: | |
| st.error("Ensure that maximum values are greater than minimum values for both flow rate and velocity.") | |