SuriRaja commited on
Commit
1e07532
·
verified ·
1 Parent(s): 3ff8437

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -10
app.py CHANGED
@@ -1,36 +1,51 @@
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)"),
@@ -43,7 +58,7 @@ interface = gr.Interface(
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
 
 
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(tool_type, use_case, simulator, **kwargs):
9
+ """
10
+ Main simulation workflow.
11
+
12
+ Parameters:
13
+ tool_type (str): 'Punch' or 'Die'.
14
+ use_case (str): 'plate' or 'beam'.
15
+ simulator (str): 'FEniCS' or 'ANSYS'.
16
+ kwargs: Input parameters for the simulation.
17
+
18
+ Returns:
19
+ results (str): Text result summarizing stress and deformation.
20
+ graph_path (str): Path to 2D visualization.
21
+ three_d_path (str): Path to 3D visualization.
22
+ """
23
+ # Generate APDL script if needed
24
  if use_case == "plate":
25
  apdl_path = generate_plate_apdl(kwargs["thickness"], kwargs["length"], kwargs["width"], kwargs["hole_diameter"], kwargs["force"])
26
  elif use_case == "beam":
27
  apdl_path = generate_beam_apdl(kwargs["length"], kwargs["width"], kwargs["thickness"], kwargs["load"])
28
  else:
29
+ return "Invalid use case selected.", None, None
30
 
31
+ # Run simulation
32
+ if simulator == "FEniCS":
 
33
  stress, deformation = run_fenics_simulation(use_case, **kwargs)
34
  elif simulator == "ANSYS":
35
  stress, deformation = run_ansys_simulation(apdl_path)
36
  else:
37
+ return "Invalid simulator selected.", None, None
38
 
39
+ # Visualize results
40
  graph_path, three_d_path = visualize_results(simulator, kwargs["length"], kwargs["width"], kwargs["thickness"], stress, deformation)
41
+ return f"{tool_type} Simulation\nStress: {stress:.2f} MPa\nDeformation: {deformation:.2f} mm", graph_path, three_d_path
42
 
43
  interface = gr.Interface(
44
  fn=simulation_workflow,
45
  inputs=[
46
+ gr.Radio(["Punch", "Die"], label="Select Tool Type"),
47
  gr.Radio(["plate", "beam"], label="Select Use Case"),
48
+ gr.Dropdown(["FEniCS", "ANSYS"], label="Select Simulator"),
49
  gr.Slider(10, 50, step=1, label="Thickness (mm)"),
50
  gr.Slider(100, 500, step=10, label="Length (mm)"),
51
  gr.Slider(50, 200, step=10, label="Width (mm)"),
 
58
  gr.Image(label="2D Results Visualization"),
59
  gr.Image(label="3D Results Visualization")
60
  ],
61
+ title="Punch and Die Simulation Tool",
62
  live=True
63
  )
64