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

Modified abaqus parser to enable inp files with multiple NODE blocks #1441

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
20 changes: 15 additions & 5 deletions src/meshio/abaqus/_abaqus.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def read(filename):

def read_buffer(f):
# Initialize the optional data fields
points = []
points = None
cells = []
cell_ids = []
point_sets = {}
Expand All @@ -121,6 +121,9 @@ def read_buffer(f):
point_data = {}
point_ids = None

# MODIFIED jeffrey-cochran: Keep track of point id through multiple node blocks
counter = 0

line = f.readline()
while True:
if not line: # EOF
Expand All @@ -133,7 +136,15 @@ def read_buffer(f):

keyword = line.partition(",")[0].strip().replace("*", "").upper()
if keyword == "NODE":
points, point_ids, line = _read_nodes(f)
# MODIFIED jeffrey-cochran: persist counter
tmp_points, tmp_point_ids, line, counter = _read_nodes(f, counter=counter)

# MODIFIED jeffrey-cochran: persist points
points = tmp_points if points is None else np.concatenate((points, tmp_points), axis=0)

# MODIFIED jeffrey-cochran: persist point_ids
point_ids = tmp_point_ids if point_ids is None else {**point_ids, **tmp_point_ids}

elif keyword == "ELEMENT":
if point_ids is None:
raise ReadError("Expected NODE before ELEMENT")
Expand Down Expand Up @@ -228,10 +239,9 @@ def read_buffer(f):
)


def _read_nodes(f):
def _read_nodes(f, counter=None):
points = []
point_ids = {}
counter = 0
while True:
line = f.readline()
if not line or line.startswith("*"):
Expand All @@ -245,7 +255,7 @@ def _read_nodes(f):
points.append([float(x) for x in coords])
counter += 1

return np.array(points, dtype=float), point_ids, line
return np.array(points, dtype=float), point_ids, line, counter


def _read_cells(f, params_map, point_ids):
Expand Down