Error with pyvista in new fenicsx version

Hello,

I am trying to run a fenicsx code from last year but the pyvista interface seems outdated. Here is the code I am running

import dolfinx 
import pyvista

L = 1. # total length
d = L/10. # thickness
h = d/6. # size of a cell

my_domain = dolfinx.mesh.create_rectangle(comm=MPI.COMM_WORLD,
                            points=((0.0, -0.5*d), (L, 0.5*d)), n=(int(L/h), int(d/h)),
                            cell_type=dolfinx.mesh.CellType.triangle)

topology, cell_types, geometry_for_plotting = dolfinx.plot.create_vtk_mesh(my_domain, 2)
grid = pyvista.UnstructuredGrid(topology, cell_types, geometry_for_plotting)

pyvista.set_jupyter_backend("none")
plotter = pyvista.Plotter()
plotter.add_mesh(grid, show_edges=True)

if not pyvista.OFF_SCREEN:
    plotter.show()
else:
    pyvista.start_xvfb()
    figure = plotter.screenshot("fundamentals_mesh.png")

I get the following error message:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[8], line 22
     19 plotter.add_mesh(grid, show_edges=True)
     21 if not pyvista.OFF_SCREEN:
---> 22     plotter.show()
     23 else:
     24     pyvista.start_xvfb()

File ~/anaconda3/envs/fenicsx-env/lib/python3.10/site-packages/pyvista/plotting/plotter.py:6673, in Plotter.show(self, title, window_size, interactive, auto_close, interactive_update, full_screen, screenshot, return_img, cpos, jupyter_backend, return_viewer, return_cpos, before_close_callback, **kwargs)
   6670     if jupyter_backend is None:
   6671         jupyter_backend = self._theme.jupyter_backend
-> 6673     if jupyter_backend.lower() != 'none':
   6674         jupyter_disp = handle_plotter(self, backend=jupyter_backend, **jupyter_kwargs)
   6676 self.render()

AttributeError: 'NoneType' object has no attribute 'lower'

Many thanks in advance for your help!

Claire

To me this seems like an issue with pyvista, as DOLFINx only provides pure numpy arrays to pyvista to generate an unstructured grid, and does not modify wrap any pyvista code. Can you try using a simple unstructured mesh like:

cells = [4, 0, 1, 2, 3]
celltypes = [pyvista.CellType.TETRA]
points = [
    [1.0, 1.0, 1.0],
    [1.0, -1.0, -1.0],
    [-1.0, 1.0, -1.0],
    [-1.0, -1.0, 1.0],
]
grid = pyvista.UnstructuredGrid(cells, celltypes, points)
grid.plot(show_edges=True)

from
https://docs.pyvista.org/version/stable/api/core/_autosummary/pyvista.UnstructuredGrid.html#pyvista.UnstructuredGrid

Yes this works! I just get a warning message.

hwloc/linux: Ignoring PCI device with non-16bit domain.
Pass --enable-32bits-pci-domain to configure to support such devices
(warning: it would break the library ABI, don't enable unless really needed).
WARNING:py.warnings:/home/claire/anaconda3/envs/fenicsx-env/lib/python3.10/site-packages/pyvista/jupyter/notebook.py:58: UserWarning: Failed to use notebook backend: 

No module named 'trame'

Falling back to a static output.
  warnings.warn(

That is very strange, as the pyvista unstructured grid from dolfinx is made in the exact same way.

This works:

import dolfinx 
import pyvista
from mpi4py import MPI


L = 1. # total length
d = L/10. # thickness
h = d/6. # size of a cell

my_domain = dolfinx.mesh.create_rectangle(comm=MPI.COMM_WORLD,
                            points=((0.0, -0.5*d), (L, 0.5*d)), n=(int(L/h), int(d/h)),
                            cell_type=dolfinx.mesh.CellType.triangle)

topology, cell_types, geometry_for_plotting = dolfinx.plot.create_vtk_mesh(my_domain, 2)
grid = pyvista.UnstructuredGrid(topology, cell_types, geometry_for_plotting)
grid.plot(show_edges=True)

This doesn’t:

import dolfinx 
import pyvista
from mpi4py import MPI


L = 1. # total length
d = L/10. # thickness
h = d/6. # size of a cell

my_domain = dolfinx.mesh.create_rectangle(comm=MPI.COMM_WORLD,
                            points=((0.0, -0.5*d), (L, 0.5*d)), n=(int(L/h), int(d/h)),
                            cell_type=dolfinx.mesh.CellType.triangle)

topology, cell_types, geometry_for_plotting = dolfinx.plot.create_vtk_mesh(my_domain, 2)
grid = pyvista.UnstructuredGrid(topology, cell_types, geometry_for_plotting)

pyvista.set_jupyter_backend("none")

plotter = pyvista.Plotter()
plotter.add_mesh(grid, show_edges=True)

if not pyvista.OFF_SCREEN:
    plotter.show()
else:
    pyvista.start_xvfb()
    figure = plotter.screenshot("fundamentals_mesh.png")

This works:

import dolfinx 
import pyvista
from mpi4py import MPI


L = 1. # total length
d = L/10. # thickness
h = d/6. # size of a cell

my_domain = dolfinx.mesh.create_rectangle(comm=MPI.COMM_WORLD,
                            points=((0.0, -0.5*d), (L, 0.5*d)), n=(int(L/h), int(d/h)),
                            cell_type=dolfinx.mesh.CellType.triangle)

topology, cell_types, geometry_for_plotting = dolfinx.plot.create_vtk_mesh(my_domain, 2)
grid = pyvista.UnstructuredGrid(topology, cell_types, geometry_for_plotting)

plotter = pyvista.Plotter()
plotter.add_mesh(grid, show_edges=True)
plotter.show()

As you can see, it has nothing to do with dolfinx, but how you interact with pyvista.

2 Likes