import matplotlib.pyplot as plt
import numpy as np
from pyNastran.op2.op2 import OP2
from pyNastran.bdf.bdf import BDF
# Load OP2 and BDF files
op2 = OP2('path/to/op2/file.op2')
bdf = BDF()
bdf.read_bdf('path/to/bdf/file.bdf')
# Get the envelope deflection results
disp = op2.get_displacement_index() # Get the index for the displacement result
envelope = op2.get_envelope(disp) # Get the envelope results
nodes = envelope.node_grid[:, 0]
dofs = envelope.node_grid[:, 1]
displacements = envelope.data[:, :3]
# Get the nodal coordinates
x, y, z = [], [], []
for nid, node in bdf.nodes.items():
x.append(
node.xyz[0])
y.append(
node.xyz[1])
z.append(
node.xyz[2])
# Plot the deflection
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlabel('X axis')
ax.set_ylabel('Y axis')
ax.set_zlabel('Z axis')
ax.scatter(x, y, z, c='b', marker='.')
ax.quiver(x, y, z, displacements[:, 0], displacements[:, 1], displacements[:, 2], length=1.0, color='r')
plt.title('Envelope deflection plot')
plt.savefig('path/to/output/file.jpg')
plt.show()
this code is not working, can anyone help me with this if i am making any mistake.