Use dirichletbc and dolfinx.fem.set_bc, see: DirichletBC with mesh tags in dolfinx - weird behavior - #2 by dokken
dirichletbc
dolfinx.fem.set_bc