The actually relevant error probably is
Traceback (most recent call last):
File "/tmp/a.py", line 58, in <module>
dof=locate_dofs_topological(W,0,startpt)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "lib/python3.11/site-packages/dolfinx/fem/bcs.py", line 87, in locate_dofs_topological
return _cpp.fem.locate_dofs_topological(V._cpp_object, entity_dim, _entities, remote) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Entity-to-cell connectivity has not been computed.
That error you get can be fixed by adding a domain.topology.create_connectivity(0, domain.topology.dim)
before the final for
loop.