SuriRaja commited on
Commit
844bdc9
·
verified ·
1 Parent(s): 1eef590

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -23
app.py CHANGED
@@ -1,30 +1,71 @@
1
- import matplotlib.pyplot as plt
 
 
 
 
2
 
3
- def visualize_results(simulator, length, width, thickness, stress, deformation):
4
  """
5
- Generates 2D visualizations for simulation results.
6
 
7
  Parameters:
8
- simulator (str): Name of the simulator (e.g., 'Python-Based Solver').
9
- length (float): Length of the object.
10
- width (float): Width of the object.
11
- thickness (float): Thickness of the object.
12
- stress (float): Stress value.
13
- deformation (float): Deformation value.
 
 
 
 
 
14
 
15
  Returns:
16
- str: Path to the 2D visualization image.
 
17
  """
18
- # Generate 2D bar chart
19
- fig, ax = plt.subplots(figsize=(6, 4))
20
- ax.bar(["Stress", "Deformation"], [stress, deformation], color=["red", "blue"])
21
- ax.set_title(f"Simulation Results ({simulator})")
22
- ax.set_ylabel("Magnitude")
23
- ax.grid(True, linestyle="--", alpha=0.6)
24
-
25
- # Save the chart
26
- output_path = "results_2d.png"
27
- plt.savefig(output_path)
28
- plt.close(fig)
29
-
30
- return output_path, None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.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
 
11
  Parameters:
12
+ tool_type (str): 'Punch' or 'Die'.
13
+ use_case (str): 'plate' or 'beam'.
14
+ include_hole (bool): Whether to include a hole in the plate simulation.
15
+ include_force (bool): Whether to include force in the simulation.
16
+ include_load (bool): Whether to include load in the simulation.
17
+ thickness (float): Thickness of the material.
18
+ length (float): Length of the material.
19
+ width (float): Width of the material.
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
30
+ load = load if include_load else 0
31
+
32
+ # Generate APDL script dynamically
33
+ if use_case == "plate":
34
+ hole_diameter = hole_diameter if include_hole else 0
35
+ apdl_path = generate_plate_apdl(thickness, length, width, hole_diameter, force)
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,
50
+ inputs=[
51
+ gr.Radio(["Punch", "Die"], label="Select Tool Type"),
52
+ gr.Radio(["plate", "beam"], label="Select Use Case"),
53
+ gr.Checkbox(label="Include Hole for Plate Simulation"), # Checkbox for optional hole
54
+ gr.Checkbox(label="Include Force"), # Checkbox for optional force
55
+ gr.Checkbox(label="Include Load"), # Checkbox for optional load
56
+ gr.Slider(10, 50, step=1, label="Thickness (mm)"),
57
+ gr.Slider(100, 500, step=10, label="Length (mm)"),
58
+ gr.Slider(50, 200, step=10, label="Width (mm)"),
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
+
71
+ interface.launch()