Hello,
I would like to figure out how to set multiple Dirichlet boundary conditions for a mixed functionspace in dolfinx. I have been trying a few different approaches, but nothing quite worked.
I am trying to solve a system of equations and I build the functionspace like so
from dolfinx import mesh, fem
from basix.ufl import element, mixed_element
... everything mesh related...
domain = mesh.create_mesh(comm, cells=cells, x=x_array, e=cell_type)
P = element("P", domain.basix_cell(), 1)
ME = fem.functionspace(domain, mixed_element([P] * 4))
U = fem.Function(ME)
H0, H1, H2, H3 = ufl.split(U)
Now I would like to set a few Dirichlet conditions.
Specifically I would like to set H0 = H1 = H3 = 0 at (x=L) and H2 = 0 at (x~0).
I tried setting them like so, is that correct?
def boundary_left_marker(x):
return np.isclose(x[0], 0.0)
def boundary_right_marker(x):
return np.isclose(x[0], L)
U0 = U.sub(0).collapse().function_space
U1 = U.sub(1).collapse().function_space
U2 = U.sub(2).collapse().function_space
U3 = U.sub(3).collapse().function_space
C_zero = fem.Constant(domain, 0.0)
bc_right1 = fem.dirichletbc(C_zero, fem.locate_dofs_geometrical(U0, boundary_right_marker), U0)
bc_right2 = fem.dirichletbc(C_zero, fem.locate_dofs_geometrical(U1, boundary_right_marker), U1)
bc_right4 = fem.dirichletbc(C_zero, fem.locate_dofs_geometrical(U3, boundary_right_marker), U3)
bc_left3 = fem.dirichletbc(C_zero, fem.locate_dofs_geometrical(U2, boundary_left_marker), U2)
bc = [bc_right1, bc_right2, bc_right4, bc_left3]
I am later solving for H0, H1, H2, H3.
My problem now is that I can spot a Dirichlet condition H0 = 0 at (x~0) in my results, but that is not what I defined above.
Is it a problem to use U0 = U.sub(0).collapse().function_space, since it will essentially build a new functionspace with unrelated dofs?
Thank you in advance,
Jeremie