Could you provide how you modified the code in:
as, you most likely need to use the Mesh
wrapper around the object returned by generate_mesh
from mshr. See for instance: Adjoint solution with PointSource as source term (f) for Poisson equation - #6 by dokken