Boundary conditions for vector valued elements: how to use locate_dofs_topological?

Hi, I would like to apply a Dirichlet boundary condition on a function space of RT element. I followed the suggestions in this topic and visited the Mixed Poisson demo. Using these, I made the following code which does not work.

import numpy as np
from dolfinx import fem, mesh
from ufl import FiniteElement
from mpi4py import MPI
from petsc4py import PETSc


def boundary_top(x):
    return np.isclose(x[1], 1.0)

domain = mesh.create_unit_square(
    MPI.COMM_WORLD,
    32, 32,
    mesh.CellType.triangle
)

RT = FiniteElement("RT", domain.ufl_cell(), 1)
V = fem.FunctionSpace(domain, RT)

fdim = domain.topology.dim - 1
facets_top = mesh.locate_entities_boundary(domain, fdim, boundary_top)
dofs_top = fem.locate_dofs_topological(V, fdim, facets_top)

def f1(x):
    values = np.zeros((2, x.shape[1]))
    return values


f_h1 = fem.Function(V)
f_h1.interpolate(f1)
bc_top = fem.dirichletbc(f_h1, dofs_top, V)

The original code in the mixed Poisson demo does work for me, this modification does crashes with TypeError. I’d be grateful for any explanation how this should work or what is the logic behind. I checked other forum posts but they mostly deal with the situation where the function space is a subspace of mixed element and the solution there does not work for me.

Further investigation shows that the significant difference in my code snippet and Mixed Poisson demo is in the line responsible for the location of boundary condition dofs. The demo has the line as:

dofs_top = fem.locate_dofs_topological((V.sub(0), Q), fdim, facets_top)

Q is defined as V.sub(0).collapse()[0], V is a function space for a mixed element. I do not understand why is there the tuple of FunctionSpaces instead of only Q or porentionally V.sub(0).
I have not seen any other python demo file that would use locate_dofs_topological in this way.

In my example, if I change

dofs_top = fem.locate_dofs_topological(V, fdim, facets_top)

to

dofs_top = fem.locate_dofs_topological((V, V), fdim, facets_top)

I get a code that passes without error but I unfortunately do not know what exactly it does or should be doing.

Simply use: bc_top = fem.dirichletbc(f_h1, dofs_top)
as you do not need to map f_h1 to any function space (which is the case when you used collapesed sub spaces.