karthikmn commited on
Commit
59b9a97
·
verified ·
1 Parent(s): 064c922

Update visualization/visualization.py

Browse files
Files changed (1) hide show
  1. visualization/visualization.py +12 -42
visualization/visualization.py CHANGED
@@ -1,45 +1,15 @@
1
- # visualization/visualization.py
2
  import matplotlib.pyplot as plt
3
- from mpl_toolkits.mplot3d import Axes3D
4
 
5
- def visualize_results(solver_name, length, width, thickness, stress, deformation):
6
- """
7
- Visualize the simulation results in both 2D and 3D.
8
-
9
- Parameters:
10
- solver_name (str): Name of the solver.
11
- length (float): Length of the plate/beam.
12
- width (float): Width of the plate/beam.
13
- thickness (float): Thickness of the plate/beam.
14
- stress (float): Stress value from the simulation.
15
- deformation (float): Deformation value from the simulation.
16
-
17
- Returns:
18
- tuple: Paths to the 2D and 3D visualization images.
19
- """
20
- # 2D visualization (stress distribution over the length)
21
  fig, ax = plt.subplots()
22
- ax.plot([0, length], [0, stress], label="Stress Distribution")
23
- ax.set_title("2D Stress Distribution")
24
- ax.set_xlabel("Length (mm)")
25
- ax.set_ylabel("Stress (MPa)")
26
- ax.legend()
27
-
28
- graph_path = "/tmp/2d_stress_distribution.png"
29
- plt.savefig(graph_path)
30
- plt.close()
31
-
32
- # 3D visualization (stress and deformation)
33
- fig = plt.figure()
34
- ax = fig.add_subplot(111, projection='3d')
35
- ax.scatter(length, width, stress, label="Stress Distribution")
36
- ax.set_title("3D Stress Visualization")
37
- ax.set_xlabel("Length (mm)")
38
- ax.set_ylabel("Width (mm)")
39
- ax.set_zlabel("Stress (MPa)")
40
-
41
- three_d_path = "/tmp/3d_stress_visualization.png"
42
- plt.savefig(three_d_path)
43
- plt.close()
44
-
45
- return graph_path, three_d_path
 
1
+ import pyvista as pv
2
  import matplotlib.pyplot as plt
 
3
 
4
+ def visualize_results(simulator, length, width, thickness, stress, deformation):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  fig, ax = plt.subplots()
6
+ ax.bar(["Stress", "Deformation"], [stress, deformation], color=["red", "blue"])
7
+ ax.set_title(f"Results ({simulator})")
8
+ plt.savefig("results_2d.png")
9
+ plt.close(fig)
10
+
11
+ mesh = pv.Box(bounds=(0, length, 0, width, 0, thickness))
12
+ plotter = pv.Plotter(off_screen=True)
13
+ plotter.add_mesh(mesh, color="white", show_edges=True)
14
+ plotter.screenshot("results_3d.png")
15
+ return "results_2d.png", "results_3d.png"