Controlling contents of OP2 file

113 views
Skip to first unread message

Mike Demchenko

unread,
Mar 8, 2024, 3:48:36 PM3/8/24
to pyNastran Discuss
Hello!
I'd like to ask a question about getting an OP2 file and saving it with a subset of original data.

First of all, I'm using Simcenter Femap.
I want to create a Python script to write an OP2 file with an explicit set of output vectors, output sets (results, analysis cases), and elements.
I looked through pynastran and didn't find the level of control I needed (I hope I didn't miss anything).
I'm thinking of abandoning the idea, but maybe I could write my own methods on top of pynastran to get what I need?
I'm neither a Python expert nor a Nastran expert, so I'm not sure I can handle such thing at the moment.
If it is possible, could you please outline the stuff I need to do to get this fine control over the contents of OP2?

Steven Doyle

unread,
Mar 8, 2024, 4:30:12 PM3/8/24
to pynastra...@googlegroups.com
Hi MIke,

The best way to do that would be to just not load it in in the first place.  If you did, you can use the includes/skips options in the write_op2 method.  For finer control, you'd just remove them from the results objects.

The read_op2 function has a subcases option:

>>> from pyNastran.op2.op2 import read_op2, OP2
>>> model = read_op2(op2_filename, subcases=[1])

if you're using the class approach, which has slightly more control:
>>> model = OP2()
>>> model.set_subcases([1])
>>> model.read_op2(op2_filename)
I
Then you can just call the write_op2 method.
>>> model.write_op2(op2_filename_new)

--
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/616cc961-82f3-4d18-afb2-5b5618b9e859n%40googlegroups.com.

Mike Demchenko

unread,
Mar 21, 2024, 2:06:08 AM3/21/24
to pyNastran Discuss

Hello, Steve!

Thank you for taking your time to reply. Apologies for disappearing; I was dealing with a heavy load at work.
So I think I didn't quite understand if the thing I want is possible. Let me rephrase it.
 
Suppose we have a 10k element model with 10 analysis results in it.
I want to pass 3 arrays to pynastran:
 
1. An array of elements.
     Let's say it will be a list of elements with IDs from 1000 to 5000.
2. An array of output vectors.
    Let's say our ID list contains BEAM and PLATE elements. So I would want to have output vectors for Beam Axial Force and Plate Mid VonMises Stress only. So we got a list of their IDs: 3022 and 8033 in Femap.
3. Array of output sets (results)
    This is the easiest part; looks like no problems here to have any number of cases I want.
 
So, is all of this possible?
 
If it isn't, I had another idea recently about editing hdf5 using PyTables, then converting it to a schema that pynastran is able to read, and then just saving it as .op2.
The problem is that I have no idea what's special about MSC Nastran hdf5 schema.

Could you please tell me how I would need to edit MSC hdf5 output to be able to open it with pynastran? What is special about MSC hdf5 schema?


суббота, 9 марта 2024 г. в 00:30:12 UTC+3, Steven Doyle:

Steven Doyle

unread,
Mar 21, 2024, 2:28:08 AM3/21/24
to pynastra...@googlegroups.com
Mike,

MSC HDF5 is not supported yet.  You have to use the op2 to use results in pynastran.

Pynastran doesn’t offer methods to get subsets of say plate stress of the op2 result objects yet.  The op2 stores stresses by element type, so you have cquad4_stress or whatever.  I recommend going through the op2 examples in the documentation.

You can definitely slice the data though based on your requirements.  I guess I don’t understand why you just wouldn’t write the whole thing in that case.  What is your end goal and why do you want to take subsets of the data?

Steve 

Mike Demchenko

unread,
Mar 21, 2024, 9:20:06 AM3/21/24
to pyNastran Discuss

Um, I may not have hit reply. Sorry if it's doubled, because it's not yet approved or whatever.

The goal is to let user get the results relevant to them from a huge full-fledged analysis with thousands of cases. Also, each case contains output vectors (stresses, forces, strains etc) which are not used 95% of the time. Deleting these vectors manually, or even through API is inefficient.

I'd like to try it because working with such datasets in Femap is painfully slow, mainly because it's operating on a single thread, I think.
So I want to be able to define the slice of data precisely. I want to be able to save op2 file containing nothing more except the slice I defined.
четверг, 21 марта 2024 г. в 09:28:08 UTC+3, Steven Doyle:

Steven Doyle

unread,
Mar 21, 2024, 11:17:59 AM3/21/24
to pynastra...@googlegroups.com
How would the user get the results?  Like get the max for all elements?  Save all the load cases where a single element is critical?

You cannot use the op2 to down select to specific results like Plate Mid von Mises Stress.  The op2 is just a faster f06, so you get no results or all the quad results (oxx, oyy, txy, max/min principal, angle, and von Mises.  You also have to handle trias separately.

That said, reading a 2 GB op2 takes about 4 seconds and writing most results is fast these days.  If you’re writing vectorized numpy, it should be fast.  I assume the FEMAP issue is not because it’s single threaded (pyNastran is too), but rather that you’re building the result on the fly and rendering the result.  Rendering results is slow.

Mike Demchenko

unread,
Mar 25, 2024, 9:45:11 PM3/25/24
to pyNastran Discuss

I'm planning to write a GUI for the user to choose the section of the model, the array of vectors, and the results.

We're dealing with  a single op2 file closing in on 200 Gb containing several thousand cases. Attaching it takes 40-50 minutes. Everything about dealing with this file is painful. I cannot change the format of the data. You can't split it easily, it probably will be a nightmare to manage. The more output sets (results, cases) are there in your model and the larger the single case size is, the slower Femap gets. It gets, like, really, really slow. To the point where you can't even do anything. I'm fairly confident it's due to Femap operating on a single thread. When my hands were somewhat untied, I did everything I described manually for myself through Femap GUI. During result attaching process, I selected the group of elements and output vectors I wanted. So for my particular problems, I was down to 300-500kb size of a result for 1 case from 70-80 mb (I usually split them for myself to have them properly named). It is a night and day difference.
This is what I would like to try and recreate.

четверг, 21 марта 2024 г. в 18:17:59 UTC+3, Steven Doyle:

Mike Demchenko

unread,
Mar 25, 2024, 9:45:17 PM3/25/24
to pyNastran Discuss

The goal is to let user get the results relevant to them from a huge full-fledged analysis with thousands of cases. Also, each case contains output vectors (stresses, forces, strains etc) which are not used 95% of the time. Deleting these vectors manually, or even through API is inefficient.

I'd like to try it because working with such datasets in Femap is painfully slow, mainly because it's operating on a single thread, I think. 

So I want to be able to define the slice of data precisely. I want to be able to save op2 file containing nothing more except the slice I defined.

четверг, 21 марта 2024 г. в 09:28:08 UTC+3, Steven Doyle:
Mike,

Steven Doyle

unread,
Mar 25, 2024, 9:57:57 PM3/25/24
to pynastra...@googlegroups.com
Yeah, I would certainly consider splitting that massive file up if you can.  At least back in the day, I ran into issues loading in files of more than ~500 cases.

It really depends on how you plan to reduce that data.  Let's say some group of elements only have isotropic stress, so you find the 10 cases out of 3000 that you care about and write that.  It really depends on how complicated your logic is.  You just need to make sure you're following the rules of the op2.  You're not going to be able to output only von Mises using an op2.  That's just not how the file works.  Give it a shot and if you have questions, ask.

You can also try spawning off multiple python instances and loading a subset of results/subcases with each thread.  I'm not sure where that sweet spot is, but batch processing is certainly helpful for your RAM usage.

Mike Demchenko

unread,
Apr 2, 2024, 8:30:27 PM4/2/24
to pyNastran Discuss

Hello, Steve!
In the past few days, I have outlined 4 main approaches I could try to do the thing. Several combinations of Femap API, pynastran, PyTables, .op2 and hdf5 basically.
I would say the easiest one is:

1. Read .op2 using pynastran
2. Create the subset of data in memory using the requested arrays, compute additional vectors if needed. Just slice / filter dataframes.
3. Using Femap API create empty results and fill them with data. Femap API provides a decently convenient way to define the data vector by vector and then write it in one go.

I started implementing it and encountered the part where I can't access vector ID = 8033 (Femap ID) Midsurface Plate VonMises stress. It's not present in op2 by default, you have to flip the option "Compute Averaged Mid Stress/Strain" in Femap preferences for it to appear in op2.

So, if I do this to access cquad4 data:

```
results = read_op2(
    op2_filename=RESULTS_PATH,
    encoding="windows-1251",
    build_dataframe=True,
    combine=False,
    debug=False,
    )

loadcase_1 = (1, 1, 1, 0, 0, "", "")
loadcase_2 = (2, 1, 1, 0, 0, "", "")
loadcase_3 = (3, 1, 1, 0, 0, "", "")

cquad4_stress = results.op2_results.stress.cquad4_stress
cquad4_stress_case_1 = cquad4_stress[loadcase_1].data_frame
cquad4_stress_case_2 = cquad4_stress[loadcase_2].data_frame
cquad4_stress_case_3= cquad4_stress[loadcase_3].data_frame
```

I only get default vectors.

Obviously, I can easily compute it myself using Plate Forces and it won't slow down the process, but I would prefer not to do this.
So, can I use pynastran to access this vector? Maybe there is some special table where these kinds of vectors are put?

Thanks in advance!


вторник, 26 марта 2024 г. в 04:57:57 UTC+3, steve:

Steven Doyle

unread,
Apr 2, 2024, 8:48:09 PM4/2/24
to pynastra...@googlegroups.com
The outputs of the op2 are the same as the f06.  A few things are removed (e.g., solid element principal vectors), but in general it's the same.

You can output midplane strains using STRCURV (vs. using FIBER).  You pick one, just like you pick Max Shear vs. von Mises.
image.png
I'm pretty sure that stress doesn't have that option, so you have to do that manually.  PyNastran doesn't support calculating extra terms.  That is planned for the gui along with nodal averaging (outside of the gui), but it's not there yet.  Either way, it's not going to be faster than doing it manually.

Since you're chasing extreme performance, I would try avoiding using dataframes.  I don't know how long it takes to build a dataframe, but it's longer than not doing it.

Reply all
Reply to author
Forward
0 new messages