Distance map from boundary

Hello!
Given a mesh defined in FreeFem (in 2D for the moment), I would be interested by a distance map to a part of its boundary as a finite element field on it.

For instance, if I have a square mesh with label 1 for the bottom, label 2 for the right side, label 3 for the top and label 4 for the left side, I would like to have a distance map to the boundary part defined by labels 1 and 2.

What would be the way to have that?

Thanks a lot in advance!

You can use the plugin distante,

see :

to build the iso value of the border

load "distance"
int[int] lb=labels(Th);:
varf vb(u,v) = on(lb,u=1):
Vh ub= vb(0,Vh,tgv=1);// 1 on all arder and zero inside
ub[] = ub[] ? 0 : 1; //  0 on border and 1 inside
Vh dist;
distance(Th,ub,dist);
plot(ub,wait=1);