From ef133f6be452afded9e9179b025dd661674ccd31 Mon Sep 17 00:00:00 2001 From: Keurfon Luu Date: Mon, 6 Dec 2021 18:10:20 -0800 Subject: [PATCH] fix removing lower order cells when mesh is dict --- toughio/_mesh/_helpers.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/toughio/_mesh/_helpers.py b/toughio/_mesh/_helpers.py index b5c9c30c..c3772858 100644 --- a/toughio/_mesh/_helpers.py +++ b/toughio/_mesh/_helpers.py @@ -104,24 +104,25 @@ def read(filename, file_format=None, **kwargs): mesh = from_meshio(mesh) # Remove lower order cells - idx = np.ones(len(mesh.cells), dtype=bool) + if not isinstance(mesh, dict): + idx = np.ones(len(mesh.cells), dtype=bool) - celltypes = np.array([cell.type for cell in mesh.cells]) - cell_data = {k: mesh.split(v) for k, v in mesh.cell_data.items()} + celltypes = np.array([cell.type for cell in mesh.cells]) + cell_data = {k: mesh.split(v) for k, v in mesh.cell_data.items()} - idx = np.logical_and(idx, celltypes != "vertex") - idx = np.logical_and(idx, celltypes != "line") + idx = np.logical_and(idx, celltypes != "vertex") + idx = np.logical_and(idx, celltypes != "line") - if mesh.dim == 3: - idx = np.logical_and(idx, celltypes != "quad") - idx = np.logical_and(idx, celltypes != "triangle") + if mesh.dim == 3: + idx = np.logical_and(idx, celltypes != "quad") + idx = np.logical_and(idx, celltypes != "triangle") - if idx.sum() < len(mesh.cells): - mesh.cells = [cell for keep, cell in zip(idx, mesh.cells) if keep] - for k, v in cell_data.items(): - mesh.cell_data[k] = np.concatenate([vv for keep, vv in zip(idx, v) if keep]) + if idx.sum() < len(mesh.cells): + mesh.cells = [cell for keep, cell in zip(idx, mesh.cells) if keep] + for k, v in cell_data.items(): + mesh.cell_data[k] = np.concatenate([vv for keep, vv in zip(idx, v) if keep]) - mesh.prune_duplicates() + mesh.prune_duplicates() return mesh