I try to use Dolfinx in docker to run codes.However, when I try to plot them using Pyvista, I encounter the error
X Error of failed request: BadShmSeg (invalid shared segment parameter)
Major opcode of failed request: 130 (MIT-SHM)
Minor opcode of failed request: 3 (X_ShmPutImage)
Segment id in failed request: 0x600005
Serial number of failed request: 67
Current serial number in output stream: 68
and I don’t know why. If I delete the part involving Pyvista, the code runs well and I also try other codes written before and they can be compiled well.So maybe something wrong with the codes when I use pyvista. I am new to docker too, so I don’t know whether the error is from docker or pyvista.
Please help me with it. Thanks in advance!
The code is given below
from dolfinx import mesh, fem,plot,io
from functools import partial
from ufl import (inner, dot, div, grad,
TrialFunction, TestFunction, dx,ds,FacetNormal,
CellDiameter, min_value, sqrt, lhs, rhs, SpatialCoordinate, exp,Measure
)
from mpi4py import MPI
from petsc4py import PETSc
import numpy as np
Nx=20
Ny=20
k=1
domain=mesh.create_unit_square(MPI.COMM_WORLD,Nx,Ny)
V=fem.FunctionSpace(domain,("CG",k))
f=fem.Constant(domain,PETSc.ScalarType(0))
a=fem.Constant(domain,np.array([np.cos(np.arctan(1)),np.sin(np.arctan(1))],dtype=PETSc.ScalarType))
kappa=fem.Constant(domain,PETSc.ScalarType(1e-6))
boundary_zero=fem.Constant(domain,PETSc.ScalarType(0))
boundary_one=fem.Constant(domain,PETSc.ScalarType(1))
boundaries=[(1,lambda x:np.logical_and(np.isclose(x[0],0),np.logical_and(x[1]>0.2-1e-16,x[1]<=1))),
(2,lambda x:np.logical_and(np.isclose(x[0],0),np.logical_and(x[1]<0.2+1e-16,x[1]>=0))),
(3,lambda x:np.isclose(x[1],0)),
(4,lambda x:np.isclose(x[0],1)),
(5,lambda x:np.isclose(x[1],1))]
facet_indices,facet_markers=[],[]
fdim=domain.topology.dim-1
for (marker,locator) in boundaries:
facets=mesh.locate_entities(domain,fdim,locator)
facet_indices.append(facets)
facet_markers.append(np.full_like(facets,marker))
facets_indices=np.hstack(facet_indices).astype(np.int32)
facets_markers=np.hstack(facet_markers).astype(np.int32)
sorted_facets=np.argsort(facets_indices)
facet_tag=mesh.meshtags(domain,fdim,facets_indices[sorted_facets],facets_markers[sorted_facets])
u=TrialFunction(V)
v=TestFunction(V)
h=CellDiameter(domain)
tau=h/2
facet_zero=np.hstack([facet_tag.find(1),facet_tag.find(4),facet_tag.find(5)])
dofs_zero = fem.locate_dofs_topological(V, fdim, facet_zero)
bcd0=fem.dirichletbc(boundary_zero,dofs_zero,V)
facet_one=np.hstack([facet_tag.find(2),facet_tag.find(3)])
dofs_one = fem.locate_dofs_topological(V, fdim, facet_one)
bcd1=fem.dirichletbc(boundary_one,dofs_one,V)
bcd=[bcd0,bcd1]
A=dot(a,grad(u))*v*dx+kappa*dot(grad(u),grad(v))*dx+ \
tau*(-kappa*div(grad(u))+dot(a,grad(u)))*(dot(a,grad(v))+kappa*div(grad(v)))*dx
L=f*v*dx+f*tau*(dot(a,grad(v))+kappa*div(grad(v)))*dx
problem=fem.petsc.LinearProblem(A,L,bcs=bcd)
uh=fem.Function(V)
uh=problem.solve()
import pyvista as pv
plotter=pv.Plotter()
grid=pv.UnstructuredGrid(*plot.create_vtk_mesh(V))
grid.point_data["uh"]=uh.x.array
grid.set_active_scalars("uh")
warped = grid.warp_by_scalar("uh", factor=0.1)
plotter.add_mesh(warped,show_edges=True)
plotter.view_xy()
plotter.show()