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