Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,71 @@
|
|
1 |
-
import
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
def
|
4 |
"""
|
5 |
-
|
6 |
|
7 |
Parameters:
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
Returns:
|
16 |
-
str:
|
|
|
17 |
"""
|
18 |
-
#
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from apdl_generator.apdl_plate import generate_plate_apdl
|
3 |
+
from apdl_generator.apdl_beam import generate_beam_apdl
|
4 |
+
from simulators.python_simulation import run_python_simulation
|
5 |
+
from visualization import visualize_results
|
6 |
|
7 |
+
def simulation_workflow(tool_type, use_case, include_hole, include_force, include_load, thickness, length, width, hole_diameter, force, load):
|
8 |
"""
|
9 |
+
Main simulation workflow.
|
10 |
|
11 |
Parameters:
|
12 |
+
tool_type (str): 'Punch' or 'Die'.
|
13 |
+
use_case (str): 'plate' or 'beam'.
|
14 |
+
include_hole (bool): Whether to include a hole in the plate simulation.
|
15 |
+
include_force (bool): Whether to include force in the simulation.
|
16 |
+
include_load (bool): Whether to include load in the simulation.
|
17 |
+
thickness (float): Thickness of the material.
|
18 |
+
length (float): Length of the material.
|
19 |
+
width (float): Width of the material.
|
20 |
+
hole_diameter (float): Diameter of the hole (optional).
|
21 |
+
force (float): Applied force (optional).
|
22 |
+
load (float): Applied load (optional).
|
23 |
|
24 |
Returns:
|
25 |
+
results (str): Text result summarizing stress and deformation.
|
26 |
+
graph_path (str): Path to the 2D visualization.
|
27 |
"""
|
28 |
+
# Handle optional parameters
|
29 |
+
force = force if include_force else 0
|
30 |
+
load = load if include_load else 0
|
31 |
+
|
32 |
+
# Generate APDL script dynamically
|
33 |
+
if use_case == "plate":
|
34 |
+
hole_diameter = hole_diameter if include_hole else 0
|
35 |
+
apdl_path = generate_plate_apdl(thickness, length, width, hole_diameter, force)
|
36 |
+
elif use_case == "beam":
|
37 |
+
apdl_path = generate_beam_apdl(length, width, thickness, load)
|
38 |
+
else:
|
39 |
+
return "Invalid use case selected.", None
|
40 |
+
|
41 |
+
# Run simulation using Python-based solver
|
42 |
+
stress, deformation = run_python_simulation(apdl_path, use_case, thickness=thickness, length=length, width=width, force=force, load=load)
|
43 |
+
|
44 |
+
# Generate 2D visualization
|
45 |
+
graph_path, _ = visualize_results("Python-Based Solver", length, width, thickness, stress, deformation)
|
46 |
+
return f"{tool_type} Simulation\nStress: {stress:.2f} MPa\nDeformation: {deformation:.2f} mm", graph_path
|
47 |
+
|
48 |
+
interface = gr.Interface(
|
49 |
+
fn=simulation_workflow,
|
50 |
+
inputs=[
|
51 |
+
gr.Radio(["Punch", "Die"], label="Select Tool Type"),
|
52 |
+
gr.Radio(["plate", "beam"], label="Select Use Case"),
|
53 |
+
gr.Checkbox(label="Include Hole for Plate Simulation"), # Checkbox for optional hole
|
54 |
+
gr.Checkbox(label="Include Force"), # Checkbox for optional force
|
55 |
+
gr.Checkbox(label="Include Load"), # Checkbox for optional load
|
56 |
+
gr.Slider(10, 50, step=1, label="Thickness (mm)"),
|
57 |
+
gr.Slider(100, 500, step=10, label="Length (mm)"),
|
58 |
+
gr.Slider(50, 200, step=10, label="Width (mm)"),
|
59 |
+
gr.Slider(5, 25, step=1, label="Hole Diameter (mm)"), # Controlled by "Include Hole"
|
60 |
+
gr.Slider(1000, 10000, step=500, label="Force (N)"), # Controlled by "Include Force"
|
61 |
+
gr.Slider(1000, 20000, step=1000, label="Load (N)"), # Controlled by "Include Load"
|
62 |
+
],
|
63 |
+
outputs=[
|
64 |
+
gr.Textbox(label="Simulation Results"),
|
65 |
+
gr.Image(label="2D Results Visualization")
|
66 |
+
],
|
67 |
+
title="Punch and Die Simulation Tool (Python-Based)",
|
68 |
+
live=True
|
69 |
+
)
|
70 |
+
|
71 |
+
interface.launch()
|