Package: meshio
I/O for mesh files.There are various mesh formats available for representing unstructured meshes.
meshio can read and write all of the following and smoothly converts between them:Abaqus(.inp),
ANSYS msh (.msh),AVS-UCD(.avs),CGNS(.cgns),DOLFIN XML(.xml),Exodus(.e,.exo),FLAC3D(.f3grid),H5M(.h5m),Kratos/MDPA(.mdpa),Medit(.mesh,.meshb),MED/Salome(.med),Nastran(bulk data,.bdf,.fem,.nas),Netgen(.vol,.vol.gz),Neuroglancer precomputed format,Gmsh(format versions 2.2, 4.0, and 4.1,.msh),OBJ(.obj),OFF(.off),PERMAS(.post,.post.gz,.dato,.dato.gz),PLY(.ply),STL(.stl),Tecplot .dat,TetGen .node/.ele,SVG(2D output only) (.svg),SU2(.su2),UGRID(.ugrid),VTK(.vtk),VTU(.vtu),WKT(TIN) (.wkt),XDMF(.xdmf,.xmf).(Here's a little surveyon which formats are actually
used.)Install with one ofpip install meshio[all]
conda install -c conda-forge meshio([all]pulls in all optional dependencies. By default, meshio only uses numpy.)
You can then use the command-line toolmeshioconvertinput.mshoutput.vtk# convert between two formatsmeshioinfoinput.xdmf# show some info about the meshmeshiocompressinput.vtu# compress the mesh filemeshiodecompressinput.vtu# decompress the mesh filemeshiobinaryinput.msh# convert to binary formatmeshioasciiinput.msh# convert to ASCII formatwith any of the supported formats.In Python, simply doimportmeshiomesh=meshio.read(filename,# string, os.PathLike, or a buffer/open file# file_format="stl",  # optional if filename is a path; inferred from extension# see meshio-convert -h for all possible formats)# mesh.points, mesh.cells, mesh.cells_dict, ...# mesh.vtk.read() is also possibleto read a mesh. To write, doimportmeshio# two triangles and one quadpoints=[[0.0,0.0],[1.0,0.0],[0.0,1.0],[1.0,1.0],[2.0,0.0],[2.0,1.0],]cells=[("triangle",[[0,1,2],[1,3,2]]),("quad",[[1,4,5,3]]),]mesh=meshio.Mesh(points,cells,# Optionally provide extra data on points, cells, etc.point_data={"T":[0.3,-1.2,0.5,0.7,0.0,-3.0]},# Each item in cell data must match the cells arraycell_data={"a":[[0.1,0.2],[0.4]]},)mesh.write("foo.vtk",# str, os.PathLike, or buffer/open file# file_format="vtk",  # optional if first argument is a path; inferred from extension)# Alternative with the same optionsmeshio.write_points_cells("foo.vtk",points,cells)For both input and output, you can optionally specify the exactfile_format(in case you would like to enforce ASCII over binary VTK, for example).Time seriesTheXDMF formatsupports
time series with a shared mesh. You can write times series data using meshio
withwithmeshio.xdmf.TimeSeriesWriter(filename)aswriter:writer.write_points_cells(points,cells)fortin[0.0,0.1,0.21]:writer.write_data(t,point_data={"phi":data})and read it withwithmeshio.xdmf.TimeSeriesReader(filename)asreader:points,cells=reader.read_points_cells()forkinrange(reader.num_steps):t,point_data,cell_data=reader.read_data(k)ParaView plugin*A Gmsh file opened with ParaView.*If you have downloaded a binary version of ParaView, you may proceed as follows.Install meshio for the Python major version that ParaView uses (checkpvpython --version)Open ParaViewFind the fileparaview-meshio-plugin.pyof your meshio installation (on Linux:~/.local/share/paraview-5.9/plugins/) and load it underTools / Manage Plugins / Load NewOptional:ActivateAuto LoadYou can now open all meshio-supported files in ParaView.Performance comparisonThe comparisons here are for a triangular mesh with about 900k points and 1.8M
triangles. The red lines mark the size of the mesh in memory.File sizesI/O speedMaximum memory usageInstallationmeshio isavailable from the Python Package Index,
so simply runpip install meshioto install.Additional dependencies (netcdf4,h5py) are required for some of the output formats
and can be pulled in bypip install meshio[all]You can also install meshio fromAnaconda:conda install -c conda-forge meshioTestingTo run the meshio unit tests, check out this repository and typetoxLicensemeshio is published under theMIT license.