Spaces:
Build error
Build error
Update visualization/visualization.py
Browse files- visualization/visualization.py +12 -42
visualization/visualization.py
CHANGED
|
@@ -1,45 +1,15 @@
|
|
| 1 |
-
|
| 2 |
import matplotlib.pyplot as plt
|
| 3 |
-
from mpl_toolkits.mplot3d import Axes3D
|
| 4 |
|
| 5 |
-
def visualize_results(
|
| 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.
|
| 23 |
-
ax.set_title("
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 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"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|