Spaces:
Build error
Build error
File size: 3,317 Bytes
4705f3c 5fcabc3 4705f3c 5fcabc3 015c6a8 4705f3c 4f6ea23 b72ca25 5fcabc3 4705f3c b72ca25 4f6ea23 4705f3c b72ca25 4705f3c b72ca25 4705f3c b72ca25 5fcabc3 b72ca25 5fcabc3 4f6ea23 b72ca25 5fcabc3 4f6ea23 b72ca25 4f6ea23 4705f3c b72ca25 5fcabc3 b72ca25 4f6ea23 b72ca25 4f6ea23 4705f3c 5fcabc3 4705f3c 5fcabc3 2f223c4 5fcabc3 4705f3c 5fcabc3 4705f3c 2f223c4 4705f3c 5fcabc3 b72ca25 4705f3c |
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 |
import gradio as gr
import subprocess
from apdl_generator.apdl_plate import generate_plate_apdl
from apdl_generator.apdl_beam import generate_beam_apdl
from simulators.pycalculix_simulation import run_pycalculix_simulation
from simulators.ansys_simulation import run_ansys_simulation
from visualization import visualize_results
def simulation_workflow(use_case, simulator, **kwargs):
print(f"Running simulation for use_case={use_case}, simulator={simulator}")
# Generate APDL script based on user inputs
if use_case == "plate":
print("Generating APDL script for plate simulation...")
apdl_path = generate_plate_apdl(kwargs["thickness"], kwargs["length"], kwargs["width"], kwargs["hole_diameter"], kwargs["force"])
elif use_case == "beam":
print("Generating APDL script for beam simulation...")
apdl_path = generate_beam_apdl(kwargs["length"], kwargs["width"], kwargs["thickness"], kwargs["load"])
else:
print("Invalid use case selected.")
return "Invalid use case selected.", None, None
print(f"APDL script generated at: {apdl_path}")
# Run the selected simulator
if simulator == "PyCalculix":
print("Running PyCalculix simulation...")
stress, deformation = run_pycalculix_simulation(use_case, **kwargs)
elif simulator == "ANSYS":
print("Running ANSYS simulation...")
stress, deformation = run_ansys_simulation(apdl_path)
else:
print("Invalid simulator selected.")
return "Invalid simulator selected.", None, None
print(f"Simulation results - Stress: {stress}, Deformation: {deformation}")
# Visualize results (both 2D and 3D)
print("Visualizing results...")
graph_path, three_d_path = visualize_results(simulator, kwargs["length"], kwargs["width"], kwargs["thickness"], stress, deformation)
print(f"Visualization paths - 2D: {graph_path}, 3D: {three_d_path}")
return f"Stress: {stress:.2f} MPa, Deformation: {deformation:.2f} mm", graph_path, three_d_path
# Define Gradio interface
interface = gr.Interface(
fn=simulation_workflow,
inputs=[
gr.Radio(["plate", "beam"], label="Select Use Case"), # Choose plate or beam simulation
gr.Dropdown(["PyCalculix", "ANSYS"], label="Select Simulator"), # Choose simulator
gr.Slider(10, 50, step=1, label="Thickness (mm)"), # Input: Thickness
gr.Slider(100, 500, step=10, label="Length (mm)"), # Input: Length
gr.Slider(50, 200, step=10, label="Width (mm)"), # Input: Width
gr.Slider(5, 25, step=1, label="Hole Diameter (mm)", optional=True), # Input: Hole Diameter (for plate)
gr.Slider(1000, 10000, step=500, label="Force (N)", optional=True), # Input: Force (for plate)
gr.Slider(1000, 20000, step=1000, label="Load (N)", optional=True) # Input: Load (for beam)
],
outputs=[
gr.Textbox(label="Simulation Results"), # Output: Simulation text results
gr.Image(label="2D Results Visualization"), # Output: 2D plot (stress and deformation)
gr.Image(label="3D Results Visualization") # Output: 3D plot (stress distribution)
],
title="Unified Simulation Tool (PyCalculix and ANSYS)",
live=True
)
# Launch Gradio interface
print("Launching Gradio interface...")
interface.launch()
|