Skip to content

Commit

Permalink
Merge pull request #1240 from nschloe/warn-flac
Browse files Browse the repository at this point in the history
add warning for flac
  • Loading branch information
nschloe authored Dec 18, 2021
2 parents 51d30fb + 58c567e commit b019c68
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/meshio/_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,10 @@ def sets_to_int_data(self):
intfun.append(arr)

for item in intfun:
if np.any(item == default_value):
num_default = np.sum(item == default_value)
if num_default > 0:
warnings.warn(
"Not all cells are part of a cell set. "
f"{num_default} cells are not part of any cell set. "
f"Using default value {default_value}."
)
break
Expand Down
19 changes: 15 additions & 4 deletions src/meshio/flac3d/_flac3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import struct
import time
from warnings import warn

import numpy as np

Expand Down Expand Up @@ -112,6 +113,7 @@ def read_buffer(f, binary):
point_ids = {}
cells = []
cell_sets = {}
cell_ids = []

pidx = 0
if binary:
Expand All @@ -128,7 +130,8 @@ def read_buffer(f, binary):
for flag in ["zone", "face"]:
(num_cells,) = struct.unpack("<I", f.read(4))
for _ in range(num_cells):
_, cell = _read_cell_binary(f, point_ids)
cell_id, cell = _read_cell_binary(f, point_ids)
cell_ids.append(cell_id)
_update_cells(cells, cell, flag)
# mapper[flag][cid] = [cidx]
# cidx += 1
Expand All @@ -147,15 +150,17 @@ def read_buffer(f, binary):
pidx += 1
elif line[0] in {"Z", "F"}:
flag = zone_or_face[line[0]]
_, cell = _read_cell_ascii(line, point_ids)
cell_id, cell = _read_cell_ascii(line, point_ids)
cell_ids.append(cell_id)
_update_cells(cells, cell, flag)
# mapper[flag][cid] = [cidx]
# cidx += 1
elif line[0] in {"ZGROUP", "FGROUP"}:
flag = zone_or_face[line[0][0]]
name, slot, data = _read_cell_group_ascii(f, line)
# flac data is 1-based
cell_sets[f"{flag}:{name}:{slot}"] = np.array(data) - 1
# Watch out! data refers to the glocal cell_ids, so we need to
# adapt this later.
cell_sets[f"{flag}:{name}:{slot}"] = np.asarray(data)

line = f.readline().rstrip().split()

Expand All @@ -164,6 +169,12 @@ def read_buffer(f, binary):
for key, indices in cells
]

if len(cell_sets) > 0:
# Can only deal with sequential cell_ids for now. If the order is messed
# up, or if some indices are missing, cell_sets will be wrong.
if not np.all(np.arange(cell_ids[0], cell_ids[-1] + 1) == cell_ids):
warn("FLAC3D cell IDs not sequential. Cell sets probably messed up.")

# cell_sets contains the indices into the global cell list. Since this is
# split up into blocks, we need to split the cell_sets, too.
bins = np.cumsum([len(cb[1]) for cb in cell_blocks])
Expand Down

0 comments on commit b019c68

Please sign in to comment.