Use a computed solution as boundary value

Dear all,
I am new on FreeFem. I want to compute some shape derivatives and therefore I need to Solve first a PDE with a prescribed boundary data and then I need to capture a partial derivative of the computed solution to take it as new data on the boundary.
I naively tried this (u1,u2) being the computed solution :
Xh U1 = dx(u1)(x,y);
Xh U2 = dx(u2)(x,y);
and then
but this does not work.
Then this :
Up1([x, y]) = U1(x,y);
Up2([x, y]) = U2(x,y);
and then
This doesn’t work neither.
I can indeed evaluate U1 and U2 at any given point of the boundary so I have tried to rebuild the new boundary data from an interpolation but I was not successful.
Does someone know how to solve this ? I have checked the documentation and the forum but I do not find any example I can mirror.
Thanks in advance and best,

Theoretical this works:
but try :

I restarted from scratch and it works just as I was trying or as you suggest. Probably some other thing was wrong in my code. Thanks for your quick answer !