Xiang,
Adding to Bruno's response: If the interface you want to apply Dirichlet boundary conditions to stays the same through the whole simulation, then treating the corresponding faces as disjoint while creating your mesh might be a better option.
Setting constraints yourself requires you to know how the degrees of freedom map to function values (which depends on the finite element you are using). FE_Q elements are nodal, though, so you can simply constrain the degrees of freedom to the desired function value at the corresponding support points.
Best,
Daniel