From 969adaca18de367a99769630f125c6da710b217a Mon Sep 17 00:00:00 2001 From: Ilshat Saifullin Date: Thu, 20 Jul 2023 22:00:11 +0200 Subject: [PATCH 1/2] I found the code doesn't work with the latest meshio. With this commit the error "TypeError: cannot unpack non-iterable CellBlock object" for the line "for meshio_type, data in cells:" fixed. Example of "cells": [, ] "cells_dict": {'triangle': array([[0, 1, 2], [1, 3, 2]]), 'quad': array([[1, 4, 5, 3]])} --- tools/paraview-meshio-plugin.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/paraview-meshio-plugin.py b/tools/paraview-meshio-plugin.py index a4f2813f8..1bf2a34ea 100644 --- a/tools/paraview-meshio-plugin.py +++ b/tools/paraview-meshio-plugin.py @@ -71,7 +71,7 @@ def RequestData(self, request, inInfoVec, outInfoVec): # Use meshio to read the mesh mesh = meshio.read(self._filename, self._file_format) - points, cells = mesh.points, mesh.cells + points, cells, cells_dict = mesh.points, mesh.cells, mesh.cells_dict # Points if points.shape[1] == 2: @@ -82,16 +82,17 @@ def RequestData(self, request, inInfoVec, outInfoVec): cell_types = np.array([], dtype=np.ubyte) cell_offsets = np.array([], dtype=int) cell_conn = np.array([], dtype=int) - for meshio_type, data in cells: + for meshio_type in cells_dict.keys(): # loop over cell types vtk_type = meshio_to_vtk_type[meshio_type] - ncells, npoints = data.shape + ncells = cells_dict[meshio_type].shape[0] + npoints = cells_dict[meshio_type][0].size # for one cell cell_types = np.hstack( [cell_types, np.full(ncells, vtk_type, dtype=np.ubyte)] ) offsets = len(cell_conn) + (1 + npoints) * np.arange(ncells, dtype=int) cell_offsets = np.hstack([cell_offsets, offsets]) conn = np.hstack( - [npoints * np.ones((ncells, 1), dtype=int), data] + [npoints * np.ones((ncells, 1), dtype=int), cells_dict[meshio_type]] ).flatten() cell_conn = np.hstack([cell_conn, conn]) output.SetCells(cell_types, cell_offsets, cell_conn) From 5c9611c0da29de847ecebd630a8f3fb9c1b3b0e0 Mon Sep 17 00:00:00 2001 From: Ilshat Saifullin Date: Thu, 20 Jul 2023 22:36:54 +0200 Subject: [PATCH 2/2] Instruction to paraview plugin updated. "rich" module used in Paraview Load plugin and it doesn't load new plugin with it. Ideally, Paraview should deliver it with itself. --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 097456527..35ba61605 100644 --- a/README.md +++ b/README.md @@ -171,10 +171,11 @@ with meshio.xdmf.TimeSeriesReader(filename) as reader: If you have downloaded a binary version of ParaView, you may proceed as follows. -- Install meshio for the Python major version that ParaView uses (check `pvpython --version`) +- Install `meshio` and `rich` modules for the Python major version that ParaView uses (check `pvpython --version` from `paraview/bin`). +Then copy `meshio` and `rich` directories from your Python directory `PYTHONPATH/Lib/site-packages/meshio` to `paraview/bin/Lib/site-packages`. - Open ParaView - Find the file `paraview-meshio-plugin.py` of your meshio installation (on Linux: - `~/.local/share/paraview-5.9/plugins/`) and load it under _Tools / Manage Plugins / Load New_ + `~/.local/share/paraview-5.9/plugins/`, on Windows: `PYTHONPATH\share\paraview-5.9\plugins\`) and load it under _Tools / Manage Plugins / Load New_ - _Optional:_ Activate _Auto Load_ You can now open all meshio-supported files in ParaView.