Skip to content

Commit

Permalink
fix for mesh.prune()
Browse files Browse the repository at this point in the history
  • Loading branch information
nschloe committed Jun 11, 2018
1 parent 8dd5ee5 commit f5eda96
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions meshio/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ def prune(self):
self.cells.pop("triangle", None)
# remove_orphaned_nodes.
# find which nodes are not mentioned in the cells and remove them
flat_cells = self.cells["tetra"].flatten()
orphaned_nodes = numpy.setdiff1d(numpy.arange(len(self.points)), flat_cells)
all_cells_flat = numpy.concatenate(
[vals for vals in self.cells.values()]
).flatten()
orphaned_nodes = numpy.setdiff1d(numpy.arange(len(self.points)), all_cells_flat)
self.points = numpy.delete(self.points, orphaned_nodes, axis=0)
# also adapt the point data
for key in self.point_data:
Expand All @@ -52,9 +54,14 @@ def prune(self):
self.point_data["GLOBAL_ID"] = numpy.arange(1, len(self.points) + 1)

# We now need to adapt the cells too.
diff = numpy.zeros(len(flat_cells), dtype=flat_cells.dtype)
diff = numpy.zeros(len(all_cells_flat), dtype=all_cells_flat.dtype)
for orphan in orphaned_nodes:
diff[numpy.argwhere(flat_cells > orphan)] += 1
flat_cells -= diff
self.cells["tetra"] = flat_cells.reshape(self.cells["tetra"].shape)
diff[numpy.argwhere(all_cells_flat > orphan)] += 1
all_cells_flat -= diff
k = 0
for key in self.cells:
s = self.cells[key].shape
n = numpy.prod(s)
self.cells[key] = all_cells_flat[k : k + n].reshape(s)
k += n
return

0 comments on commit f5eda96

Please sign in to comment.