Hello, how do I apply a Dirichlet BC to the x and y components of displacements at a specific coordinate but leave the z-component free?
U_ele = ufl.VectorElement(“CG”, mesh.ufl_cell(), degree=deg_u)
U = fem.FunctionSpace(mesh, U_ele)
def x_y(x):
return np.logical_and(np.logical_and(np.isclose(x[0], 1.), np.isclose(x[1], 0.)), np.isclose(x[2], 0.))
Is it like this:
x_y_dof_x = fem.locate_dofs_topological(U.sub(0), mesh.topology.dim-1, x_y_facets)
x_y_dof_y = fem.locate_dofs_topological(U.sub(1), mesh.topology.dim-1, x_y_facets)
x_y_bcx = fem.dirichletbc(PETSc.ScalarType(0.), x_y_dof_x, U.sub(0))
x_y_bcy = fem.dirichletbc(PETSc.ScalarType(0.), x_y_dof_y, U.sub(1))
Because this does not work, it only constrains the X-component and not the Y-component.
dokken
April 3, 2023, 12:22pm
2
You would need to add a complete minimal working example that reproduces your error for anyone to be able to help you.
See for instance:
https://jsdokken.com/dolfinx-tutorial/chapter3/component_bc.html#boundary-conditions
and
def test_sub_constant_bc(mesh_factory):
"""Test that setting a dirichletbc with on a component of a vector
valued function yields the same result as setting it with a
function"""
func, args = mesh_factory
mesh = func(*args)
tdim = mesh.topology.dim
V = VectorFunctionSpace(mesh, ("Lagrange", 1))
c = Constant(mesh, PETSc.ScalarType(3.14))
boundary_facets = locate_entities_boundary(mesh, tdim - 1, lambda x: np.ones(x.shape[1], dtype=bool))
for i in range(V.num_sub_spaces):
Vi = V.sub(i).collapse()[0]
u_bci = Function(Vi)
u_bci.x.array[:] = PETSc.ScalarType(c.value)
boundary_dofsi = locate_dofs_topological((V.sub(i), Vi), tdim - 1, boundary_facets)
bc_fi = dirichletbc(u_bci, boundary_dofsi, V.sub(i))
boundary_dofs = locate_dofs_topological(V.sub(i), tdim - 1, boundary_facets)
bc_c = dirichletbc(c, boundary_dofs, V.sub(i))
This file has been truncated. show original
Thanks for the share Dokken. I fixed the issue with:
Hi
I have been successfully running a nonlinear mixed vector field problem (simple uni-axial tension of a rod) using a non-homogeneous Dirichlet boundary condition incrementally applied as a vector, i.e [ u_x, u_y, u_z] = [ t*1.0, 0.0, 0.0 ] at the right end of the rod (the left end is clamped):
msh = mesh.create_box(MPI.COMM_WORLD, [np.array([0.0, 0.0, 0.0]), np.array([L, H, H])], [20, 1, 1],
mesh.CellType.hexahedron)
P1 = ufl.VectorElement("CG", msh.ufl_cell(), 2, dim=3…