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); 

Hello Fréderic,

Regarding the last example that you have mentioned:

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); 

By applying it initially to a square domain in the following form:

load “iovtk”

load “distance”

//mesh Th=readmesh(“Square2d.mesh”);

mesh Th=square(10,10);

int[int] lb=labels(Th);

fespace Vh(Th,P1);

Vh u,v;

varf vb(u,v) = on(lb,u=0);

//+on(2,3,4, u=-1);

Vh ub = vb(0,Vh, tgv=1);

plot(ub, wait=1, value=1);

ub = ub ? 0:1;

plot(ub,wait=1,value=1);

Vh dist;

distance(Th,ub,dist,distmax=100);

plot(dist,wait=1,value=1,nbiso=100);

savevtk(“distance.vtk”,Th,dist,dataname=“distance”);

When i plot the distance filed i get:

[image]

The representation I get is above. Could you give me a hint of what’s faling or missing in the code in order to obtain the desired distribution? The idea is to reproduce this method in a ficticious domain which embeds a smaller square domain and compute a lavel set phi function:

[image]

Thank you in avance.

Best Regards

Jacob

My correction

load "distance"
mesh Th=square(10,10);
fespace Vh(Th,P1);
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);
plot(dist,wait=1);

the correction :
untitled.edp (435 Bytes)