In my reply I should have defined the function spaces used in the problem. The code snippet from above should include the lines below before defining the boundary condition:
V = VectorFunctionSpace(mesh, 'P', 2)
Q = FunctionSpace(mesh, 'P', 1)
From your code snippet I see that you are using a mixed element formulation, which means W.sub(0) is 2D (i.e. velocity functions will be based there) and W.sub(1) is 1D.
To impose a specific value for the x component of the velocity for DirichletBC using mixed elements I would access the component as below:
from dolfin import *
from mshr import *
channel = Rectangle(Point(0,0), Point(2, 1))
mesh = generate_mesh(channel, 50)
# Boundaries
left= 'near(x[0], 0)'
right= 'near(x[0], 2)'
bottom = 'near(x[1], 0)'
top= 'near(x[1], 1)'
V = VectorElement("CG", triangle, 2)
Q = FiniteElement("CG", triangle, 1)
W = FunctionSpace(mesh, MixedElement([V, Q]))
noslip = DirichletBC(W.sub(0), Constant((0, 0)), top) # no-slip using mixed elements
# addressing a value for the y-component of velocity
symmetry = DirichletBC(W.sub(0).sub(1), Constant(0.0), bottom)
P_inlet = DirichletBC(W.sub(1), Constant(3.0), left)
P_outlet = DirichletBC(W.sub(1), Constant(0.0), right)
# Collect bcs for pressure-driven flow
bcu = [noslip , symmetry]
bcp = [P_inlet, P_outlet]
I hope I addressed your question. I am prone to errors (as everyone), so any suggestions are welcome!