Spaces:
Configuration error
Configuration error
Uploading files
Browse files- README.md +5 -13
- double_span_beam_analysis.py +113 -0
- requirements.txt +5 -0
README.md
CHANGED
@@ -1,13 +1,5 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version: 5.14.0
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
-
short_description: An application to automate beam theory
|
11 |
-
---
|
12 |
-
|
13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
+
# Beam Analysis Tool
|
2 |
+
|
3 |
+
This app allows you to analyze a two-span continuous beam with uniformly distributed loads on each span.
|
4 |
+
|
5 |
+
Enter the length of each span and the load per unit length on each span. The app calculates the bending moment and shear force along the beam and generates plots, along with downloadable CSV output.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
double_span_beam_analysis.py
ADDED
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sympy as sp
|
2 |
+
import numpy as np
|
3 |
+
import pandas as pd
|
4 |
+
import gradio as gr
|
5 |
+
import matplotlib.pyplot as plt
|
6 |
+
|
7 |
+
def solve_beam(l1_val, l2_val, q1_val, q2_val):
|
8 |
+
# Define the variables
|
9 |
+
Mx, l1, l2, q1, q2 = sp.symbols('Mx l1 l2 q1 q2')
|
10 |
+
|
11 |
+
# Equation to solve for Mx
|
12 |
+
equation = (Mx*l1/3 + q1*l1**3/24 + Mx*l2/3 + q2*l2**3/24)
|
13 |
+
Mx_solution = sp.solve(equation, Mx)
|
14 |
+
|
15 |
+
# Define variables for reactions
|
16 |
+
VA, VB1, VB2, VC, HA = sp.symbols('VA VB1 VB2 VC HA')
|
17 |
+
|
18 |
+
# System of equations for the first span
|
19 |
+
eq1_span1 = VA + VB1 - q1*l1
|
20 |
+
eq2_span1 = VB1*l1 - q1*l1**2/2 + Mx_solution[0]
|
21 |
+
|
22 |
+
# System of equations for the second span
|
23 |
+
eq1_span2 = VB2 + VC - q2*l2
|
24 |
+
eq2_span2 = VB2*l2 - q2*l2**2/2 + Mx_solution[0]
|
25 |
+
|
26 |
+
# Solve for the reactions for the first span
|
27 |
+
reactions_span1 = sp.solve((eq1_span1, eq2_span1), (VA, VB1))
|
28 |
+
|
29 |
+
# Solve for the reactions for the second span
|
30 |
+
reactions_span2 = sp.solve((eq1_span2, eq2_span2), (VB2, VC))
|
31 |
+
|
32 |
+
# Define variables for positions on the spans
|
33 |
+
x1, x2 = sp.symbols('x1 x2')
|
34 |
+
|
35 |
+
# Bending moment and shear for the first span
|
36 |
+
M1_expr = reactions_span1[VA] * x1 - q1 * x1**2 / 2
|
37 |
+
V1_expr = reactions_span1[VA] - q1 * x1
|
38 |
+
|
39 |
+
# Bending moment and shear for the second span
|
40 |
+
M2_expr = Mx_solution[0] - q2 * x2**2 / 2 + reactions_span2[VB2] * x2
|
41 |
+
V2_expr = reactions_span2[VB2] - q2 * x2
|
42 |
+
|
43 |
+
# Substitute the provided numerical values into the expressions
|
44 |
+
M1_expr = M1_expr.subs({l1: l1_val, q1: q1_val, l2: l2_val, q2: q2_val})
|
45 |
+
V1_expr = V1_expr.subs({l1: l1_val, q1: q1_val, l2: l2_val, q2: q2_val})
|
46 |
+
M2_expr = M2_expr.subs({l1: l1_val, q1: q1_val, l2: l2_val, q2: q2_val})
|
47 |
+
V2_expr = V2_expr.subs({l1: l1_val, q1: q1_val, l2: l2_val, q2: q2_val})
|
48 |
+
Mx_value = Mx_solution[0].subs({l1: l1_val, q1: q1_val, l2: l2_val, q2: q2_val})
|
49 |
+
|
50 |
+
# Generate numerical values for x1 and x2
|
51 |
+
x1_vals = np.arange(0, l1_val, 0.1)
|
52 |
+
x2_vals = np.arange(0, l2_val, 0.1)
|
53 |
+
|
54 |
+
# Evaluate M1 and V1 at each x1
|
55 |
+
M1_vals = [float(M1_expr.subs(x1, val)) for val in x1_vals]
|
56 |
+
V1_vals = [float(V1_expr.subs(x1, val)) for val in x1_vals]
|
57 |
+
|
58 |
+
# Evaluate M2 and V2 at each x2
|
59 |
+
M2_vals = [float(M2_expr.subs(x2, val)) for val in x2_vals]
|
60 |
+
V2_vals = [float(V2_expr.subs(x2, val)) for val in x2_vals]
|
61 |
+
|
62 |
+
# Create dataframes for beam1 and beam2
|
63 |
+
beam1 = pd.DataFrame({'x': x1_vals, 'M': M1_vals, 'V': V1_vals})
|
64 |
+
beam2 = pd.DataFrame({'x': x2_vals + l1_val, 'M': M2_vals, 'V': V2_vals})
|
65 |
+
|
66 |
+
# Concatenate beam1 and beam2 into one dataframe
|
67 |
+
beam = pd.concat([beam1, beam2], ignore_index=True)
|
68 |
+
|
69 |
+
return beam
|
70 |
+
|
71 |
+
def plot_beam(beam_df):
|
72 |
+
fig, axs = plt.subplots(2, 1, figsize=(8, 8))
|
73 |
+
|
74 |
+
# Plot bending moment
|
75 |
+
axs[0].plot(beam_df['x'], beam_df['M'], label='Bending Moment (M)')
|
76 |
+
axs[0].invert_yaxis()
|
77 |
+
axs[0].set_title('Bending Moment Diagram')
|
78 |
+
axs[0].set_xlabel('Position along the beam (x)')
|
79 |
+
axs[0].set_ylabel('Bending Moment (M)')
|
80 |
+
axs[0].legend()
|
81 |
+
|
82 |
+
# Plot shear force
|
83 |
+
axs[1].plot(beam_df['x'], beam_df['V'], label='Shear Force (V)')
|
84 |
+
axs[1].invert_yaxis()
|
85 |
+
axs[1].set_title('Shear Force Diagram')
|
86 |
+
axs[1].set_xlabel('Position along the beam (x)')
|
87 |
+
axs[1].set_ylabel('Shear Force (V)')
|
88 |
+
axs[1].legend()
|
89 |
+
|
90 |
+
plt.tight_layout()
|
91 |
+
return fig
|
92 |
+
|
93 |
+
def main(l1, l2, q1, q2):
|
94 |
+
beam_df = solve_beam(l1, l2, q1, q2)
|
95 |
+
csv_file = 'beam_analysis.csv'
|
96 |
+
beam_df.to_csv(csv_file, index=False)
|
97 |
+
fig = plot_beam(beam_df)
|
98 |
+
return beam_df, csv_file, fig
|
99 |
+
|
100 |
+
inputs = [
|
101 |
+
gr.components.Number(label="Length of span 1 (l(m)))"),
|
102 |
+
gr.components.Number(label="Length of span 2 (l2(m))"),
|
103 |
+
gr.components.Number(label="Load on span 1 (q1(kN/m))"),
|
104 |
+
gr.components.Number(label="Load on span 2 (q2(kN/m))")
|
105 |
+
]
|
106 |
+
|
107 |
+
outputs = [
|
108 |
+
gr.components.Dataframe(label="Beam Analysis Data"),
|
109 |
+
gr.components.File(label="Download CSV"),
|
110 |
+
gr.components.Plot(label="Bending Moment and Shear Force Diagrams")
|
111 |
+
]
|
112 |
+
|
113 |
+
gr.Interface(fn=main, inputs=inputs, outputs=outputs, title="Beam Analysis Tool").launch()
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
sympy
|
2 |
+
numpy
|
3 |
+
pandas
|
4 |
+
gradio
|
5 |
+
matplotlib
|