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

Update visualization.py

Browse files
Files changed (1) hide show
  1. 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 and 3D visualizations for simulation results.
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
- tuple: Paths to the 2D and 3D visualization images.
22
  """
23
- # Generate 2D visualization
24
- fig, ax = plt.subplots()
25
  ax.bar(["Stress", "Deformation"], [stress, deformation], color=["red", "blue"])
26
- ax.set_title(f"Results ({simulator})")
27
- plt.savefig("results_2d.png")
28
- plt.close(fig)
29
-
30
- # Generate 3D visualization
31
- # Create a simple rectangular mesh
32
- mesh = pv.Box(bounds=(0, length, 0, width, 0, thickness))
33
 
34
- # Assign a scalar array to match the number of cells
35
- cell_data = np.full(mesh.n_cells, stress) # Assign stress value to each cell
36
- mesh.cell_data["Stress"] = cell_data
 
37
 
38
- # Plot 3D visualization
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