See for instance
There are various other ways to do this as well, for instance with locate_dofs_topological
or geometrical, see for instance How to apply a pointwise force using dolfinx - #6 by lyunfei1211
How to apply component wise dirichlet boundary condition on a point - #2 by dokken
or by looking at a map from global input index to dof:
How to apply a boundary condition to a range of DOFs? - #7 by dokken