pyNastran/op2/op2

This is the pyNastran.op2.op2.rst file.

op2 Module

digraph inheritancef8ea0456ef { bgcolor=transparent; rankdir=LR; size=""; "pyNastran.f06.f06_writer.F06Writer" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled"]; "pyNastran.op2.op2_interface.op2_f06_common.OP2_F06_Common" -> "pyNastran.f06.f06_writer.F06Writer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "pyNastran.op2.fortran_format.FortranFormat" [URL="pyNastran.op2.fortran_format.html#pyNastran.op2.fortran_format.FortranFormat",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="defines basic methods for reading Fortran formatted data files"]; "pyNastran.op2.op2.OP2" [URL="#pyNastran.op2.op2.OP2",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; "pyNastran.op2.op2_interface.op2_scalar.OP2_Scalar" -> "pyNastran.op2.op2.OP2" [arrowsize=0.5,style="setlinewidth(0.5)"]; "pyNastran.op2.writer.op2_writer.OP2Writer" -> "pyNastran.op2.op2.OP2" [arrowsize=0.5,style="setlinewidth(0.5)"]; "pyNastran.op2.op2_interface.op2_codes.Op2Codes" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled"]; "pyNastran.op2.op2_interface.op2_common.OP2Common" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled"]; "pyNastran.op2.op2_interface.op2_codes.Op2Codes" -> "pyNastran.op2.op2_interface.op2_common.OP2Common" [arrowsize=0.5,style="setlinewidth(0.5)"]; "pyNastran.f06.f06_writer.F06Writer" -> "pyNastran.op2.op2_interface.op2_common.OP2Common" [arrowsize=0.5,style="setlinewidth(0.5)"]; "pyNastran.op2.op2_interface.op2_f06_common.OP2_F06_Common" [URL="op2_interface/pyNastran.op2.op2_interface.html#pyNastran.op2.op2_interface.op2_f06_common.OP2_F06_Common",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; "pyNastran.op2.op2_interface.op2_scalar.OP2_Scalar" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Defines an interface for the Nastran OP2 file."]; "pyNastran.op2.op2_interface.op2_common.OP2Common" -> "pyNastran.op2.op2_interface.op2_scalar.OP2_Scalar" [arrowsize=0.5,style="setlinewidth(0.5)"]; "pyNastran.op2.fortran_format.FortranFormat" -> "pyNastran.op2.op2_interface.op2_scalar.OP2_Scalar" [arrowsize=0.5,style="setlinewidth(0.5)"]; "pyNastran.op2.writer.op2_writer.OP2Writer" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled"]; "pyNastran.op2.op2_interface.op2_f06_common.OP2_F06_Common" -> "pyNastran.op2.writer.op2_writer.OP2Writer" [arrowsize=0.5,style="setlinewidth(0.5)"]; }

Defines the main OP2 class. Defines:

  • read_op2(op2_filename=None, combine=True, subcases=None,

    exclude_results=None, include_results=None, log=None, debug=True, debug_file=None, build_dataframe=False, skip_undefined_matrices=True, mode=’msc’, encoding=None)

  • OP2(debug=True, log=None, debug_file=None, mode=’msc’) - build_dataframe() - combine_results(combine=True) - create_objects_from_matrices() - object_attributes(mode=’public’, keys_to_skip=None, filter_properties=False) - object_methods(mode=’public’, keys_to_skip=None) - print_subcase_key() - read_op2(op2_filename=None, combine=True, build_dataframe=False,

    skip_undefined_matrices=False, encoding=None)

    • set_mode(mode)

    • transform_displacements_to_global(i_transform, coords, xyz_cid0=None, debug=False)

    • transform_gpforce_to_global(nids_all, nids_transform, i_transform, coords, xyz_cid0=None)

class pyNastran.op2.op2.OP2(debug: bool | None = True, log: Any = None, debug_file: str | None = None, mode: str | None = None)[source]

Bases: OP2_Scalar, OP2Writer

Initializes the OP2 object

Parameters:
debugbool/None; default=True
used to set the logger if no logger is passed in

True: logs debug/info/warning/error messages False: logs info/warning/error messages None: logs warning/error messages

logLog()

a logging object to write debug messages to

(.. seealso:: import logging)

debug_filestr; default=None (No debug)

sets the filename that will be written to

modestr; default=None -> ‘msc’

{msc, nx}

assert_op2_equal(op2_model, skip_results: list[str] | None = None, stop_on_failure: bool = True, debug: bool = False) bool[source]

Diffs the current op2 model vs. another op2 model.

Parameters:
op2_modelOP2()

the model to compare to

skip_resultslist[str]; default=None -> []

results that shouldn’t be compred

stop_on_failurebool; default=True

True : Crashes if they’re not equal False : Go to the next object

debugbool; default=False

give slightly more debugging messages

Returns:
is_equalbool

are the objects equal?

Raises:
AssertionError/ValueErrorstop_on_failure=True and and error occurred
NotImplementedErrorthis is a sign of an unsupported object
build_dataframe() None[source]

Converts the OP2 objects into pandas DataFrames

Todo

fix issues with: - RealDisplacementArray - RealPlateStressArray (???) - RealPlateStrainArray (???) - RealCompositePlateStrainArray (???)

combine_results(combine: bool = True) None[source]

we want the data to be in the same format and grouped by subcase, so we take

stress = {
    # isubcase, analysis_code, sort_method, count, superelement_adaptivity_index, pval_step
    (1, 2, 1, 0, 'SUPERELEMENT 0', '') : result1,
    (1, 2, 1, 0, 'SUPERELEMENT 10', '') : result2,
    (1, 2, 1, 0, 'SUPERELEMENT 20', '') : result3,
    (2, 2, 1, 0, 'SUPERELEMENT 0', '') : result4,

code = (isubcase, analysis_code, sort_method, count, ogs,
        superelement_adaptivity_index, pval_step)
  }

and convert it to:

stress = {
    1 : result1 + result2 + results3,
    2 : result4,
}
export_hdf5_file(hdf5_file: H5File, exporter=None) None[source]

Converts the OP2 objects into hdf5 object

Parameters:
hdf5_fileH5File()

an h5py object

exporterHDF5Exporter; default=None

unused

TODO: doesn’t support:
  • BucklingEigenvalues

export_hdf5_filename(hdf5_filename: str) None[source]

Converts the OP2 objects into hdf5 object

TODO: doesn’t support:
  • BucklingEigenvalues

get_key_order() list[tuple[int, int, int, int, int, str, str]][source]
Returns:
keys3list[tuple[int, int, int, int, int, str, str]]

the keys in order

key: isubcase, analysis_code, sort_method, count, ogs, superelement_adaptivity_index, pval_step

isubcase: int

subcase id

analysis_code: int (rough guess)

1: statics 2: modes 5: freq 6: transient 8: post-buckling 9: complex eigenvalues 10: nonlinear statics

sort_method: int

0: SORT1; 1: SORT2

count: int

optimization flag; default = 0

ogs: int

default = 0

superelement_adaptivity_index: str

default = ‘’

pval_step: str

default = ‘’

include_exclude_results(exclude_results: list[str] | None = None, include_results: list[str] | None = None) None[source]

Sets results to include/exclude

Parameters:
exclude_results / include_resultslist[str] / str; default=None

a list of result types to exclude/include one of these must be None

property is_geometry: bool
load(obj_filename: str = 'model.obj') None[source]

Loads a pickleable object

load_hdf5_file(h5_file: H5File, combine: bool = True) None[source]

Loads an h5 file object into an OP2 object

Parameters:
h5_fileH5File()

an h5py file object

combinebool; default=True

runs the combine routine

load_hdf5_filename(hdf5_filename: str, combine: bool = True) None[source]

Loads an h5 file into an OP2 object

Parameters:
hdf5_filenamestr

the path to the an hdf5 file

combinebool; default=True

runs the combine routine

object_attributes(mode: str = 'public', keys_to_skip: list[str] | None = None, filter_properties: bool = False) list[str][source]

List the names of attributes of a class as strings. Returns public attributes as default.

Parameters:
modestr

defines what kind of attributes will be listed * ‘public’ - names that do not begin with underscore * ‘private’ - names that begin with single underscore * ‘both’ - private and public * ‘all’ - all attributes that are defined for the object

keys_to_skiplist[str]; default=None -> []

names to not consider to avoid deprecation warnings

Returns:
attribute_nameslist[str]

sorted list of the names of attributes of a given type or None if the mode is wrong

object_methods(mode: str = 'public', keys_to_skip: list[str] | None = None) list[str][source]

List the names of methods of a class as strings. Returns public methods as default.

Parameters:
objinstance

the object for checking

modestr

defines what kind of methods will be listed * “public” - names that do not begin with underscore * “private” - names that begin with single underscore * “both” - private and public * “all” - all methods that are defined for the object

keys_to_skiplist[str]; default=None -> []

names to not consider to avoid deprecation warnings

Returns:
methodlist[str]

sorted list of the names of methods of a given type or None if the mode is wrong

print_subcase_key() None[source]
read_op2(op2_filename: str | None = None, combine: bool = True, build_dataframe: bool | None = False, skip_undefined_matrices: bool = False, encoding: str | None = None) None[source]

Starts the OP2 file reading

Parameters:
op2_filenamestr (default=None -> popup)

the op2_filename

combinebool; default=True

True : objects are isubcase based False : objects are (isubcase, subtitle) based;

will be used for superelements regardless of the option

#load_as_h5default=False

#loads the op2 as an h5 file to save memory #stores the result.element/data attributes in h5 format

build_dataframebool; default=False

builds a pandas DataFrame for op2 objects None: True if in iPython, False otherwise

skip_undefined_matricesbool; default=False

True : prevents matrix reading crashes

encodingstr

the unicode encoding (default=None; system default)

save(obj_filename: str = 'model.obj', unxref: bool = True) None[source]

Saves a pickleable object

saves() str[source]

Saves a pickled string

set_mode(mode: str) None[source]

Sets the mode as ‘msc’, ‘nx’, ‘autodesk’, ‘nasa95’, or ‘optistruct’

to_msc(msg='') None[source]
to_nx(msg='') None[source]
transform_displacements_to_global(icd_transform: Any, coords: dict[int, Any], xyz_cid0: Any = None, debug: bool = False) None[source]

Transforms the data of displacement-like results into the global coordinate system for those nodes with different output coordinate systems. Takes indicies and transformation matricies for nodes with their output in coordinate systems other than the global.

Used in combination with BDF.get_displacement_index

Parameters:
icd_transformdict{int cidint ndarray}

Dictionary from coordinate id to index of the nodes in BDF.point_ids that their output (CD) in that coordinate system.

coordsdict{int cid :Coord()}

Dictionary of coordinate id to the coordinate object Use this if CD is only rectangular Use this if CD is not rectangular

xyz_cid0(nnodes+nspoints, 3) float ndarray

the nodes in the global frame Don’t use this if CD is only rectangular Use this if CD is not rectangular

debugbool; default=False

developer debug

.. warning:: only works if all nodes are included…

test_pynastrangui isat_tran.dat isat_tran.op2 -f nastran

.. note:: Nastran has this concept of a basic (cid=0) and global (cid=cd)

coordinate system. They occur at the same time. Basic is for positions/properties, while global is for result outputs.

pyNastran’s OP2 interface uses:
  • cd=0 for global frames

  • cd>0 are local frames

pyNastran’s BDF interface uses:
  • cp=0 for global frames

  • cp>0 are local frames

transform_gpforce_to_global(nids_all, nids_transform, icd_transform, coords, xyz_cid0=None)[source]

Transforms the data of GPFORCE results into the global coordinate system for those nodes with different output coordinate systems. Takes indicies and transformation matricies for nodes with their output in coordinate systems other than the global.

Used in combination with BDF.get_displacement_index

Parameters:
nids_all???

???

nids_transformdict{int cidint ndarray nds}

Dictionary from coordinate id to corresponding node ids.

icd_transformdict{int cidint ndarray}

Dictionary from coordinate id to index of the nodes in BDF.point_ids that their output (CD) in that coordinate system.

coordsdict{int cid :Coord()}

Dictionary of coordinate id to the coordinate object Use this if CD is only rectangular Use this if CD is not rectangular

xyz_cid0???

required for cylindrical/spherical coordinate systems

pyNastran.op2.op2.read_op2(op2_filename: str | None = None, load_geometry: bool = False, combine: bool = True, subcases: list[int] | None = None, exclude_results: list[str] | None = None, include_results: list[str] | None = None, log: Any = None, debug: bool | None = True, build_dataframe: bool | None = False, skip_undefined_matrices: bool = True, mode: str | None = None, encoding: str | None = None) OP2[source]

Creates the OP2 object without calling the OP2 class.

Parameters:
op2_filenamestr (default=None -> popup)

the op2_filename

load_geometry: bool; default=False

False: load results and matrices True: load geometry as well

combinebool; default=True

True : objects are isubcase based False : objects are (isubcase, subtitle) based;

will be used for superelements regardless of the option

subcaseslist[int, …] / int; default=None->all subcases

list of [subcase1_ID,subcase2_ID]

exclude_results / include_resultslist[str] / str; default=None

a list of result types to exclude/include one of these must be None build_dataframe : bool; default=False

builds a pandas DataFrame for op2 objects None: True if in iPython, False otherwise

skip_undefined_matricesbool; default=False

True : prevents matrix reading crashes

debugbool/None; default=True
used to set the logger if no logger is passed in

True: logs debug/info/warning/error messages False: logs info/warning/error messages None: logs warning/error messages

logLog()

a logging object to write debug messages to (.. seealso:: import logging)

modestr; default=None -> ‘msc’

the version of the Nastran you’re using {nx, msc, autodesk, optistruct, nasa95}

encodingstr

the unicode encoding (default=None; system default)

Returns:
modelOP2()

an OP2 object

Todo

creates the OP2 object without all the read methods ..

Note

this method will change in order to return an object that does not have so many methods