How to apply a pointwise force using dolfinx

Hi, everyone! I want to apply a force on a specify node of the mesh in only one direction (e.g x-direction) in linear elasticity problem. How should I do this?

Please use the search button before posting. The question has been asked several times in this forum, and one possible solution is Point Sources (Redux) - #6 by dokken

Thank you Mr. ballarin. for your suggestion. I apologize for the post question. I’ll search the forum to make sure no the same posting before posting. :pray:

rd = dolfinx.fem.locate_dofs_geometrical(V=V, marker=lambda x: np.isclose(x[0], 2.0) & np.isclose(x[1], 0.0))
# create compiled form
a_compiled = dolfinx.fem.form(a)
L_compiled = dolfinx.fem.form(L)
# Define a linear variational solver
ksp_type = getattr(petsc4py.PETSc.KSP.Type, "PREONLY")
pc_type = getattr(petsc4py.PETSc.PC.Type, "LU")
solver = petsc4py.PETSc.KSP().create(mesh.comm)
# assemble_matrix with Dirichlet conditions
A = dolfinx.fem.petsc.assemble_matrix(a_compiled)
dofs, _ = bc._cpp_object.dof_indices()
A.zeroRowsColumnsLocal(dofs, diag=1)
# assemble_vector without dirichletbc
b = dolfinx.fem.petsc.assemble_vector(L_compiled)
b.ghostUpdate(addv=petsc4py.PETSc.InsertMode.ADD_VALUES, mode=petsc4py.PETSc.ScatterMode.REVERSE)
# apply_lifting, i.e subtract Ag from the vector
dolfinx.fem.petsc.apply_lifting(b, [a_compiled], bcs=[[bc]])
b.ghostUpdate(addv=petsc4py.PETSc.InsertMode.INSERT_VALUES, mode=petsc4py.PETSc.ScatterMode.FORWARD)
# set bc, i.e set the degrees of freedom for known dofs
dolfinx.fem.petsc.set_bc(b, [bc])
b.setValue(rd, 1)

When I use ‘’‘b.setValue(rd, 1)’‘’ to apply point force using the above code, it will apply the force to all directions of the point “rd” (which is the dof of the point). But I just want to appy the force in the x-direction. Do you have any suggestions for this? Thank you very much.

Please add a minimal reproducible example, as it is hard to Give any guidance from the snippet you have produced

1 Like

I figured out what the mistake was. The degrees-of-freedom of the point I want to find through “rd = dolfinx.fem.locate_dofs_geometrical(V=V, marker=lambda x: np.isclose(x[0], 2.0) & np.isclose(x[1], 0.0))” is actually The global index of the node. So if I want to apply a x-direction force on the node, I should use “b.setValue(2*rd, 1)” instead of “b.setValue(rd, 1)”. Still thanks for your reply.