Buildlayers : labels

Hello, I would like to use the buildlayers command to create a 3D block from a rectangle. The rectangle is defined as follows:

border Square1(t=0,1){x = -L/2 + t*L; y = -l/2;label=1;} border Square2(t=0,1){x = L/2; y = -l/2 + t*l;label=2;} border Square3(t=0,1){x = L/2 - t*L; y = l/2;label=3;} border Square4(t=0,1){x = -L/2; y = l/2 - t*l;label=4;}

I would like to understand how the labels work when using buildlayers. I would like the top face to have label 1, the bottom face label 3, and the sides to all share the same label, which is 2. How can I do that?

And how can I check the labels in FreeFEM?

Thank you.

For the 3d labels and buildlayers you can look at the documentation

p.146
you need to define three arrays
rdown, rup, rmid to define the labels of the boundaries of the 3d mesh.
These arrays are a list of couples of integers, the first integer is the label of the 2d input mesh, the second integer is the label of the 3d output mesh.

For your case you have to take (label 0 for the 2d mesh means the interior)
rup=[0,1];
rdown=[0,3];
rmid=[1,2,2,2,3,2,4,2];

To check the regions of a mesh (labels in the interior of the domain) you can write
int mylab=Th(0.,0.,0.).region;
where the three arguments are the coordonates of a point.

To get the list of all labels (not regions) of a mesh you can write
int[int] labs=labels(Th);

real L=1.,l=0.5;
border Square1(t=0,1){x = -L/2 + t*L; y = -l/2;label=1;}
border Square2(t=0,1){x = L/2; y = -l/2 + t*l;label=2;}
border Square3(t=0,1){x = L/2 - t*L; y = l/2;label=3;}
border Square4(t=0,1){x = -L/2; y = l/2 - t*l;label=4;}
mesh Th2=buildmesh(Square1(5)+Square2(5)+Square3(5)+Square4(4));
plot(Th2,wait=1);

int ny=3;
int[int] rup=[0,1],rdown=[0,3],rmid=[1,2,2,2,3,2,4,2];;
mesh3 Th=buildlayers(Th2, ny, zbound = [-1., 1.],labelmid=rmid, labelup = rup, labeldown = rdown);
plot(Th);

int mylab=Th(0.,0.,1.).region;
cout << "mylab " << mylab << endl;

int[int] labs=labels(Th);
cout << "labs " << labs << endl;