envelope deflection plot using PyNASTRAN

149 views
Skip to first unread message

ashwin prabhu

unread,
Mar 9, 2023, 7:43:13 AM3/9/23
to pyNastran Discuss
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.

Steven Doyle

unread,
Mar 9, 2023, 8:55:11 AM3/9/23
to pynastra...@googlegroups.com
What is op2.get_displacement_index() and op2.get_envelope(disp)?  Those don’t exist.

I’d suggest reading through the examples.
Grab the .data array and call max(axis=???) on it.

--
You received this message because you are subscribed to the Google Groups "pyNastran Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pynastran-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pynastran-discuss/f57862e8-e3b0-4e96-adb9-8432c62d0439n%40googlegroups.com.

Alejandro Stewart

unread,
Mar 9, 2023, 9:36:38 AM3/9/23
to pyNastran Discuss
Am I wrong guessing that this was written by chatGPT?

ashwin prabhu

unread,
Mar 9, 2023, 9:52:41 AM3/9/23
to pyNastran Discuss
you are absolutely right it was generated by CHatgpt.
I know that the code is not right as i looked through the methods.

i am looking into the below
I’d suggest reading through the examples.
Grab the .data array and call max(axis=???) on it.

But is it possible to generate deflection plot and plot out the output?

Alejandro Stewart

unread,
Mar 9, 2023, 10:32:57 AM3/9/23
to pyNastran Discuss
Yes it is, I suggest you get familiar woth the OP2 object and its contents by inspeccting the variables in a debugger on your favourite IDE. Once you understand the way data is stored, you´ll be able to do it and much more.

Steven Doyle

unread,
Mar 9, 2023, 11:14:36 AM3/9/23
to pynastra...@googlegroups.com
Yeah, ChatGPT kinda bombs pynastran.  It gets some things right, but entire modules/classes don’t exist.  It claims there is a full Nastran solver inside it.  It even got the license wrong (something that is  standard to every software project).

Pynastran doesn’t do plotting outside of a few areas (flutter, composites, aero panels).  In general, any matplotlib plots need to be generated by you.

That said, there is a gui that you can use.  It’s a lot better than matplotlib, especially for large models.  There are just no axes.  You can do fancy things like represent deflections using deformation or vectors or both while setting the fringe/colors to the stress.

--
You received this message because you are subscribed to the Google Groups "pyNastran Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pynastran-disc...@googlegroups.com.

ashwin prabhu

unread,
Mar 9, 2023, 9:47:14 PM3/9/23
to pynastra...@googlegroups.com
Appreciate the response guys, will dig into it and get back to you.

You received this message because you are subscribed to a topic in the Google Groups "pyNastran Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pynastran-discuss/xmGxOWQnRFk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pynastran-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pynastran-discuss/CADJnEGFPbKooA2QvbiMkEeENOyxO4TdDqUDpBOizUtsXNx%3D5qw%40mail.gmail.com.

ashwin prabhu

unread,
Mar 18, 2023, 2:44:30 AM3/18/23
to pyNastran Discuss
Hi Guys,

I was able to get the deflection data for all load cases based on node ID's using op2.get_result('displacements'). The went through the object and then was able to get values for Fwd, Aft, Left, Right, Down, and Up.

Have one doubt now about the values that i have i need to create a deflection plot as attached is it possible?
Please do let me know if it's even feasible.
Test.jpg

Steven Doyle

unread,
Mar 18, 2023, 11:04:04 AM3/18/23
to pynastra...@googlegroups.com
Ash win,

Yes.  I don’t know what result that is b/c the color scale and values are confusing me.  It looks like a fringe plot and not a displacement plot or marker/quiver/arrow plot.  It’s also not a displacement magnitude on the legend.  Let me know if that’s correct.

PyNastran has a GUI and you can use that.  You might want to export the displacements (right click on your result in the tree) and load it in as a fringe, but it’s hard to say without understanding what you have.

Beyond that, the picture looks like it might be Femap.  Is this just a task Femap is better at?

ashwin prabhu

unread,
Mar 18, 2023, 11:30:05 AM3/18/23
to pyNastran Discuss
Hi Steve,
Appreciate you responding to my message.

It is a fringe showing the front of the galley i have blurred a bit of image as its restricted.
It basically provides the FEM plots for envelope deflection in each direction.
The plot is done using Patran.

I did use the GUI and was not able to run the same, i am checking with my IT team if there is something that is blocking from the tool being opened.
I am trying to use the command line option of the GUI, any pointers you can provide to generate the same using command line, do let me know.

Steven Doyle

unread,
Mar 18, 2023, 12:44:57 PM3/18/23
to pynastra...@googlegroups.com
Ashwin,

There are two parts to this.  Calculating your fringe and plotting the fringe in the gui.

For the first part, I don’t know what you mean by envelope.  It’s not a displacement magnitude, but I think now that you want a fringe.  You must provide the GUI with results for each node or a subset of nodes.  Can you provide a non-proprietary example like a solid beam that demonstrates your goal?  I don’t understand your math.

For the plotting part, I assume you’re using the exe.  Your security settings may be stricter, but you can just type pynastranGUI on the command line to load it.  You’ll probably also need to install some extra dependencies.


Reply all
Reply to author
Forward
0 new messages