AamerAkhter commited on
Commit
f32dd0d
·
verified ·
1 Parent(s): 4abd422

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -0
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import math
3
+ import matplotlib.pyplot as plt
4
+ import numpy as np
5
+
6
+ # Function to calculate pipe diameter
7
+ def calculate_diameter(flow_rate, velocity):
8
+ # Formula to calculate pipe diameter (d = sqrt(4 * Q / (pi * v)))
9
+ # Where Q is flow rate (in cubic meters per second)
10
+ # v is the velocity (in meters per second)
11
+ diameter = math.sqrt(4 * flow_rate / (math.pi * velocity))
12
+ return diameter
13
+
14
+ # Function to plot the graph
15
+ def plot_diameter_graph():
16
+ # Define a range of flow rates (Q) and velocities (v)
17
+ flow_rate_values = np.linspace(0.01, 1.0, 100) # Range of flow rates (0.01 to 1.0 m³/s)
18
+ velocity_values = np.linspace(0.1, 5.0, 50) # Range of velocities (0.1 to 5.0 m/s)
19
+
20
+ # Create a meshgrid for the flow rates and velocities
21
+ flow_rate_grid, velocity_grid = np.meshgrid(flow_rate_values, velocity_values)
22
+
23
+ # Calculate the pipe diameter for each combination of flow rate and velocity
24
+ diameter_values = np.sqrt(4 * flow_rate_grid / (np.pi * velocity_grid))
25
+
26
+ # Plotting the graph
27
+ fig, ax = plt.subplots(figsize=(10, 6))
28
+ cp = ax.contourf(flow_rate_grid, velocity_grid, diameter_values, cmap='viridis')
29
+ fig.colorbar(cp, ax=ax, label='Pipe Diameter (m)')
30
+ ax.set_xlabel('Flow Rate (m³/s)')
31
+ ax.set_ylabel('Velocity (m/s)')
32
+ ax.set_title('Pipe Diameter vs. Flow Rate and Velocity')
33
+
34
+ # Display the plot in Streamlit
35
+ st.pyplot(fig)
36
+
37
+ # Streamlit App
38
+ def main():
39
+ # Set the page configuration with a title, icon, and layout style
40
+ st.set_page_config(
41
+ page_title="Pipe Sizing Helper",
42
+ page_icon="💧", # Water-related icon
43
+ layout="centered", # Center the content
44
+ )
45
+
46
+ # Title and description
47
+ st.title("Pipe Sizing Helper 💧")
48
+ st.markdown("Enter the flow rate and permissible velocity to get the recommended pipe diameter.")
49
+
50
+ # Input fields for flow rate and velocity
51
+ flow_rate = st.number_input("Enter Flow Rate (m³/s):", min_value=0.0, step=0.01)
52
+ velocity = st.number_input("Enter Permissible Velocity (m/s):", min_value=0.0, step=0.1)
53
+
54
+ # Create a button to calculate the recommended pipe diameter
55
+ if st.button("Generate Pipe Diameter"):
56
+ # Check if both flow rate and velocity are greater than zero
57
+ if flow_rate > 0 and velocity > 0:
58
+ diameter = calculate_diameter(flow_rate, velocity)
59
+ st.write(f"The recommended pipe diameter is: **{diameter:.2f} meters**")
60
+ else:
61
+ st.error("Please enter valid values for flow rate and velocity.")
62
+
63
+ # Show the graphical visualization of pipe diameter vs flow rate and velocity
64
+ st.subheader("Graphical Visualization")
65
+ plot_diameter_graph()
66
+
67
+ # Add some helpful info or tips
68
+ st.markdown("""
69
+ ### Tips:
70
+ - Flow rate (Q) is the volume of fluid passing through the pipe per unit of time (in cubic meters per second).
71
+ - Permissible velocity (v) is the maximum allowable speed of the fluid inside the pipe (in meters per second).
72
+ """)
73
+
74
+ if __name__ == "__main__":
75
+ main()