pyNastran/op2/op2

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

op2 Module

Inheritance diagram of pyNastran.op2.op2

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: Optional[bool] = True, log: Optional[Any] = None, debug_file: Optional[str] = None, mode: Optional[str] = None)[source]

Bases: pyNastran.op2.op2_interface.op2_scalar.OP2_Scalar, pyNastran.op2.writer.op2_writer.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: Optional[List[str]] = None, stop_on_failure: bool = True, debug: bool = False) → None[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: str = 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,
}
create_objects_from_matrices() → None[source]
creates the following objects:
  • monitor3 : MONPNT3 object from the MP3F matrix

  • monitor1 : MONPNT1 object from the PMRF, PERF, PFRF, AGRF, PGRF, AFRF matrices

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]][source]
Returns
keys3List[int, int, int, int, int, str]

the keys in order

include_exclude_results(exclude_results: Optional[List[str]] = None, include_results: Optional[List[str]] = 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
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: Optional[List[str]] = 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: Optional[List[str]] = 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: Optional[str] = None, combine: bool = True, build_dataframe: Optional[bool] = False, skip_undefined_matrices: bool = False, encoding: Optional[str] = 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: Optional[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 cid

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 cid

Dictionary from coordinate id to corresponding node ids.

icd_transformdict{int cid

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: Optional[str] = None, load_geometry: bool = False, combine: bool = True, subcases: Optional[List[int]] = None, exclude_results: Optional[List[str]] = None, include_results: Optional[List[str]] = None, log: Optional[Any] = None, debug: Optional[bool] = True, build_dataframe: Optional[bool] = False, skip_undefined_matrices: bool = True, mode: Optional[str] = None, encoding: Optional[str] = None) → pyNastran.op2.op2.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