Hello,
I am using the Jupyterlab docker image (tried both the stable and nightly builds) to run FEniCSx and when I try to plot the mesh with pyvista, the widget instead shows an “Unable to connect” tab. I tried running the following according to this other post :
!python3 -m pip install --no-cache-dir pyvista[trame] -U
But when I run my script, this is what I see:
from mpi4py import MPI
from dolfinx import fem, io, nls, log, mesh, plot, cpp, plot
import numpy as np
import ufl
from petsc4py.PETSc import ScalarType
import pyvista
# create simple rectangular mesh
points = [[0.0, 0.0], [1.0, 1.0]]
domain = mesh.create_rectangle(MPI.COMM_WORLD, points, [10 , 10])
P1 = ufl.FiniteElement('CG', domain.ufl_cell(), 1)
element = ufl.MixedElement([P1, P1])
V = fem.FunctionSpace(domain, element)
# attempt to plot mesh with pyvista
pyvista.start_xvfb()
topology, cell_types, geometry = plot.create_vtk_mesh(domain, domain.topology.dim)
grid = pyvista.UnstructuredGrid(topology, cell_types, geometry)
plotter = pyvista.Plotter()
plotter.add_mesh(grid, show_edges=True)
plotter.show()
1 Like
Hello to the community, I do not answer to provide a solution but to add information on the error. I have the same issues as mentioned before, especially about the ‘localhost refused to connect’ occurrence in the jupyter lab environment.
If we execute :
from mpi4py import MPI
from dolfinx import fem, io, nls, log, mesh, plot, cpp, plot
import numpy as np
import ufl
from petsc4py.PETSc import ScalarType
import pyvista
# create simple rectangular mesh
points = [[0.0, 0.0], [1.0, 1.0]]
domain = mesh.create_rectangle(MPI.COMM_WORLD, points, [10 , 10])
P1 = ufl.FiniteElement('CG', domain.ufl_cell(), 1)
element = ufl.MixedElement([P1, P1])
V = fem.FunctionSpace(domain, element)
# attempt to plot mesh with pyvista
pyvista.start_xvfb()
topology, cell_types, geometry = plot.create_vtk_mesh(domain, domain.topology.dim)
grid = pyvista.UnstructuredGrid(topology, cell_types, geometry)
plotter = pyvista.Plotter()
plotter.add_mesh(grid, show_edges=True)
plotter.show()
We indeed obtain the window with ‘localhost refused to connect’. But if we change the
plotter.show()
to
plotter.show(jupyter_backend=‘panel’)
We obtain a static image of the desired mesh, which is still not what we want I guess…
dokken
October 24, 2023, 1:39pm
3
This is a pure pyvista
-“issue”, in the sense that you need to use the correct configuration for pyvista.
See for instance: Using PyVista in Jupyter — PyVista Tutorial
2 Likes