karthikmn commited on
Commit
4f6ea23
·
verified ·
1 Parent(s): 42a864f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -30
app.py CHANGED
@@ -1,52 +1,37 @@
1
- # main.py
2
  import gradio as gr
3
  from apdl_generator.apdl_plate import generate_plate_apdl
4
  from apdl_generator.apdl_beam import generate_beam_apdl
5
- from simulators.python_simulation import run_python_simulation
 
6
  from visualization import visualize_results
7
 
8
- def simulation_workflow(tool_type, use_case, include_hole, **kwargs):
9
- """
10
- Main simulation workflow.
11
-
12
- Parameters:
13
- tool_type (str): 'Punch' or 'Die'.
14
- use_case (str): 'plate' or 'beam'.
15
- include_hole (bool): Whether to include a hole in the plate simulation.
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 dynamically
24
  if use_case == "plate":
25
- hole_diameter = kwargs["hole_diameter"] if include_hole else 0
26
- apdl_path = generate_plate_apdl(kwargs["thickness"], kwargs["length"], kwargs["width"], hole_diameter, kwargs["force"])
27
  elif use_case == "beam":
28
  apdl_path = generate_beam_apdl(kwargs["length"], kwargs["width"], kwargs["thickness"], kwargs["load"])
29
  else:
30
  return "Invalid use case selected.", None, None
31
 
32
- # Run simulation using Python-based solver
33
- stress, deformation = run_python_simulation(apdl_path, use_case, **kwargs)
 
 
 
 
34
 
35
- # Visualize results
36
- graph_path, three_d_path = visualize_results("Python-Based Solver", kwargs["length"], kwargs["width"], kwargs["thickness"], stress, deformation)
37
- return f"{tool_type} Simulation\nStress: {stress:.2f} MPa\nDeformation: {deformation:.2f} mm", graph_path, three_d_path
38
 
39
- # Gradio Interface
40
  interface = gr.Interface(
41
  fn=simulation_workflow,
42
  inputs=[
43
- gr.Radio(["Punch", "Die"], label="Select Tool Type"),
44
  gr.Radio(["plate", "beam"], label="Select Use Case"),
45
- gr.Checkbox(label="Include Hole for Plate Simulation"), # Checkbox for optional hole
46
  gr.Slider(10, 50, step=1, label="Thickness (mm)"),
47
  gr.Slider(100, 500, step=10, label="Length (mm)"),
48
  gr.Slider(50, 200, step=10, label="Width (mm)"),
49
- gr.Slider(5, 25, step=1, label="Hole Diameter (mm)"), # Always active but controlled by checkbox
50
  gr.Slider(1000, 10000, step=500, label="Force (N)", optional=True),
51
  gr.Slider(1000, 20000, step=1000, label="Load (N)", optional=True)
52
  ],
@@ -55,7 +40,7 @@ interface = gr.Interface(
55
  gr.Image(label="2D Results Visualization"),
56
  gr.Image(label="3D Results Visualization")
57
  ],
58
- title="Punch and Die Simulation Tool (Python-Based)",
59
  live=True
60
  )
61
 
 
 
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":
12
  apdl_path = generate_beam_apdl(kwargs["length"], kwargs["width"], kwargs["thickness"], kwargs["load"])
13
  else:
14
  return "Invalid use case selected.", None, None
15
 
16
+ if simulator == "FEniCS":
17
+ stress, deformation = run_fenics_simulation(use_case, **kwargs)
18
+ elif simulator == "ANSYS":
19
+ stress, deformation = run_ansys_simulation(apdl_path)
20
+ else:
21
+ return "Invalid simulator selected.", None, None
22
 
23
+ graph_path, three_d_path = visualize_results(simulator, kwargs["length"], kwargs["width"], kwargs["thickness"], stress, deformation)
24
+ return f"Stress: {stress:.2f} MPa, Deformation: {deformation:.2f} mm", graph_path, three_d_path
 
25
 
 
26
  interface = gr.Interface(
27
  fn=simulation_workflow,
28
  inputs=[
 
29
  gr.Radio(["plate", "beam"], label="Select Use Case"),
30
+ gr.Dropdown(["FEniCS", "ANSYS"], label="Select Simulator"),
31
  gr.Slider(10, 50, step=1, label="Thickness (mm)"),
32
  gr.Slider(100, 500, step=10, label="Length (mm)"),
33
  gr.Slider(50, 200, step=10, label="Width (mm)"),
34
+ gr.Slider(5, 25, step=1, label="Hole Diameter (mm)", optional=True),
35
  gr.Slider(1000, 10000, step=500, label="Force (N)", optional=True),
36
  gr.Slider(1000, 20000, step=1000, label="Load (N)", optional=True)
37
  ],
 
40
  gr.Image(label="2D Results Visualization"),
41
  gr.Image(label="3D Results Visualization")
42
  ],
43
+ title="Simulation Tool Without PyCalculix",
44
  live=True
45
  )
46