File size: 681 Bytes
1cf39f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import pyvista as pv
import matplotlib.pyplot as plt

def visualize_results(simulator, length, width, thickness, stress, deformation):
    # 2D Bar Plot
    fig, ax = plt.subplots()
    ax.bar(["Stress", "Deformation"], [stress, deformation], color=["red", "blue"])
    ax.set_title(f"Results ({simulator})")
    plt.savefig("results_2d.png")
    plt.close(fig)
    
    # 3D Visualization
    mesh = pv.Box(bounds=(0, length, 0, width, 0, thickness))
    mesh["Stress"] = stress
    plotter = pv.Plotter(off_screen=True)
    plotter.add_mesh(mesh, scalars="Stress", cmap="coolwarm")
    plotter.show(screenshot="results_3d.png")
    
    return "results_2d.png", "results_3d.png"