Plot of quadrilateral mesh shows triangles

I’m running fenics 0.11, downloaded via conda, on macOS 13.7.7.

To familiarise myself with fenics, I’ve been editing the example in Chapter 1 of the tutorial. I changed the cell type to quadrilateral, but still see a mesh plot of triangles. Unfortunately, it seems I’m not allowed to upload a picture, but the code is pasted below. It includes some debugging lines which seem to show that the mesh is indeed quadrilateral in its numerical representation. The original is in a Jupyter notebook, which I can provide if the exported markdown is unsatisfactory.

from mpi4py import MPI
from dolfinx import mesh
import numpy as np

#  Mesh parameters
Lx = 1.9
Ly = 1.3
nx = 3
ny = 2

domain = mesh.create_rectangle(MPI.COMM_WORLD, [np.array([0,0]), np.array([Lx,Ly])], [nx,ny], mesh.CellType.quadrilateral)
tdim = domain.topology.dim  # Hijacked from further down to provide for earlier mesh plot

import pyvista

from dolfinx import plot

domain.topology.create_connectivity(tdim, tdim)
topology, cell_types, geometry = plot.vtk_mesh(domain, tdim)
grid = pyvista.UnstructuredGrid(topology, cell_types, geometry)
mesh_edges = grid.extract_all_edges()
print(mesh_edges.lines)
[ 2  0  1  2  0  2  2  1  3  2  1  4  2  2  3  2  2  6  2  3  5  2  3  7
  2  4  5  2  5  8  2  6  7  2  6  9  2  7  8  2  7 10  2  8 11  2  9 10
  2 10 11]
plotter = pyvista.Plotter()
plotter.add_mesh(grid, show_edges=True)
plotter.view_xy()
if not pyvista.OFF_SCREEN:
    plotter.show()
else:
    figure = plotter.screenshot("fundamentals_mesh.png")
/var/folders/d0/qs348d8c8xl6pv006s6nj_hh0000gn/T/ipykernel_40314/2210393252.py:5: UserWarning: Using static image for notebook display.
Install trame for interactive backends: pip install "pyvista[jupyter]"
  plotter.show()
cell_types
array([70, 70, 70, 70, 70, 70])
topology
print(topology[0:20])
[4 0 1 3 2 4 1 4 5 3 4 2 3 7 6 4 3 5 8 7]
geometry
array([[0.        , 0.        , 0.        ],
       [0.        , 0.65      , 0.        ],
       [0.63333333, 0.        , 0.        ],
       [0.63333333, 0.65      , 0.        ],
       [0.        , 1.3       , 0.        ],
       [0.63333333, 1.3       , 0.        ],
       [1.26666667, 0.        , 0.        ],
       [1.26666667, 0.65      , 0.        ],
       [1.26666667, 1.3       , 0.        ],
       [1.9       , 0.        , 0.        ],
       [1.9       , 0.65      , 0.        ],
       [1.9       , 1.3       , 0.        ]])

Hi, this may be related to the bug discussed here:

If so, a quick workaround seems to be going via a CG1 space, replacing

topology, cell_types, geometry = plot.vtk_mesh(domain, tdim)

with

CG1 = dolfinx.fem.functionspace(domain, ("CG", 1))
topology, cell_types, geometry = plot.vtk_mesh(CG1)

<shameless self-promotion>

Your code can be simplified to just a few lines with pyvista4dolfinx ( Pyvista for dolfinx — pyvista for dolfinx documentation ), which incorporates the correct rendering mentioned by @ingvildsd:

from mpi4py import MPI
from dolfinx import mesh
import numpy as np

#  Mesh parameters
Lx = 1.9
Ly = 1.3
nx = 3
ny = 2

domain = mesh.create_rectangle(MPI.COMM_WORLD, [np.array([0,0]), np.array([Lx,Ly])], [nx,ny], mesh.CellType.quadrilateral)

import pyvista4dolfinx as p4d
p4d.plot(domain, show=True)

</shameless self-promotion>

Thanks; that works!
Hearts to reach character target as recommended …

Many thanks - that works nicely.

Unfortunately it seems I can’t tag a second solution …