From 0b136afb84eea533be1c2165c810ca651bf07bc1 Mon Sep 17 00:00:00 2001 From: Alex Kaszynski Date: Sat, 9 Sep 2023 15:09:02 -0600 Subject: [PATCH] add etblock support --- .pre-commit-config.yaml | 2 +- mapdl_archive/cython/_reader.pyx | 18 ++++++++++++++++++ tests/test_archive.py | 8 ++++++++ tests/test_data/etblock.cdb | 16 ++++++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 tests/test_data/etblock.cdb diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f7d1550..5dd3ae0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ ci: repos: - repo: https://github.com/psf/black - rev: 23.7.0 + rev: 23.9.0 hooks: - id: black diff --git a/mapdl_archive/cython/_reader.pyx b/mapdl_archive/cython/_reader.pyx index 0e34ccb..581f61c 100644 --- a/mapdl_archive/cython/_reader.pyx +++ b/mapdl_archive/cython/_reader.pyx @@ -149,6 +149,24 @@ def read(filename, read_parameters=False, debug=False, read_eblock=True): print('Invalid "ET" command %s' % line.decode()) continue + # read in new ETBLOCK (replacement for ET) + elif b'ETBLOCK' in line or b'etblock' in line: + # read the number of items in the block + set_dat = [safe_int(value) for value in line.split(b',')[1:]] + n_items = set_dat[0] + + # Skip Format1 (2i9,19a9) + fgets(line, sizeof(line), cfile) + print(line) + + for item in range(n_items): + fgets(line, sizeof(line), cfile) + + # Only read in the first two items (ELEM index and TYPE) + # NOTE: Remaining contents of the block are unknown + et_val = [safe_int(value) for value in line.split()[:2]] + elem_type.append(et_val) + elif b'EBLOCK,' == line[:7] or b'eblock,' == line[:7] and read_eblock: if eblock_read: # Sometimes, DAT files contain two EBLOCKs. Read diff --git a/tests/test_archive.py b/tests/test_archive.py index f2dae35..7e27a7e 100644 --- a/tests/test_archive.py +++ b/tests/test_archive.py @@ -537,6 +537,14 @@ def test_rlblock_prior_to_nblock(): assert archive.n_elem == 36 +def test_etblock(): + # test edge case where RLBLOCK is immediately prior to the NBLOCK + filename = os.path.join(TESTFILES_PATH, "etblock.cdb") + archive = Archive(filename) + assert archive.n_node == 4 + assert archive.n_elem == 1 + + class TestPathlibFilename: def test_pathlib_filename_property(self, pathlib_archive): assert isinstance(pathlib_archive.pathlib_filename, pathlib.Path) diff --git a/tests/test_data/etblock.cdb b/tests/test_data/etblock.cdb new file mode 100644 index 0000000..9cfb9c1 --- /dev/null +++ b/tests/test_data/etblock.cdb @@ -0,0 +1,16 @@ +/PREP7 +/TITLE,ETBLOCK testing +ETBLOCK, 1, 1 +(2i9,19a9) + 1 181 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + -1 +NBLOCK,6,SOLID, 1, 4 +(3i9,6e21.13e3) + 1 0 0 0.0000000000000E+000 0.0000000000000E+000 0.0000000000000E+000 + 2 0 0 1.0000000000000E+000 0.0000000000000E+000 0.0000000000000E+000 + 3 0 0 1.0000000000000E+000 1.0000000000000E+000 0.0000000000000E+000 + 4 0 0 0.0000000000000E+000 1.0000000000000E+000 0.0000000000000E+000 +N,UNBL,LOC, -1, +EBLOCK,19,SOLID, 4, 1 +(19i10) + 1 1 1 1 1 0 0 0 4 0 1 1 2 3 4