pyyeti.nastran.op4.OP4¶
- class pyyeti.nastran.op4.OP4[source]¶
Class for reading/writing Nastran output4 (.op4) files.
See demo below and refer to the help on these functions for more information:
write()(orsave()),load()(or the lower leveldctload(),listload()), anddir(). save is an alias for write.Examples
Instantiate the class and create matrices for demo:
>>> from pyyeti.nastran import op4 >>> o4 = op4.OP4() >>> import numpy as np >>> rng = np.random.default_rng() >>> r = rng.normal(size=(3, 5)) >>> c = r + 1j*rng.normal(size=(3, 5))
Write binary op4 file, with ‘r’ first:
>>> o4.write('testbin.op4', ['r', 'c'], [r, c])
Write ascii op4 file without caring about order:
>>> o4.write('testascii.op4', dict(r=r, c=c), binary=False)
To read an op4 file into a dictionary (indexed by the name in lower case):
>>> dct = o4.load('testbin.op4', into='dct')
Note: to preserve order, the dictionary returned by “load” or “read” is actually an OrderedDict from the standard Python “collections” module (
collections.OrderedDict).To read into a list:
>>> names, mats, forms, mtypes = o4.load('testascii.op4', ... into='list')
Check some results:
>>> print(np.all(r == dct['r'][0])) True
>>> if names[0] == 'c': ... print(np.all(c == mats[0])) ... else: ... print(np.all(c == mats[1])) True
To print a ‘directory’ of an op4 file:
>>> d = o4.dir('testbin.op4') r , 3 x 5 , form=2, mtype=2 c , 3 x 5 , form=2, mtype=4
Clean up:
>>> import os >>> os.remove('testbin.op4') >>> os.remove('testascii.op4')
Methods
__init__()dctload(filename[, namelist, justmatrix, sparse])Read all matching matrices from op4 file into dictionary.
dir(filename[, verbose])Directory of all matrices in op4 file.
listload(filename[, namelist, sparse])Read all matching matrices from op4 file into a list; useful if op4 file has duplicate names.
load(filename[, namelist, into, justmatrix, ...])Read all matching matrices from op4 file into dictionary or list; interface to
dctload()andlistload().write(filename, names[, matrices, binary, ...])Write op4 file.