simulationapdl / visualization.py
karthikmn's picture
Create visualization.py
5dd42d2 verified
raw
history blame contribute delete
681 Bytes
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"