In legacy dolfin: Project the gradient into a suitable space and use point evaluation. See:
In Dolfinx you can use the Expression class.
Expression