Vtk_mesh for quadrilaterals plots as triangles

Plotting a quad mesh in pyvista produces a triangular mesh. A CG-1 space on a quad mesh properly shows a quad mesh, so it seems like this is in part hidden in dolfinx’s vtk_mesh implementation. Specifically, in the dispatched code for plotting meshes (and then the call to _cpp.io.extract_vtk_connectivity maybe?)

# dolfinx v0.9.0

from mpi4py import MPI
from dolfinx import mesh, fem, plot
import pyvista

domain = mesh.create_unit_square(MPI.COMM_WORLD, 10, 10, cell_type=mesh.CellType.quadrilateral)
CG1 = fem.functionspace(domain, ("Lagrange", 1, (domain.geometry.dim,)))
CG2 = fem.functionspace(domain, ("Lagrange", 2, (domain.geometry.dim,)))

def plot_mesh(plottable):
    plotter = pyvista.Plotter()
    grid = pyvista.UnstructuredGrid(*plot.vtk_mesh(plottable))
    plotter.add_mesh(grid, show_edges=True)
    plotter.show()

plot_mesh(domain) # Wrong
plot_mesh(CG1) # Correct
plot_mesh(CG2) # Wrong

Unfortunately CG-2 again renders as triangles, but that is somewhat understandable due to the added nodes. Is there anything I can do about this at this point?

This is a bug in pyvista that I reported years ago: VTK_LAGRANGE_HEXAHEDRON not supported with showing edges · Issue #947 · pyvista/pyvista · GitHub
hide internal edges of quadratic cells like ParaView · Issue #867 · pyvista/pyvista · GitHub
which I guess can be bypassed with
Step-by-step tutorial to hide internal edges of quadratic cells · pyvista/pyvista · Discussion #5777 · GitHub

1 Like

Awesome, thanks, I’ll try that