Spaces:
Build error
Build error
Create visualization/visualization.py
Browse files
visualization/visualization.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|