Spaces:
Sleeping
Sleeping
Update visualization.py
Browse files- visualization.py +12 -25
visualization.py
CHANGED
@@ -1,13 +1,8 @@
|
|
1 |
-
import pyvista as pv
|
2 |
-
import numpy as np
|
3 |
import matplotlib.pyplot as plt
|
4 |
|
5 |
-
# Start virtual framebuffer for headless environments
|
6 |
-
pv.start_xvfb()
|
7 |
-
|
8 |
def visualize_results(simulator, length, width, thickness, stress, deformation):
|
9 |
"""
|
10 |
-
Generates 2D
|
11 |
|
12 |
Parameters:
|
13 |
simulator (str): Name of the simulator (e.g., 'Python-Based Solver').
|
@@ -18,26 +13,18 @@ def visualize_results(simulator, length, width, thickness, stress, deformation):
|
|
18 |
deformation (float): Deformation value.
|
19 |
|
20 |
Returns:
|
21 |
-
|
22 |
"""
|
23 |
-
# Generate 2D
|
24 |
-
fig, ax = plt.subplots()
|
25 |
ax.bar(["Stress", "Deformation"], [stress, deformation], color=["red", "blue"])
|
26 |
-
ax.set_title(f"Results ({simulator})")
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
# Generate 3D visualization
|
31 |
-
# Create a simple rectangular mesh
|
32 |
-
mesh = pv.Box(bounds=(0, length, 0, width, 0, thickness))
|
33 |
|
34 |
-
#
|
35 |
-
|
36 |
-
|
|
|
37 |
|
38 |
-
|
39 |
-
plotter = pv.Plotter(off_screen=True)
|
40 |
-
plotter.add_mesh(mesh, scalars="Stress", cmap="coolwarm")
|
41 |
-
plotter.show(screenshot="results_3d.png")
|
42 |
-
|
43 |
-
return "results_2d.png", "results_3d.png"
|
|
|
|
|
|
|
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').
|
|
|
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
|
|
|
|
|
|
|
|
|
|