Evaluating displacement at different locations in the variational form

Hello everybody,

I am trying to solve an elastic contact problem in fenicsx between nonoverlapping meshes.
I would like to compute the distance between points as a function of displacement. Every point has a known mapping function so the only unknown is the displacement field.

I am looking to compute something like ((f(x) + u(f(x)))-(x + u(x)))ds where f(x) maps point x to some other point on the mesh.
The problem arises in u(f(x)) how do I evaluate this function?
Now I can use a separate function, interpolate with u.eval, add it as a constant and iterate. However, ideally I would like to add this as a function of my unknowns.

This is similar to Hertzian contact with a rigid indenter using a penalty approach — Numerical tours of continuum mechanics using FEniCS master documentation
where the distance function now becomes a function of u.

Is there a way to get u as a function at some location on the mesh for use in the variational form?