Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| # Function to compute reactions and shear and moment diagrams | |
| def compute_beam_analysis(L1, L2, w, E, I): | |
| # Reactions at supports | |
| R1 = (w * L2 * (2 * L1 + L2)) / (2 * (L1 + L2)) | |
| R2 = (w * L1 * (2 * L2 + L1)) / (2 * (L1 + L2)) | |
| # Position vectors | |
| x1 = np.linspace(0, L1, 100) | |
| x2 = np.linspace(L1, L1 + L2, 100) | |
| # Shear force calculation | |
| V1 = R1 - w * x1 # For the first span | |
| V2 = R2 - w * (x2 - L1) # For the second span | |
| # Bending moment calculation | |
| M1 = R1 * x1 - 0.5 * w * x1**2 # For the first span | |
| M2 = R2 * (x2 - L1) - 0.5 * w * (x2 - L1)**2 # For the second span | |
| return x1, x2, V1, V2, M1, M2 | |
| # Streamlit App Layout | |
| st.title("Two Span Beam Analysis") | |
| st.sidebar.header("Input Parameters") | |
| L1 = st.sidebar.number_input("Length of Span 1 (L1) [m]", min_value=1.0, value=5.0) | |
| L2 = st.sidebar.number_input("Length of Span 2 (L2) [m]", min_value=1.0, value=5.0) | |
| w = st.sidebar.number_input("Uniform Load (w) [N/m]", min_value=1.0, value=10.0) | |
| E = st.sidebar.number_input("Modulus of Elasticity (E) [Pa]", min_value=1e3, value=2e11) | |
| I = st.sidebar.number_input("Moment of Inertia (I) [m^4]", min_value=1e-6, value=1e-4) | |
| # Calculate | |
| x1, x2, V1, V2, M1, M2 = compute_beam_analysis(L1, L2, w, E, I) | |
| # Plot Shear Force Diagram (SFD) | |
| fig, ax = plt.subplots(1, 2, figsize=(12, 6)) | |
| # Shear Force Diagram | |
| ax[0].plot(x1, V1, label="Span 1", color='blue') | |
| ax[0].plot(x2, V2, label="Span 2", color='green') | |
| ax[0].axhline(0, color='black',linewidth=0.5) | |
| ax[0].set_xlabel("Position along the beam (m)") | |
| ax[0].set_ylabel("Shear Force (N)") | |
| ax[0].set_title("Shear Force Diagram (SFD)") | |
| ax[0].legend() | |
| # Plot Bending Moment Diagram (BMD) | |
| ax[1].plot(x1, M1, label="Span 1", color='blue') | |
| ax[1].plot(x2, M2, label="Span 2", color='green') | |
| ax[1].axhline(0, color='black',linewidth=0.5) | |
| ax[1].set_xlabel("Position along the beam (m)") | |
| ax[1].set_ylabel("Bending Moment (Nm)") | |
| ax[1].set_title("Bending Moment Diagram (BMD)") | |
| ax[1].legend() | |
| # Show the plots | |
| st.pyplot(fig) | |
| # Display results | |
| st.subheader("Reactions at Supports") | |
| st.write(f"Reaction at support A (R1): {R1:.2f} N") | |
| st.write(f"Reaction at support B (R2): {R2:.2f} N") | |