File size: 4,107 Bytes
6c59865
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import gradio as gr
import numpy as np
from math import pi

# Beam Deflection Calculator (Euler-Bernoulli)
def beam_deflection(load, length, elasticity, inertia, support_type):
    """
    Calculate deflection for common beam supports.
    Units: Load (N), Length (m), Elasticity (Pa), Inertia (m^4)
    """
    if support_type == "Simply Supported (Center Load)":
        deflection = (load * length**3) / (48 * elasticity * inertia)
    elif support_type == "Cantilever (End Load)":
        deflection = (load * length**3) / (3 * elasticity * inertia)
    elif support_type == "Simply Supported (Uniform Load)":
        deflection = (5 * load * length**4) / (384 * elasticity * inertia)
    else:
        return "Invalid support type"
    return f"Max Deflection: {deflection * 1000:.2f} mm"

# Section Properties Calculator
def section_properties(width, height, shape):
    """Calculate area and moment of inertia for rectangular or circular sections."""
    if shape == "Rectangle":
        area = width * height
        inertia = (width * height**3) / 12
    elif shape == "Circle":
        diameter = width
        area = pi * (diameter / 2)**2
        inertia = pi * (diameter**4) / 64
    else:
        return "Invalid shape"
    return f"Area: {area:.2f} m² | Moment of Inertia: {inertia:.4f} m⁴"

# Load Capacity Estimator (Simplified)
def load_capacity(material, cross_section_area, safety_factor):
    """Estimate allowable load based on material strength."""
    material_strength = {
        "Concrete (20MPa)": 20e6,
        "Steel (A36)": 250e6,
        "Wood (Pine)": 10e6
    }
    allowable_stress = material_strength[material] / safety_factor
    capacity = allowable_stress * cross_section_area
    return f"Allowable Load: {capacity / 1000:.2f} kN"

# Gradio UI
with gr.Blocks(title="Structural Engineering Toolkit") as app:
    gr.Markdown("# 🏗️ Structural Engineering Toolkit")
    
    with gr.Tab("Beam Deflection"):
        gr.Markdown("### Calculate beam deflection under load")
        with gr.Row():
            load = gr.Number(label="Load (N)")
            length = gr.Number(label="Length (m)")
        elasticity = gr.Number(label="Elasticity Modulus (Pa)", value=2.1e11)  # Steel default
        inertia = gr.Number(label="Moment of Inertia (m⁴)", value=1e-6)
        support_type = gr.Dropdown(
            ["Simply Supported (Center Load)", "Cantilever (End Load)", "Simply Supported (Uniform Load)"],
            label="Support Type"
        )
        deflection_output = gr.Textbox(label="Result")
        gr.Button("Calculate").click(
            beam_deflection,
            inputs=[load, length, elasticity, inertia, support_type],
            outputs=deflection_output
        )

    with gr.Tab("Section Properties"):
        gr.Markdown("### Calculate geometric properties of sections")
        shape = gr.Dropdown(["Rectangle", "Circle"], label="Shape")
        width = gr.Number(label="Width/Diameter (m)")
        height = gr.Number(label="Height (m)", visible=True)
        shape.change(
            lambda x: gr.Number(visible=(x == "Rectangle")),
            inputs=shape,
            outputs=height
        )
        section_output = gr.Textbox(label="Result")
        gr.Button("Calculate").click(
            section_properties,
            inputs=[width, height, shape],
            outputs=section_output
        )

    with gr.Tab("Load Capacity"):
        gr.Markdown("### Estimate allowable load for materials")
        material = gr.Dropdown(
            ["Concrete (20MPa)", "Steel (A36)", "Wood (Pine)"],
            label="Material"
        )
        cross_section_area = gr.Number(label="Cross-Section Area (m²)", value=0.01)
        safety_factor = gr.Slider(1.5, 5, value=2.5, label="Safety Factor")
        capacity_output = gr.Textbox(label="Result")
        gr.Button("Calculate").click(
            load_capacity,
            inputs=[material, cross_section_area, safety_factor],
            outputs=capacity_output
        )

    gr.Markdown("---\n**Note:** This is a simplified tool for educational purposes.")

app.launch()