SuriRaja commited on
Commit
739726e
·
verified ·
1 Parent(s): 1093a9f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -33
app.py CHANGED
@@ -2,9 +2,9 @@ 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.python_simulation import run_python_simulation
5
- from visualization import visualize_results, visualize_end_product
6
 
7
- def simulation_workflow(tool_type, use_case, include_hole, include_force, include_load, thickness, length, width, hole_diameter, force, load, elastic_modulus):
8
  """
9
  Main simulation workflow.
10
 
@@ -20,13 +20,10 @@ def simulation_workflow(tool_type, use_case, include_hole, include_force, includ
20
  hole_diameter (float): Diameter of the hole (optional).
21
  force (float): Applied force (optional).
22
  load (float): Applied load (optional).
23
- elastic_modulus (float): Elastic modulus of the material (Pa).
24
 
25
  Returns:
26
  results (str): Text result summarizing stress and deformation.
27
  graph_path (str): Path to the 2D visualization.
28
- product_path (str): Path to the end-product visualization.
29
- apdl_program (str): The generated APDL program.
30
  """
31
  # Handle optional parameters
32
  force = force if include_force else 0
@@ -39,33 +36,14 @@ def simulation_workflow(tool_type, use_case, include_hole, include_force, includ
39
  elif use_case == "beam":
40
  apdl_path = generate_beam_apdl(length, width, thickness, load)
41
  else:
42
- return "Invalid use case selected.", None, None, None
43
-
44
- # Read the generated APDL program
45
- with open(apdl_path, "r") as file:
46
- apdl_program = file.read()
47
 
48
  # Run simulation using Python-based solver
49
- stress, deformation = run_python_simulation(apdl_path, use_case, thickness, length, width, force, load, elastic_modulus)
50
-
51
- # Explanation for negligible deformation
52
- if deformation < 1e-6:
53
- deformation_note = "\nNote: Deformation is negligible due to the high rigidity of the material."
54
- else:
55
- deformation_note = ""
56
 
57
- # Generate 2D simulation visualization
58
  graph_path, _ = visualize_results("Python-Based Solver", length, width, thickness, stress, deformation)
59
-
60
- # Generate end-product visualization
61
- product_path = visualize_end_product(use_case, length, width, thickness, deformation)
62
-
63
- return (
64
- f"{tool_type} Simulation\nStress: {stress:.2f} MPa\nDeformation: {deformation:.6f} mm{deformation_note}",
65
- graph_path,
66
- product_path,
67
- apdl_program
68
- )
69
 
70
  interface = gr.Interface(
71
  fn=simulation_workflow,
@@ -81,15 +59,12 @@ interface = gr.Interface(
81
  gr.Slider(5, 25, step=1, label="Hole Diameter (mm)"), # Controlled by "Include Hole"
82
  gr.Slider(1000, 10000, step=500, label="Force (N)"), # Controlled by "Include Force"
83
  gr.Slider(1000, 20000, step=1000, label="Load (N)"), # Controlled by "Include Load"
84
- gr.Slider(5e10, 3e11, step=1e10, label="Elastic Modulus (Pa)") # Slider for Elastic Modulus
85
  ],
86
  outputs=[
87
  gr.Textbox(label="Simulation Results"),
88
- gr.Image(label="2D Simulation Visualization"),
89
- gr.Image(label="End Product Visualization"),
90
- gr.Code(language="plaintext", label="Generated APDL Program") # Display APDL program
91
  ],
92
- title="Punch and Die Simulation Tool with End Product Visualization and APDL",
93
  live=True
94
  )
95
 
 
2
  from apdl_generator.apdl_plate import generate_plate_apdl
3
  from apdl_generator.apdl_beam import generate_beam_apdl
4
  from simulators.python_simulation import run_python_simulation
5
+ from visualization import visualize_results
6
 
7
+ def simulation_workflow(tool_type, use_case, include_hole, include_force, include_load, thickness, length, width, hole_diameter, force, load):
8
  """
9
  Main simulation workflow.
10
 
 
20
  hole_diameter (float): Diameter of the hole (optional).
21
  force (float): Applied force (optional).
22
  load (float): Applied load (optional).
 
23
 
24
  Returns:
25
  results (str): Text result summarizing stress and deformation.
26
  graph_path (str): Path to the 2D visualization.
 
 
27
  """
28
  # Handle optional parameters
29
  force = force if include_force else 0
 
36
  elif use_case == "beam":
37
  apdl_path = generate_beam_apdl(length, width, thickness, load)
38
  else:
39
+ return "Invalid use case selected.", None
 
 
 
 
40
 
41
  # Run simulation using Python-based solver
42
+ stress, deformation = run_python_simulation(apdl_path, use_case, thickness=thickness, length=length, width=width, force=force, load=load)
 
 
 
 
 
 
43
 
44
+ # Generate 2D visualization
45
  graph_path, _ = visualize_results("Python-Based Solver", length, width, thickness, stress, deformation)
46
+ return f"{tool_type} Simulation\nStress: {stress:.2f} MPa\nDeformation: {deformation:.2f} mm", graph_path
 
 
 
 
 
 
 
 
 
47
 
48
  interface = gr.Interface(
49
  fn=simulation_workflow,
 
59
  gr.Slider(5, 25, step=1, label="Hole Diameter (mm)"), # Controlled by "Include Hole"
60
  gr.Slider(1000, 10000, step=500, label="Force (N)"), # Controlled by "Include Force"
61
  gr.Slider(1000, 20000, step=1000, label="Load (N)"), # Controlled by "Include Load"
 
62
  ],
63
  outputs=[
64
  gr.Textbox(label="Simulation Results"),
65
+ gr.Image(label="2D Results Visualization")
 
 
66
  ],
67
+ title="Punch and Die Simulation Tool (Python-Based)",
68
  live=True
69
  )
70