How to convert Gmsh into Explicit Structured (or VTI) with VTK?

Hello,

I am trying to convert a Gmsh (unstructured) mesh into a structured grid (VTI).

Below is a part of a question that I asked on the PyVista slack forum (before I was granted access to VTK’s discourse forum). The code is based on https://kitware.github.io/vtk-examples/site/Python/ExplicitStructuredGrid/LoadESGrid/, https://kitware.github.io/vtk-examples/site/Python/ExplicitStructuredGrid/CreateESGrid/ and https://kitware.github.io/vtk-examples/site/Python/IO/ReadUnstructuredGrid/. I could not upload the .msh file

import meshio
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkFiltersCore import vtkUnstructuredGridToExplicitStructuredGrid
from vtkmodules.vtkIOXML import vtkXMLUnstructuredGridReader
from vtkmodules.vtkInteractionStyle import vtkInteractorStyleRubberBandPick
from vtkmodules.vtkRenderingCore import (
    vtkActor,
    vtkDataSetMapper,
    vtkRenderWindow,
    vtkRenderWindowInteractor,
    vtkRenderer
)
# exported with Gmsh as VTK, then:
meshio.read("mat_gmsh_simple_mesh.vtk").write("mat_gmsh_simple_mesh.vtu")
reader = vtkXMLUnstructuredGridReader()
reader.SetFileName("mat_gmsh_simple_mesh.vtu")
reader.Update()
#
converter = vtkUnstructuredGridToExplicitStructuredGrid()
# converter.GlobalWarningDisplayOff()  # hide VTK errors
converter.GlobalWarningDisplayOn()
converter.SetInputConnection(reader.GetOutputPort())
converter.SetInputArrayToProcess(0, 0, 0, 1, 'BLOCK_I')
converter.SetInputArrayToProcess(1, 0, 0, 1, 'BLOCK_J')
converter.SetInputArrayToProcess(2, 0, 0, 1, 'BLOCK_K')
converter.Update()
#
grid = converter.GetOutput()
grid.ComputeFacesConnectivityFlagsArray()

The error message is

(   6.617s) [        57842B80]vtkUnstructuredGridToEx:81     ERR| vtkUnstructuredGridToExplicitStructuredGrid (0x561812d759a0): An ijk array has not be set using SetInputArrayToProcess, aborting.
(   6.617s) [        57842B80]       vtkExecutive.cxx:752    ERR| vtkCompositeDataPipeline (0x5618130e26e0): Algorithm vtkUnstructuredGridToExplicitStructuredGrid(0x561812d759a0) returned failure for request: vtkInformation (0x5618130ec1c0)
  Debug: Off
  Modified Time: 556
  Reference Count: 1
  Registered Events: (none)
  Request: REQUEST_DATA
  FROM_OUTPUT_PORT: 0
  ALGORITHM_AFTER_FORWARD: 1
  FORWARD_DIRECTION: 0

Process Python segmentation fault (core dumped)

Running software:

VTK 9.1.0, Python 3.10.8, Meshio 5.3.4, Arch Linux

Your help and time are much appreciated. Thanks!

I got a solution with PyVista. Thanks!

For those who are interested, this may also help, but may involve converting the cell data into point data first.