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

tools/paraview_meshio_plugin made working with the latest meshio #1423

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 5 additions & 4 deletions tools/paraview-meshio-plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down