Extra facets are inadvertently selected when combining faces in locate_entities_boundary (indepedent of element type), and subsequently extra dofs in locate_dofs_topological (on e.g. 3D BDM (N2F) elements, but not e.g. 3D P elements). Separating them out into seperate boundary conditions results in consistency with dolfin.
from ufl import *
from dolfinx import *
import numpy as np
from mpi4py import MPI
from slepc4py import SLEPc
mesh=UnitCubeMesh(MPI.COMM_WORLD,1,1,1)
BDM=FiniteElement("BDM",mesh.ufl_cell(),1)
W=FunctionSpace(mesh,BDM)
def noslip_boundary(x): return np.isclose(x[0],0.0)
facdim=2
facets=dolfinx.mesh.locate_entities_boundary(mesh,facdim,noslip_boundary)
print(facets)
dofs=dolfinx.fem.locate_dofs_topological(W,facdim,facets)
print(dofs)
bc0=DirichletBC(Function(W),dofs)
def noslip_boundary(x): return np.isclose(x[1],1.0)
facets=dolfinx.mesh.locate_entities_boundary(mesh,facdim,noslip_boundary)
print(facets)
dofs=dolfinx.fem.locate_dofs_topological(W,facdim,facets)
print(dofs)
bc1=DirichletBC(Function(W),dofs)
def noslip_boundary(x): return np.logical_or(np.isclose(x[0],0.0),np.isclose(x[1],1.0))
facets=dolfinx.mesh.locate_entities_boundary(mesh,facdim,noslip_boundary)
print(facets)
dofs=dolfinx.fem.locate_dofs_topological(W,facdim,facets)
print(dofs)
bc=DirichletBC(Function(W),dofs)
us=TrialFunction(W)
vs=TestFunction(W)
a=inner(us,vs)*dx
A = dolfinx.fem.assemble_matrix(a,[bc])
A.assemble()
eigensolver = SLEPc.EPS().create(MPI.COMM_WORLD)
eigensolver.setOperators(A)
eigensolver.solve()
vr, vi = A.createVecs()
l = eigensolver.getEigenpair(0 ,vr, vi)
print(l.real)
A = dolfinx.fem.assemble_matrix(a,[bc0,bc1])
A.assemble()
eigensolver = SLEPc.EPS().create(MPI.COMM_WORLD)
eigensolver.setOperators(A)
eigensolver.solve()
vr, vi = A.createVecs()
l = eigensolver.getEigenpair(0 ,vr, vi)
print(l.real)
Results (just printing facets and dofs)
[8 4]
[[ 0]
[ 1]
[ 2]
[21]
[22]
[23]]
[15 14]
[[27]
[28]
[29]
[42]
[43]
[44]]
[15 8 17 4 3 14] <- facets 17 and 3 are also inadvertently selected
[[ 0]
[ 1]
[ 2]
[ 9] <- extra dof selected
[10] <- extra dof selected
[11] <- extra dof selected
[21]
[22]
[23]
[27] <- extra dof selected
[28] <- extra dof selected
[29] <- extra dof selected
[37]
[38]
[39]
[42]
[43]
[44]]
1.7746788776946878 (eigenvalue trivial system doing everything in one go w.r.t. boundary condtion bc)
1.8034741465722868 (eigenvalue trivial system separating out boundary conditions bc0 and bc1)
(This does not happen on all adjacent faces)
Just following the Stokes equations with Taylor-Hood elements demo here with respect to the boundary conditions.
Versioning: latest kali linux with apt get fenics fenicx + latest git ffcx and dolfinx (3 days ago)