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

fix RLBLOCK extra line read #19

Merged
merged 4 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Simple makefile to simplify repetitive build env management tasks under posix

CODESPELL_DIRS ?= ./
CODESPELL_SKIP ?= "*.pyc,*.txt,*.gif,*.png,*.jpg,*.js,*.html,*.doctree,*.ttf,*.woff,*.woff2,*.eot,*.mp4,*.inv,*.pickle,*.ipynb,flycheck*,./.git/*,./.hypothesis/*,*.yml,./docs/build/*,./docs/images/*,./dist/*,*~,.hypothesis*,./docs/source/examples/*,*cover,*.dat,*.mac,\#*,build,./docker/mapdl/v211,./factory/*,./ansys/mapdl/reader/cython/_reader.c,./ansys/mapdl/reader/cython/_binary_reader.cpp,./ansys/mapdl/reader/cython/_cellqual.c,,./ansys/mapdl/reader/cython/_relaxmidside.c,*.inp,_*.c*,*.mypy_cache/*"
CODESPELL_SKIP ?= "*.pyc,*.txt,*.gif,*.png,*.jpg,*.js,*.html,*.doctree,*.ttf,*.woff,*.woff2,*.eot,*.mp4,*.inv,*.pickle,*.ipynb,flycheck*,./.git/*,./.hypothesis/*,*.yml,./docs/build/*,./docs/images/*,./dist/*,*~,.hypothesis*,./docs/source/examples/*,*cover,*.dat,*.mac,\#*,build,./docker/mapdl/v211,./factory/*,./ansys/mapdl/reader/cython/_reader.c,./ansys/mapdl/reader/cython/_binary_reader.cpp,./ansys/mapdl/reader/cython/_cellqual.c,,./ansys/mapdl/reader/cython/_relaxmidside.c,*.inp,_*.c*,*.mypy_cache/*,*.cdb"
CODESPELL_IGNORE ?= "ignore_words.txt"

all: doctest
Expand Down
55 changes: 45 additions & 10 deletions ansys/mapdl/reader/cython/_reader.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ import numpy as np
cimport numpy as np


def safe_int(value):
"""Safely convert a value to int.

Return int if can be converted, None if otherwise
"""
try:
return int(value)
except:
return


cdef extern from "reader.h":
int read_nblock_from_nwrite(char*, int*, double*, int)
int read_nblock(char*, int*, double*, int, int*, int, int*)
Expand All @@ -32,6 +43,7 @@ cdef extern from 'vtk_support.h':
int ans_to_vtk(const int, const int*, const int*, const int*, const int,
const int*, int64_t*, int64_t*, uint8_t*, const int)


cdef int myfgets(char *outstr, char *instr, int *n, int fsize):
"""Copies a single line from instr to outstr starting from position n """

Expand Down Expand Up @@ -240,23 +252,46 @@ def read(filename, read_parameters=False, debug=False):
if debug:
print('reading RLBLOCK')

# Get number of sets
ist = line.find(b',') + 1
ien = line[ist:].find(b',') + ist
nset = int(line[ist:ien])

# The RLBLOCK command defines a real constant
# set. The real constant sets follow each set,
# starting with

# Format1 and followed by one or more Format2's, as
# needed. The command format is:
# RLBLOCK,NUMSETS,MAXSET,MAXITEMS,NPERLINE
# Format1
# Format2
#
# where:
# Format1 - Data descriptor defining the format of the
# first line. For the RLBLOCK command, this is always
# (2i8,6g16.9). The first i8 is the set number, the
# second i8 is the number of values in this set,
# followed by up to 6 real
#
# Format2 - Data descriptors defining the format of
# the subsequent lines (as needed); this is always
# (7g16.9).
#
# - NUMSETS : The number of real constant sets defined
# - MAXSET : Maximum real constant set number
# - MAXITEMS : Maximum number of reals in any one set
# - NPERLINE : Number of reals defined on a line

# Get number of sets from the RLBLOCK line
set_dat = [safe_int(value) for value in line.split(b',')[1:]]
nset, maxset, maxitems, nperline = set_dat

# Skip Format1 and Format2 (always 2i8,6g16.9 and 7g16.9)
if myfgets(line, raw, &n, fsize): raise Exception(badstr)
if myfgets(line, raw, &n, fsize): raise Exception(badstr)

# Read data
c_set = 0
while True:
if myfgets(line, raw, &n, fsize): raise Exception(badstr)
for _ in range(nset):
rcon = [] # real constants
c_set += 1
if c_set > nset:
break

if myfgets(line, raw, &n, fsize): raise Exception(badstr)

# Get real constant number
rnum.append(int(line[:8]))
Expand Down
28 changes: 18 additions & 10 deletions tests/archive/test_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
VTK_WEDGE,
VTK_HEXAHEDRON]

test_path = os.path.dirname(os.path.abspath(__file__))
testfiles_path = os.path.join(test_path, 'test_data')
DAT_FILE = os.path.join(testfiles_path, 'Panel_Transient.dat')
TEST_PATH = os.path.dirname(os.path.abspath(__file__))
TESTFILES_PATH = os.path.join(TEST_PATH, 'test_data')
DAT_FILE = os.path.join(TESTFILES_PATH, 'Panel_Transient.dat')


def proto_cmblock(array):
Expand Down Expand Up @@ -57,12 +57,12 @@ def hex_archive():

@pytest.fixture(scope='module')
def all_solid_cells_archive():
return pymapdl_reader.Archive(os.path.join(testfiles_path, 'all_solid_cells.cdb'))
return pymapdl_reader.Archive(os.path.join(TESTFILES_PATH, 'all_solid_cells.cdb'))


@pytest.fixture(scope='module')
def all_solid_cells_archive_linear():
return pymapdl_reader.Archive(os.path.join(testfiles_path, 'all_solid_cells.cdb'),
return pymapdl_reader.Archive(os.path.join(TESTFILES_PATH, 'all_solid_cells.cdb'),
force_linear=True)


Expand Down Expand Up @@ -92,7 +92,7 @@ def test_repr(hex_archive):


def test_read_mesh200():
archive = pymapdl_reader.Archive(os.path.join(testfiles_path, 'mesh200.cdb'))
archive = pymapdl_reader.Archive(os.path.join(TESTFILES_PATH, 'mesh200.cdb'))
assert archive.grid.n_cells == 1000


Expand Down Expand Up @@ -135,7 +135,7 @@ def test_write_angle(tmpdir, hex_archive):

def test_missing_midside():
allowable_types = [45, 95, 185, 186, 92, 187]
archive_file = os.path.join(testfiles_path, 'mixed_missing_midside.cdb')
archive_file = os.path.join(TESTFILES_PATH, 'mixed_missing_midside.cdb')
archive = pymapdl_reader.Archive(archive_file, allowable_types=allowable_types)

assert (archive.quality > 0.0).all()
Expand Down Expand Up @@ -320,7 +320,7 @@ def test_write_component(tmpdir):


def test_read_parm():
filename = os.path.join(testfiles_path, 'parm.cdb')
filename = os.path.join(TESTFILES_PATH, 'parm.cdb')
archive = pymapdl_reader.Archive(filename)
with pytest.raises(AttributeError):
archive.parameters
Expand All @@ -335,7 +335,7 @@ def test_read_wb_nblock():
expected = np.array([[9.89367578e-02, -8.07092192e-04, 8.53764953e+00],
[9.65803244e-02, 2.00906704e-02, 8.53744951e+00],
[9.19243555e-02, 3.98781615e-02, 8.53723652e+00]])
filename = os.path.join(testfiles_path, 'workbench_193.cdb')
filename = os.path.join(TESTFILES_PATH, 'workbench_193.cdb')
archive = pymapdl_reader.Archive(filename)
assert np.allclose(archive.nodes, expected)
assert np.allclose(archive.node_angles, 0)
Expand All @@ -349,7 +349,7 @@ def test_read_hypermesh():
[5.98956, 2.97878, 2.37488],
[5.98956, 5.97878, 2.37488]])

filename = os.path.join(testfiles_path, 'hypermesh.cdb')
filename = os.path.join(TESTFILES_PATH, 'hypermesh.cdb')
archive = pymapdl_reader.Archive(filename, verbose=True)
assert np.allclose(archive.nodes[:6], expected)

Expand Down Expand Up @@ -424,3 +424,11 @@ def test_cython_write_eblock(hex_archive):
typenum,
nodenum,
vtk9)


def test_rlblock_prior_to_nblock():
# test edge case where RLBLOCK is immediately prior to the NBLOCK
filename = os.path.join(TESTFILES_PATH, 'ErnoRadiation.cdb')
archive = pymapdl_reader.Archive(filename)
assert archive.n_node == 65
assert archive.n_elem == 36
Loading