Find adjacent DOF

If you want your code to work in parallel, I would simply get all nodes of your mesh, i.e. mesh.geometry.x and pass it to: dolfinx/cpp/dolfinx/geometry/utils.h at 58fd47824ab920fd6576e4d321782c683b168532 · FEniCS/dolfinx · GitHub
(it has a Python wrapper, see for instance: Can you help me apply compute_cell_contributions method to 1D cantilever beam example? - #6 by dokken for an example.

It will give you the cell that collides with every point (vertex) of your mesh (and tell you what process it came from.