SteveDoyle2 / pyNastran

A Python-based interface tool for Nastran's file formats
Other
384 stars 147 forks source link

bdf_2_vtk or op2_2_vtk #772

Closed karma0704 closed 5 months ago

karma0704 commented 5 months ago

Hello, gentleman, can you realize the function of converting the geometric shape and topology of the bdf file and the displacement, stress, and strain extracted from the op2 file into the corresponding data blocks in the VTK text file? If you have implemented these functions, can you provide some test examples?

SteveDoyle2 commented 5 months ago

There is no bdf_2_vtk or op2_2_vtk function. I believe the function you’re after is nastran_to_vtk. The usage is in the docstring and there are examples of it in the code.

You can also just load up the gui and export.

On Tue, Mar 19, 2024 at 11:35 PM karma0704 @.***> wrote:

Hello, gentleman, can you realize the function of converting the geometric shape and topology of the bdf file and the displacement, stress, and strain extracted from the op2 file into the corresponding data blocks in the VTK text file? If you have implemented these functions, can you provide some test examples?

— Reply to this email directly, view it on GitHub https://github.com/SteveDoyle2/pyNastran/issues/772, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAICUWPMCVUSGIWSMIH76RTYZEU4RAVCNFSM6AAAAABE637VH2VHI2DSMVQWIX3LMV43ASLTON2WKOZSGE4TMNZWGIYDIOA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

SteveDoyle2 commented 5 months ago

from pyNastran.converters.nastran.nastran_to_vtk import nastran_to_vtk

"""
Converts a Natsran geometry/results to vtk *.vtu

Parameters
----------
bdf_filename: str, BDF, OP2Geom
    the geometry
op2_filename: str, OP2, OP2Geom
    the results; can be '' for no op2
vtk_filename : str
    the output filename; expected to be a *.vtu file

Examples
--------
bdf_filename = 'fem.bdf'
op2_filename = 'fem.op2'
vtk_filename = 'fem.vtu'

bdf_model = read_bdf(bdf_filename)
op2_model = read_op2(op2_filename)
model = read_op2_geom(op2_filename)

nastran_to_vtk(bdf_model, op2_model, vtk_filename)
nastran_to_vtk(bdf_filename, op2_filename, vtk_filename)
nastran_to_vtk(model, model, vtk_filename)
karma0704 commented 5 months ago

There is no bdf_2_vtk or op2_2_vtk function. I believe the function you’re after is nastran_to_vtk. The usage is in the docstring and there are examples of it in the code. You can also just load up the gui and export. On Tue, Mar 19, 2024 at 11:35 PM karma0704 @.> wrote: Hello, gentleman, can you realize the function of converting the geometric shape and topology of the bdf file and the displacement, stress, and strain extracted from the op2 file into the corresponding data blocks in the VTK text file? If you have implemented these functions, can you provide some test examples? — Reply to this email directly, view it on GitHub <#772>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAICUWPMCVUSGIWSMIH76RTYZEU4RAVCNFSM6AAAAABE637VH2VHI2DSMVQWIX3LMV43ASLTON2WKOZSGE4TMNZWGIYDIOA . You are receiving this because you are subscribed to this thread.Message ID: @.>

Thank you very much for your reply. I called the nastran_to_vtk function to complete the output of the VTK file as you said. However, after the function was executed, the following error occurred: image

image

SteveDoyle2 commented 5 months ago

oops! Didn't notice that in the CI. It's fixed.

guotao1415 commented 5 months ago

There is no bdf_2_vtk or op2_2_vtk function. I believe the function you’re after is nastran_to_vtk. The usage is in the docstring and there are examples of it in the code. You can also just load up the gui and export. On Tue, Mar 19, 2024 at 11:35 PM karma0704 @.> wrote: Hello, gentleman, can you realize the function of converting the geometric shape and topology of the bdf file and the displacement, stress, and strain extracted from the op2 file into the corresponding data blocks in the VTK text file? If you have implemented these functions, can you provide some test examples? — Reply to this email directly, view it on GitHub <#772>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAICUWPMCVUSGIWSMIH76RTYZEU4RAVCNFSM6AAAAABE637VH2VHI2DSMVQWIX3LMV43ASLTON2WKOZSGE4TMNZWGIYDIOA . You are receiving this because you are subscribed to this thread.Message ID: @.>

Sorry to bother you again

Do you mean that both bdf and op2 files need to be present in order to convert them into vtk files? Can I convert an op2 file without a bdf file to a vtk file?

The op2 file seems to contain geometric information. I tried the following example but encountered an error

# op2_filename = 'fem.op2'
# vtk_filename = 'fem.vtu'
# model = read_op2_geom(op2_filename)
# nastran_to_vtk(model, model, vtk_filename)

Traceback (most recent call last): File "d:\WORK\CODE\op2_to_vtu\op2_to_vtu.py", line 23, in nastran_to_vtk(model, model, vtk_filename) File "C:\Users\guotao\AppData\Roaming\Python\Python312\site-packages\pyNastran\converters\nastran\nastran_to_vtk.py", line 268, in nastran_to_vtk gui.load_nastran_geometry(bdf_filename) File "C:\Users\guotao\AppData\Roaming\Python\Python312\site-packages\pyNastran\converters\nastran\gui\nastran_io.py", line 470, in load_nastran_geometry skip_reading = self._remove_old_nastran_geometry(bdf_filename) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\guotao\AppData\Roaming\Python\Python312\site-packages\pyNastran\converters\nastran\gui\nastran_io.py", line 350, in _remove_old_nastran_geometry if bdf_filename is None or bdf_filename == '': File "C:\Users\guotao\AppData\Roaming\Python\Python312\site-packages\pyNastran\op2\op2.py", line 194, in eq is_equal = self.assert_op2_equal(op2_model, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\guotao\AppData\Roaming\Python\Python312\site-packages\pyNastran\op2\op2.py", line 237, in assert_op2_equal if not self.read_mode == op2_model.read_mode: ^^^^^^^^^^^^^^^^^^^ AttributeError: 'str' object has no attribute 'read_mode'

SteveDoyle2 commented 5 months ago

Please don't reference closed tickets especially with unrelated errors