Spaces:
Build error
Build error
Download app.py from Zainulabedin1/BeamDeflectionCalculator: direct link, hf CLI and curl.
- Browser
- Download file 2.92 kB
-
https://huggingface.co/spaces/Zainulabedin1/BeamDeflectionCalculator/resolve/main/app.py
- Command line
-
hf download hf://spaces/Zainulabedin1/BeamDeflectionCalculator/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Zainulabedin1/BeamDeflectionCalculator/resolve/main/app.py
2.92 kB
| import streamlit as st | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| # Title and description | |
| st.title("Beam Deflection Calculator") | |
| st.markdown(""" | |
| ### Problem: | |
| This app calculates the deflection of a beam under a load. It is designed for mechanical engineers who need accurate and quick calculations during design. | |
| ### Instructions: | |
| 1. Enter the beam parameters below. | |
| 2. Select the type of support and load. | |
| 3. The app will calculate the maximum deflection and plot the deflection curve. | |
| """) | |
| # User Inputs | |
| st.sidebar.header("Beam Parameters") | |
| length = st.sidebar.number_input("Beam Length (m)", min_value=0.1, step=0.1, value=5.0) | |
| load = st.sidebar.number_input("Load Magnitude (N)", min_value=0.0, step=1.0, value=1000.0) | |
| youngs_modulus = st.sidebar.number_input("Young's Modulus (Pa)", min_value=1e6, step=1e6, value=2.0e11) | |
| moment_of_inertia = st.sidebar.number_input("Moment of Inertia (m⁴)", min_value=1e-6, step=1e-6, value=1.0e-4) | |
| support_type = st.sidebar.selectbox("Support Type", ["Simply Supported", "Fixed Supported"]) | |
| load_type = st.sidebar.selectbox("Load Type", ["Point Load at Center", "Uniformly Distributed Load"]) | |
| # Calculation | |
| x = np.linspace(0, length, 500) | |
| if support_type == "Simply Supported" and load_type == "Point Load at Center": | |
| max_deflection = (load * length**3) / (48 * youngs_modulus * moment_of_inertia) | |
| deflection = (load * x * (length**3 - 2 * length * x**2 + x**3)) / (48 * youngs_modulus * moment_of_inertia) | |
| elif support_type == "Simply Supported" and load_type == "Uniformly Distributed Load": | |
| max_deflection = (5 * load * length**4) / (384 * youngs_modulus * moment_of_inertia) | |
| deflection = ((load * x**2) / (24 * youngs_modulus * moment_of_inertia)) * (length**3 - 2 * length * x**2 + x**3) | |
| elif support_type == "Fixed Supported" and load_type == "Point Load at Center": | |
| max_deflection = (load * length**3) / (192 * youngs_modulus * moment_of_inertia) | |
| deflection = (load * x**2 * (3 * length - x)) / (48 * youngs_modulus * moment_of_inertia) | |
| elif support_type == "Fixed Supported" and load_type == "Uniformly Distributed Load": | |
| max_deflection = (load * length**4) / (384 * youngs_modulus * moment_of_inertia) | |
| deflection = (load * x**2 * (length - x)**2) / (24 * youngs_modulus * moment_of_inertia) | |
| else: | |
| st.error("Invalid combination of support and load type.") | |
| deflection = None | |
| # Display Results | |
| if deflection is not None: | |
| st.subheader("Results") | |
| st.write(f"**Maximum Deflection**: {max_deflection:.5e} m") | |
| # Plot Deflection Curve | |
| st.subheader("Deflection Curve") | |
| fig, ax = plt.subplots() | |
| ax.plot(x, deflection, label="Deflection Curve") | |
| ax.axhline(0, color="black", linewidth=0.5, linestyle="--") | |
| ax.set_title("Beam Deflection Curve") | |
| ax.set_xlabel("Position along the beam (m)") | |
| ax.set_ylabel("Deflection (m)") | |
| ax.legend() | |
| ax.grid(True) | |
| st.pyplot(fig) | |