Dirichlet boundary of DG/RT/N1curl element?

A DG element does not have any dofs associated with its, facets, thus, locate_dofs_topological will always be empty.
A dof is associated with a facet would mean that the degree of freedom is shared with all other cells that has this facet. If you instead use locate_dofs_geometrical:

import numpy as np
import ufl
from dolfinx import fem
from dolfinx.fem import (Function, dirichletbc,
                         locate_dofs_geometrical)
from dolfinx.mesh import (CellType, GhostMode, create_unit_cube)
from mpi4py import MPI
from dolfinx.fem.petsc import (set_bc)
import ufl
from petsc4py import PETSc as _PETSc

msh = create_unit_cube(MPI.COMM_WORLD,
                       1, 1, 1,
                       CellType.tetrahedron, ghost_mode=GhostMode.none)

u_element = ufl.VectorElement("DG", ufl.tetrahedron, 1)
A_element = ufl.FiniteElement("N1curl", ufl.tetrahedron, 1)
P_element = ufl.FiniteElement("DG", ufl.tetrahedron, 0)

TH = ufl.MixedElement([u_element, A_element, P_element])
W = fem.FunctionSpace(msh, TH)

W0, map0 = W.sub(0).collapse()
W1, map1 = W.sub(1).collapse()
W2, map2 = W.sub(2).collapse()


def local_u(x):
    return np.isclose(x[1], 0)


def u_D(x):
    values = np.zeros_like(x, dtype=_PETSc.ScalarType)
    values[0, :] = 1
    values[1, :] = 2
    values[2, :] = 3
    return values


u_boundary = Function(W0)
u_boundary.interpolate(u_D)
dofs = locate_dofs_geometrical((W.sub(0), W0), local_u)
bc0 = dirichletbc(u_boundary, dofs, W.sub(0))

bcs = [bc0]
un = Function(W)
print(f'un initial is {un.x.array}')
set_bc(un.vector, bcs)
print(f'un last is {un.x.array}')
print(f'{dofs=}')

2 Likes