Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| 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.fenics_simulation import run_fenics_simulation | |
| from simulators.ansys_simulation import run_ansys_simulation | |
| from visualization import visualize_results | |
| def simulation_workflow(use_case, simulator, **kwargs): | |
| if use_case == "plate": | |
| apdl_path = generate_plate_apdl(kwargs["thickness"], kwargs["length"], kwargs["width"], kwargs["hole_diameter"], kwargs["force"]) | |
| elif use_case == "beam": | |
| apdl_path = generate_beam_apdl(kwargs["length"], kwargs["width"], kwargs["thickness"], kwargs["load"]) | |
| else: | |
| return "Invalid use case selected.", None | |
| if simulator == "PyCalculix": | |
| stress, deformation = run_pycalculix_simulation(use_case, **kwargs) | |
| elif simulator == "FEniCS": | |
| stress, deformation = run_fenics_simulation(use_case, **kwargs) | |
| elif simulator == "ANSYS": | |
| stress, deformation = run_ansys_simulation(apdl_path) | |
| else: | |
| return "Invalid simulator selected.", None | |
| graph_path, three_d_path = visualize_results(simulator, kwargs["length"], kwargs["width"], kwargs["thickness"], stress, deformation) | |
| return f"Stress: {stress:.2f} MPa, Deformation: {deformation:.2f} mm", graph_path, three_d_path | |
| interface = gr.Interface( | |
| fn=simulation_workflow, | |
| inputs=[ | |
| gr.Radio(["plate", "beam"], label="Select Use Case"), | |
| gr.Dropdown(["PyCalculix", "FEniCS", "ANSYS"], label="Select Simulator"), | |
| 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)", optional=True), | |
| gr.Slider(1000, 10000, step=500, label="Force (N)", optional=True), | |
| gr.Slider(1000, 20000, step=1000, label="Load (N)", optional=True) | |
| ], | |
| outputs=[ | |
| gr.Textbox(label="Simulation Results"), | |
| gr.Image(label="2D Results Visualization"), | |
| gr.Image(label="3D Results Visualization") | |
| ], | |
| title="3D Unified Simulation Tool", | |
| live=True | |
| ) | |
| interface.launch() | |