Spaces:
Sleeping
Sleeping
File size: 3,252 Bytes
844bdc9 739726e 2a7487a 739726e 1e07532 844bdc9 1e07532 844bdc9 1e07532 844bdc9 1e07532 844bdc9 739726e 844bdc9 739726e 844bdc9 739726e 844bdc9 739726e 844bdc9 739726e 844bdc9 739726e 844bdc9 |
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 |
import gradio as gr
from apdl_generator.apdl_plate import generate_plate_apdl
from apdl_generator.apdl_beam import generate_beam_apdl
from simulators.python_simulation import run_python_simulation
from visualization import visualize_results
def simulation_workflow(tool_type, use_case, include_hole, include_force, include_load, thickness, length, width, hole_diameter, force, load):
"""
Main simulation workflow.
Parameters:
tool_type (str): 'Punch' or 'Die'.
use_case (str): 'plate' or 'beam'.
include_hole (bool): Whether to include a hole in the plate simulation.
include_force (bool): Whether to include force in the simulation.
include_load (bool): Whether to include load in the simulation.
thickness (float): Thickness of the material.
length (float): Length of the material.
width (float): Width of the material.
hole_diameter (float): Diameter of the hole (optional).
force (float): Applied force (optional).
load (float): Applied load (optional).
Returns:
results (str): Text result summarizing stress and deformation.
graph_path (str): Path to the 2D visualization.
"""
# Handle optional parameters
force = force if include_force else 0
load = load if include_load else 0
# Generate APDL script dynamically
if use_case == "plate":
hole_diameter = hole_diameter if include_hole else 0
apdl_path = generate_plate_apdl(thickness, length, width, hole_diameter, force)
elif use_case == "beam":
apdl_path = generate_beam_apdl(length, width, thickness, load)
else:
return "Invalid use case selected.", None
# Run simulation using Python-based solver
stress, deformation = run_python_simulation(apdl_path, use_case, thickness=thickness, length=length, width=width, force=force, load=load)
# Generate 2D visualization
graph_path, _ = visualize_results("Python-Based Solver", length, width, thickness, stress, deformation)
return f"{tool_type} Simulation\nStress: {stress:.2f} MPa\nDeformation: {deformation:.2f} mm", graph_path
interface = gr.Interface(
fn=simulation_workflow,
inputs=[
gr.Radio(["Punch", "Die"], label="Select Tool Type"),
gr.Radio(["plate", "beam"], label="Select Use Case"),
gr.Checkbox(label="Include Hole for Plate Simulation"), # Checkbox for optional hole
gr.Checkbox(label="Include Force"), # Checkbox for optional force
gr.Checkbox(label="Include Load"), # Checkbox for optional load
gr.Slider(10, 50, step=1, label="Thickness (mm)"),
gr.Slider(100, 500, step=10, label="Length (mm)"),
gr.Slider(50, 200, step=10, label="Width (mm)"),
gr.Slider(5, 25, step=1, label="Hole Diameter (mm)"), # Controlled by "Include Hole"
gr.Slider(1000, 10000, step=500, label="Force (N)"), # Controlled by "Include Force"
gr.Slider(1000, 20000, step=1000, label="Load (N)"), # Controlled by "Include Load"
],
outputs=[
gr.Textbox(label="Simulation Results"),
gr.Image(label="2D Results Visualization")
],
title="Punch and Die Simulation Tool (Python-Based)",
live=True
)
interface.launch()
|