I have a question on how to apply Dirichlet condition in Dolfinx for a mixed finte element scheme.The problem is as follows:
The function space I defined is
Ve=ufl.VectorElement("CG",domain.ufl_cell(),2)
Pe=ufl.FiniteElement("CG",domain.ufl_cell(),1)
We=ufl.MixedElement([Ve,Pe])
W=fem.FunctionSpace(domain,We)
w=ufl.TrialFunction(W)
u,p=ufl.split(w)
where domain is a 2d unit square.Now I want to apply Dirichlet condition to u such that u = 0 on x=0,x=1 and y=0 while u=1 on y=1 .I implement this in this way:
def no_slip(x):
return np.logical_or(np.logical_or(np.isclose(x[0],0),np.isclose(x[0],1)),
np.isclose(x[1],0))
noslip_v=np.zeros(domain.geometry.dim,dtype=PETSc.ScalarType)
facets=mesh.locate_entities_boundary(domain,1,no_slip)
bc_noslip=fem.dirichletbc(noslip_v,fem.locate_dofs_topological(W.sub(0),1,facets),W.sub(0))
and it sends the error like
Invoked with: array([0., 0.]), array([ 0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 22, 23, 26, 27, 29, 30, 31,
32, 36, 37, 40, 41, 52, 53, 56, 57], dtype=int32), FunctionSpace(Mesh(VectorElement(FiniteElement('Lagrange', triangle, 1), dim=2), 0), VectorElement(FiniteElement('Lagrange', triangle, 2), dim=2))
RuntimeError: Creating a DirichletBC using a Constant is not supported when the Constant size is not equal to the block size of the constrained (sub-)space. Use a fem::Function to create the fem::DirichletBC.
I think noslip_v is dim =2 and W.sub(0) is also dim =2, so why do they not match?
And maybe one way to solve this is to use a Function used in dirichlebc() and how?But I wonder since dirichletbc() can accept a Constant in its first parameter, is there a way in which I can still use np.zeros as above in dirichletbc() without errors?(Constant in dirichletbc cannot work in MixedElement space?)