Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading stiffness matrix from op4 fails with large matrices #661

Open
Jrois opened this issue Sep 24, 2021 · 4 comments
Open

Reading stiffness matrix from op4 fails with large matrices #661

Jrois opened this issue Sep 24, 2021 · 4 comments

Comments

@Jrois
Copy link

Jrois commented Sep 24, 2021

Hi,

I am having a issues reading in a stiffness matrix from an .op4 file.
Everything worked fine until I started scaling up the number of nodes, which led me to believe my issue is similar to a previous issue. However my error traceback was different so I decided to make a separate issue.
I have tried two set-ups and they both produce a different error:

Python v3.8 & pyNastran v1.3.1 give the following traceback:

Traceback (most recent call last):
File "test2.py", line 14, in
MAT = model.read_op4("./MSCNpyBenchmarkN10/MSCNpyBenchmarkN10_kelems.op4", matrix_names=["KAA"])
File "c:\user\anaconda3\envs\py38\lib\site-packages\pyNastran\op4\op4.py", line 137, in read_op4
return self.read_op4_binary(op4_filename, matrix_names, precision)
File "c:\user\anaconda3\envs\py38\lib\site-packages\pyNastran\op4\op4.py", line 686, in read_op4_binary
(name, form, matrix) = self._read_matrix_binary(op4, precision, matrix_names)
File "c:\user\anaconda3\envs\py38\lib\site-packages\pyNastran\op4\op4.py", line 804, in _read_matrix_binary
A = self._read_real_binary(op4, nrows, ncols, Type, is_sparse, is_big_mat)
File "c:\user\anaconda3\envs\py38\lib\site-packages\pyNastran\op4\op4.py", line 895, in _read_real_binary
A = self._read_real_sparse_binary(op4, nrows, ncols, matrix_type, is_big_mat)
File "c:\user\anaconda3\envs\py38\lib\site-packages\pyNastran\op4\op4.py", line 914, in _read_real_sparse_binary
(icol, irow, nwords) = self.get_markers_sparse(op4, is_big_mat)
File "c:\user\anaconda3\envs\py38\lib\site-packages\pyNastran\op4\op4.py", line 1354, in get_markers_sparse
unused_a, icol, irow, nwords = self.read_start_marker(op4)
File "c:\user\anaconda3\envs\py38\lib\site-packages\pyNastran\op4\op4.py", line 726, in read_start_marker
assert self.n == op4.tell(), 'n=%s tell=%s' % (self.n, op4.tell())
AssertionError: n=5177352 tell=5177344

When debug=True I get a different error:

Traceback (most recent call last):
File "C:\user\anaconda3\envs\py38\lib\site-packages\IPython\core\interactiveshell.py", line 3441, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
runfile('C:/user/WF/python/MSCN-PY/test2.py', wdir='C:/SpaceLabs/WF/python/MSCN-PY')
File "C:\user\PyCharm Community Edition 2021.2.1\plugins\python-ce\helpers\pydev_pydev_bundle\pydev_umd.py", line 198, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "C:\user\PyCharm Community Edition 2021.2.1\plugins\python-ce\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/user/WF/python/MSCN-PY/test2.py", line 14, in
MAT = model.read_op4("./MSCNpyBenchmarkN10/MSCNpyBenchmarkN10_kelems.op4", matrix_names=["KAA"])
File "C:\user\anaconda3\envs\py38\lib\site-packages\pyNastran\op4\op4.py", line 137, in read_op4
return self.read_op4_binary(op4_filename, matrix_names, precision)
File "C:\user\anaconda3\envs\py38\lib\site-packages\pyNastran\op4\op4.py", line 686, in read_op4_binary
(name, form, matrix) = self._read_matrix_binary(op4, precision, matrix_names)
File "C:\user\anaconda3\envs\py38\lib\site-packages\pyNastran\op4\op4.py", line 804, in _read_matrix_binary
A = self._read_real_binary(op4, nrows, ncols, Type, is_sparse, is_big_mat)
File "C:\user\anaconda3\envs\py38\lib\site-packages\pyNastran\op4\op4.py", line 895, in _read_real_binary
A = self._read_real_sparse_binary(op4, nrows, ncols, matrix_type, is_big_mat)
File "C:\user\anaconda3\envs\py38\lib\site-packages\pyNastran\op4\op4.py", line 938, in _read_real_sparse_binary
self._show(op4, 100, types='qd')
File "C:\user\anaconda3\envs\py38\lib\site-packages\pyNastran\op4\op4.py", line 1015, in _show
strings, ints, floats = self._show_data(data, types=types, endian=endian)
File "C:\user\anaconda3\envs\py38\lib\site-packages\pyNastran\op4\op4.py", line 1044, in _show_data
return self._write_data(sys.stdout, data, types=types, endian=endian)
File "C:\user\anaconda3\envs\py38\lib\site-packages\pyNastran\op4\op4.py", line 1092, in _write_data
doubles = unpack(b'%s%id' % (endian, ndoubles), data[:ndoubles*8])
TypeError: %b requires a bytes-like object, or an object that implements bytes, not 'str'

Python v3.6 & pyNastran v1.2.1 gives this traceback:

Traceback (most recent call last):
File "test2.py", line 5, in
MAT = model.read_op4("K.op4")
File "c:\user\anaconda3\envs\py38\lib\site-packages\pyNastran\op4\op4.py", line 137, in read_op4
return self.read_op4_binary(op4_filename, matrix_names, precision)
File "c:\user\anaconda3\envs\py38\lib\site-packages\pyNastran\op4\op4.py", line 686, in read_op4_binary
(name, form, matrix) = self._read_matrix_binary(op4, precision, matrix_names)
File "c:\user\anaconda3\envs\py38\lib\site-packages\pyNastran\op4\op4.py", line 804, in _read_matrix_binary
A = self._read_real_binary(op4, nrows, ncols, Type, is_sparse, is_big_mat)
File "c:\user\anaconda3\envs\py38\lib\site-packages\pyNastran\op4\op4.py", line 895, in _read_real_binary
A = self._read_real_sparse_binary(op4, nrows, ncols, matrix_type, is_big_mat)
File "c:\user\anaconda3\envs\py38\lib\site-packages\pyNastran\op4\op4.py", line 974, in _read_real_sparse_binary
value_list = unpack(str_values, data[0:nvalues * nbytes_per_value])
struct.error: bad char in struct format

Moreover, for some attempts I have gotten the same traceback as the first above (ending in AssertionError).

Below you can find a .zip containing the model and a code snippet to reproduce the error. I also added the op4 file produced since it can take some time to run the model.

Thanks in advance!

Kind regards,
Joris

test.zip

@SteveDoyle2
Copy link
Owner

SteveDoyle2 commented Sep 26, 2021 via email

@Jrois
Copy link
Author

Jrois commented Sep 27, 2021

Hi Steve,

Thanks for the suggestion. I had not tried that yet. Unfortunately, I couldn't get that working either.
I have tried writing the output using

PARAM,EXTOUT,DMIGOP2

After adding matrices to read using the method model.set_additional_matrices_to_read (as suggested by arising errors) I get an message saying there was a FATAL ERROR in the f06:

pyNastran.f06.errors.FatalError: There was a Nastran FATAL Error. Check the F06.
last table=b'MUG1'; post=-2

However, upon inspecting the f06, I could not find any fatal errors or other signs of errors.

I also tried to output using

EXTSEOUT(STIF, EXTID=30, DMIGOP2=13)

But that lead to the same results. Moreover, both small and large problems yield the same error.

I understand that you don't have time to look at the problem now. So when you do, please send me an update.

Enjoy you holiday!

@SteveDoyle2
Copy link
Owner

SteveDoyle2 commented Sep 29, 2021 via email

@Jrois
Copy link
Author

Jrois commented Sep 30, 2021

I am not using superelements, at least not explicitly. I use an API to recreate the model such that all elements have unique nodes. This way the whole model becomes decoupled, which allows me to extract element stiffness matrices for all elements. I am relatively new to Nastran and I'm not yet familiar with superelements so I can't say for sure that this process is related to superelements.

As for the reading of the matrix, I didn't realise you could use the BDF reader to also read punch files. Instead I now wrote my own script that reads the matrix. This however can take some time when large matrices are concerned and I believe OP4 or OP2 would be faster. So if ever you fix the problem with large matrices I would definitely like to know!

Thanks for your time and help

Kind regards,
Joris

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants