Skip to content

Commit

Permalink
add etblock support (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
akaszynski authored Sep 9, 2023
1 parent 320a99c commit 52b46f1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ci:
repos:

- repo: https://github.com/psf/black
rev: 23.7.0
rev: 23.9.0
hooks:
- id: black

Expand Down
18 changes: 18 additions & 0 deletions mapdl_archive/cython/_reader.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions tests/test_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions tests/test_data/etblock.cdb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 52b46f1

Please sign in to comment.