SteveDoyle2 / pyNastran

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

op4 sparse ascii and binary readers failing on bigger stiffness matrices #293

Open wrtc90 opened 8 years ago

wrtc90 commented 8 years ago

I'm (again) trying to read the (l-level) stiffness matrix in linear statics KLL (pulled out right before the SSG3 call as either sparse ascii or sparse binary (i don't care if binary or ascii here)) from an .op4. Basically I'm doing the same as in my previous issue but the matrices are larger now with KLL having 89034 rows and columns. While everything worked fine up to 22k rows and columns, I'm getting the following tracebacks when doing

from pyNastran.op4.op4 import OP4 op4 = OP4() KLL = op4.read_op4('KLL.op4','KLL','default')

For sparse binary KLL:

Traceback (most recent call last): File "", line 1, in File "C:/Project16_3_16/pyNastran Test/read_test.py", line 5, in mat_KLL2 = op4.read_op4('KLL.op4','KLL','default') File "C:\Python27\lib\site-packages\pyNastran\op4\op4.py", line 139, in read_op4 return self.read_op4_binary(op4_filename, matrix_names, precision) File "C:\Python27\lib\site-packages\pyNastran\op4\op4.py", line 552, in read_op4_binary (name, form, matrix) = self._read_matrix_binary(op4, precision, matrix_names) File "C:\Python27\lib\site-packages\pyNastran\op4\op4.py", line 634, in _read_matrix_binary raise NotImplementedError(msg) NotImplementedError: record_length=0 filename='KLL.op4'

For sparse ascii KLL:

Traceback (most recent call last): File "", line 1, in File "C:/Project16_3_16/pyNastran Test/read_test.py", line 4, in mat_KLL = op4.read_op4('KLL.op4','KLL','default') File "C:\Python27\lib\site-packages\pyNastran\op4\op4.py", line 141, in read_op4 return self.read_op4_ascii(op4_filename, matrix_names, precision) File "C:\Python27\lib\site-packages\pyNastran\op4\op4.py", line 150, in read_op4_ascii (name, form, matrix) = self._read_matrix_ascii(op4, matrix_names, precision) File "C:\Python27\lib\site-packages\pyNastran\op4\op4.py", line 196, in _read_matrix_ascii dtype, is_sparse, is_big_mat) File "C:\Python27\lib\site-packages\pyNastran\op4\op4.py", line 346, in _read_real_ascii A = self._read_real_sparse_ascii(op4, nrows, ncols, line_size, line, dtype, is_big_mat) File "C:\Python27\lib\site-packages\pyNastran\op4\op4.py", line 247, in _read_real_sparse_ascii irow = self._get_irow_small_ascii(op4, line, sline, irow) File "C:\Python27\lib\site-packages\pyNastran\op4\op4.py", line 486, in _get_irow_small_ascii IS = int(op4.readline().strip()) ValueError: invalid literal for int() with base 10: '5 1'

I am glad to provide the model with the DMAP code required to output the stiffness matrix (I cannot reproduce the error with the static solid shell bar as this seems to be a problem related to the matrix size). I appended the matrices.

Kind regards, Chris

pyNastranMatrices.zip

SteveDoyle2 commented 8 years ago

The ASCII file is fixed. There was an issue with the following:

Input-logical-default=FALSE. BIGMAT is applicable only when IUNIT < 0. BIGMAT=FALSE selects the format that uses a string header as described under Remark 1. But, if the matrix has more than 65535 rows, then BIGMAT will automatically be set to TRUE regardless of the value specified.

I'm not sure what's going on with the binary file yet. It gets further, but it's still wrong.

wrtc90 commented 8 years ago

What exactly had to be fixed for the ASCII file to be read? Something in the .op4 reader, the .op4 file of the matrix or the DMAP statements to write the matrix?

I gather that op4._read_matrix_ascii does not recognize the BIGMAT property because the number of rows is not negative in record 1 as it somehow should be according to the DMAP guide. Therefore op4._get_irow_small_ascii is called and fails to read the records of the BIGMAT ASCII file, right?

For now I just hardcoded is_big_mat = True in _read_matrix_ascii and it worked

SteveDoyle2 commented 8 years ago

Oh...ooops...I never committed it.

From line 170 of op4.py in the new version

    if nrows < 0:  # if less than 0, big
        is_big_mat = True
    elif nrows > 0:
        is_big_mat = False

I added the bolded lines

On Tue, Mar 22, 2016 at 11:42 AM, wrtc90 notifications@github.com wrote:

What exactly had to be fixed for the ASCII file to be read? Something in the .op4 reader, the .op4 file of the matrix or the DMAP statements to write the matrix?

I gather that op4._read_matrix_ascii does not recognize the BIGMAT property because the number of rows is not negative in record 1 as it somehow should be according to the DMAP guide. Therefore op4._get_irow_small_ascii is called and fails to read the records of the BIGMAT ASCII file, right?

For now I just hardcoded is_big_mat = True in _read_matrix_ascii and it worked

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/SteveDoyle2/pyNastran/issues/293#issuecomment-199957152

wrtc90 commented 8 years ago

Oooh ok. Thanks!

drcavaliere commented 1 year ago

Hello,

I follow up this conversation on an extra error when reading op4 containing big matrices. The error I get is the following:

"in _read_matrix_ascii ncols, nrows, form, matrix_type = line[0:32].split() ValueError: not enough values to unpack (expected 4, got 3)"

This is due to the fact that the line of my op4 file contains the following string: line = ' 9552018-9552018 6 1KAA 1P,3E22.15'

As a consequence, the algorithm is not able to split correctly nrows and ncols, and gives back the following:

['9552018-9552018', '6', '1KAA']

instead of: ['9552018', '-9552018', '6', '1KAA']

Could that be fixed?

Thanks, Fabiola Cavaliere