Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,14 @@
|
|
| 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.fenics_simulation import run_fenics_simulation
|
|
|
|
| 5 |
from simulators.ansys_simulation import run_ansys_simulation
|
| 6 |
from visualization import visualize_results
|
| 7 |
|
| 8 |
def simulation_workflow(use_case, simulator, **kwargs):
|
|
|
|
| 9 |
if use_case == "plate":
|
| 10 |
apdl_path = generate_plate_apdl(kwargs["thickness"], kwargs["length"], kwargs["width"], kwargs["hole_diameter"], kwargs["force"])
|
| 11 |
elif use_case == "beam":
|
|
@@ -13,39 +16,42 @@ def simulation_workflow(use_case, simulator, **kwargs):
|
|
| 13 |
else:
|
| 14 |
return "Invalid use case selected.", None, None
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
elif simulator == "ANSYS":
|
| 19 |
-
|
| 20 |
else:
|
| 21 |
return "Invalid simulator selected.", None, None
|
| 22 |
|
| 23 |
-
|
| 24 |
-
return f"Simulation failed: {result.stderr}", None, None
|
| 25 |
-
|
| 26 |
-
stress, deformation = map(float, result.stdout.split())
|
| 27 |
graph_path, three_d_path = visualize_results(simulator, kwargs["length"], kwargs["width"], kwargs["thickness"], stress, deformation)
|
| 28 |
return f"Stress: {stress:.2f} MPa, Deformation: {deformation:.2f} mm", graph_path, three_d_path
|
| 29 |
|
|
|
|
| 30 |
interface = gr.Interface(
|
| 31 |
fn=simulation_workflow,
|
| 32 |
inputs=[
|
| 33 |
-
gr.Radio(["plate", "beam"], label="Select Use Case"),
|
| 34 |
-
gr.Dropdown(["FEniCS", "ANSYS"], label="Select Simulator"),
|
| 35 |
-
gr.Slider(10, 50, step=1, label="Thickness (mm)"),
|
| 36 |
-
gr.Slider(100, 500, step=10, label="Length (mm)"),
|
| 37 |
-
gr.Slider(50, 200, step=10, label="Width (mm)"),
|
| 38 |
-
gr.Slider(5, 25, step=1, label="Hole Diameter (mm)", optional=True),
|
| 39 |
-
gr.Slider(1000, 10000, step=500, label="Force (N)", optional=True),
|
| 40 |
-
gr.Slider(1000, 20000, step=1000, label="Load (N)", optional=True)
|
| 41 |
],
|
| 42 |
outputs=[
|
| 43 |
-
gr.Textbox(label="Simulation Results"),
|
| 44 |
-
gr.Image(label="2D Results Visualization"),
|
| 45 |
-
gr.Image(label="3D Results Visualization")
|
| 46 |
],
|
| 47 |
-
title="
|
| 48 |
live=True
|
| 49 |
)
|
| 50 |
|
|
|
|
| 51 |
interface.launch()
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import subprocess
|
| 3 |
from apdl_generator.apdl_plate import generate_plate_apdl
|
| 4 |
+
from apdl_generator.apdl_beam import generate_beam_apdl
|
| 5 |
from simulators.fenics_simulation import run_fenics_simulation
|
| 6 |
+
from simulators.pycalculix_simulation import run_pycalculix_simulation
|
| 7 |
from simulators.ansys_simulation import run_ansys_simulation
|
| 8 |
from visualization import visualize_results
|
| 9 |
|
| 10 |
def simulation_workflow(use_case, simulator, **kwargs):
|
| 11 |
+
# Generate APDL script based on user inputs
|
| 12 |
if use_case == "plate":
|
| 13 |
apdl_path = generate_plate_apdl(kwargs["thickness"], kwargs["length"], kwargs["width"], kwargs["hole_diameter"], kwargs["force"])
|
| 14 |
elif use_case == "beam":
|
|
|
|
| 16 |
else:
|
| 17 |
return "Invalid use case selected.", None, None
|
| 18 |
|
| 19 |
+
# Run the selected simulator
|
| 20 |
+
if simulator == "PyCalculix":
|
| 21 |
+
stress, deformation = run_pycalculix_simulation(use_case, **kwargs)
|
| 22 |
+
elif simulator == "FEniCS":
|
| 23 |
+
stress, deformation = run_fenics_simulation(use_case, **kwargs)
|
| 24 |
elif simulator == "ANSYS":
|
| 25 |
+
stress, deformation = run_ansys_simulation(apdl_path)
|
| 26 |
else:
|
| 27 |
return "Invalid simulator selected.", None, None
|
| 28 |
|
| 29 |
+
# Visualize results (both 2D and 3D)
|
|
|
|
|
|
|
|
|
|
| 30 |
graph_path, three_d_path = visualize_results(simulator, kwargs["length"], kwargs["width"], kwargs["thickness"], stress, deformation)
|
| 31 |
return f"Stress: {stress:.2f} MPa, Deformation: {deformation:.2f} mm", graph_path, three_d_path
|
| 32 |
|
| 33 |
+
# Define Gradio interface
|
| 34 |
interface = gr.Interface(
|
| 35 |
fn=simulation_workflow,
|
| 36 |
inputs=[
|
| 37 |
+
gr.Radio(["plate", "beam"], label="Select Use Case"), # Choose plate or beam simulation
|
| 38 |
+
gr.Dropdown(["PyCalculix", "FEniCS", "ANSYS"], label="Select Simulator"), # Choose simulator
|
| 39 |
+
gr.Slider(10, 50, step=1, label="Thickness (mm)"), # Input: Thickness
|
| 40 |
+
gr.Slider(100, 500, step=10, label="Length (mm)"), # Input: Length
|
| 41 |
+
gr.Slider(50, 200, step=10, label="Width (mm)"), # Input: Width
|
| 42 |
+
gr.Slider(5, 25, step=1, label="Hole Diameter (mm)", optional=True), # Input: Hole Diameter (for plate)
|
| 43 |
+
gr.Slider(1000, 10000, step=500, label="Force (N)", optional=True), # Input: Force (for plate)
|
| 44 |
+
gr.Slider(1000, 20000, step=1000, label="Load (N)", optional=True) # Input: Load (for beam)
|
| 45 |
],
|
| 46 |
outputs=[
|
| 47 |
+
gr.Textbox(label="Simulation Results"), # Output: Simulation text results
|
| 48 |
+
gr.Image(label="2D Results Visualization"), # Output: 2D plot (stress and deformation)
|
| 49 |
+
gr.Image(label="3D Results Visualization") # Output: 3D plot (stress distribution)
|
| 50 |
],
|
| 51 |
+
title="Unified Simulation Tool",
|
| 52 |
live=True
|
| 53 |
)
|
| 54 |
|
| 55 |
+
# Launch Gradio interface
|
| 56 |
interface.launch()
|
| 57 |
+
|