DirichletBC suppress on some dofs

Hi,

I am trying to apply the DirichletBC on the top side of mesh except two y dofs of left-top and right-top vertices as shown in figure.


I think I can use the pointwise method, but the definition of subdomains of points and DirichletBCs would be complex and inefficient.

import fenics as fe
mesh = fe.UnitSquareMesh(2,2)
V = fe.VectorFunctionSpace(mesh, 'P', 1)
u = fe.Function(V)
bc1 = fe.DirichletBC(V.sub(0), u, subdomain_all_points_on_top, method='pointwise')
bc1 = fe.DirichletBC(V.sub(1), u, subdomain_all_points_on_top_except_left_right_corner, method='pointwise')
bc = [bc1, bc2]

Is there a way to assign DirichletBC based on dof like the way of assigning nodal force?
Or is it possible to suppress the assigning of DirichletBC values on these dofs?

Thanks,
Ming

You should be able to do this by just setting different geometric criteria for the two BCs:

import fenics as fe
mesh = fe.UnitSquareMesh(8,8)
V = fe.VectorFunctionSpace(mesh, 'P', 1)
u = fe.Function(V)

# Define geometric criteria for BCs on different components:
on_top =  " && x[1] > 1.0-DOLFIN_EPS"
subdomain_all_points_on_top = "x[0]>-DOLFIN_EPS"+on_top
subdomain_all_points_on_top_except_left_right_corner \
    = "x[0] > DOLFIN_EPS && x[0] < 1.0-DOLFIN_EPS"+on_top

# Set BCs according to components of u (rather than the full vector u,
# as in the original MWE):
u0,u1 = u.split(deepcopy=False)
bc1 = fe.DirichletBC(V.sub(0), u0,
                     subdomain_all_points_on_top, method='pointwise')
bc2 = fe.DirichletBC(V.sub(1), u1,
                     subdomain_all_points_on_top_except_left_right_corner,
                     method='pointwise')
bc = [bc1, bc2]

# Demonstrate:
utest = fe.Function(V)
utest.interpolate(fe.Constant((1,1)))
u.interpolate(fe.Constant((2,3)))
for b in bc:
    b.apply(utest.vector())
from matplotlib import pyplot as plt
utest0,utest1 = utest.split()
plt.figure()
fe.plot(utest0)
fe.plot(mesh)
plt.figure()
fe.plot(utest1)
fe.plot(mesh)
plt.show()