SuriRaja commited on
Commit
2a7487a
·
verified ·
1 Parent(s): 927edb1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.pycalculix_simulation import run_pycalculix_simulation
5
+ from simulators.fenics_simulation import run_fenics_simulation
6
+ from simulators.ansys_simulation import run_ansys_simulation
7
+ from visualization import visualize_results
8
+
9
+ def simulation_workflow(use_case, simulator, **kwargs):
10
+ if use_case == "plate":
11
+ apdl_path = generate_plate_apdl(kwargs["thickness"], kwargs["length"], kwargs["width"], kwargs["hole_diameter"], kwargs["force"])
12
+ elif use_case == "beam":
13
+ apdl_path = generate_beam_apdl(kwargs["length"], kwargs["width"], kwargs["thickness"], kwargs["load"])
14
+ else:
15
+ return "Invalid use case selected.", None
16
+
17
+ if simulator == "PyCalculix":
18
+ stress, deformation = run_pycalculix_simulation(use_case, **kwargs)
19
+ elif simulator == "FEniCS":
20
+ stress, deformation = run_fenics_simulation(use_case, **kwargs)
21
+ elif simulator == "ANSYS":
22
+ stress, deformation = run_ansys_simulation(apdl_path)
23
+ else:
24
+ return "Invalid simulator selected.", None
25
+
26
+ graph_path, three_d_path = visualize_results(simulator, kwargs["length"], kwargs["width"], kwargs["thickness"], stress, deformation)
27
+ return f"Stress: {stress:.2f} MPa, Deformation: {deformation:.2f} mm", graph_path, three_d_path
28
+
29
+ interface = gr.Interface(
30
+ fn=simulation_workflow,
31
+ inputs=[
32
+ gr.Radio(["plate", "beam"], label="Select Use Case"),
33
+ gr.Dropdown(["PyCalculix", "FEniCS", "ANSYS"], label="Select Simulator"),
34
+ gr.Slider(10, 50, step=1, label="Thickness (mm)"),
35
+ gr.Slider(100, 500, step=10, label="Length (mm)"),
36
+ gr.Slider(50, 200, step=10, label="Width (mm)"),
37
+ gr.Slider(5, 25, step=1, label="Hole Diameter (mm)", optional=True),
38
+ gr.Slider(1000, 10000, step=500, label="Force (N)", optional=True),
39
+ gr.Slider(1000, 20000, step=1000, label="Load (N)", optional=True)
40
+ ],
41
+ outputs=[
42
+ gr.Textbox(label="Simulation Results"),
43
+ gr.Image(label="2D Results Visualization"),
44
+ gr.Image(label="3D Results Visualization")
45
+ ],
46
+ title="3D Unified Simulation Tool",
47
+ live=True
48
+ )
49
+
50
+ interface.launch()