# Define different regions and border in a 3D mesh

**URL:** <https://community.freefem.org/t/define-different-regions-and-border-in-a-3d-mesh/1341>\
**Category:** General Discussion\
**Created:** [November 20, 2021, 5:58pm UTC](https://community.freefem.org/t/define-different-regions-and-border-in-a-3d-mesh/1341 "2021-11-20T17:58:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ruffi92](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/ruffi92/32/921_2.png) [@ruffi92](https://community.freefem.org/u/ruffi92)\
**Post date:** [November 20, 2021, 5:58pm UTC](https://community.freefem.org/t/define-different-regions-and-border-in-a-3d-mesh/1341/1 "2021-11-20T17:58:57Z")

</div>

Hi to all , i have problems to understand how to define a particular region inside a 3D mesh, and in particular how it works the definition of “labelmid” ecc…

In detail, i have the following mesh:

//Builds a mesh on 3d cylinder with a “full holes”.  
real cx1 = 0.0; // cerchio esterno  
real cy1 = 0.0;  
real r1 = 22.85;

real cx2 = 0.0; // canale centrale  
real cy2 = 0.0;  
real r2 = 1.905;

real cx3 = 7.058; // shim  
real cy3 = 4.075;  
real r3 = 1.88;

real cx4 = 0.0; // trans  
real cy4 = -12.15;  
real r4 = 1.88;

real cx5 = -14.142; // reg  
real cy5 = 8.165;  
real r5 = 1.88;

real zmin=0, zmax=35.6;  
int[int] rup=[0,1], rdown=[0,2], rmid=[1,7];  
border C1(t1=0,2_pi){x=cx1+r1_cos(t1);y=cy1+r1_sin(t1);label=1;}; // cerchio esterno  
border C2(t1=0,2_pi){x=cx2+r2_cos(t1);y=cy2+r2_sin(t1);label=2;}; // canale centrale  
border C3(t1=0,2_pi){x=cx3+r3_cos(t1);y=cy3+r3_sin(t1);label=3;}; // shim  
border C4(t1=0,2_pi){x=cx4+r4_cos(t1);y=cy4+r4_sin(t1);label=4;}; // trans  
border C5(t1=0,2_pi){x=cx5+r5_cos(t1);y=cy5+r5\*sin(t1);label=5;}; // reg

int m=5;  
mesh Thcercle = buildmesh(C1(40_m)+C2(+10_m)+C3(+10_m)+C4(+10_m)+C5(+10\*m));  
plot(Thcercle,wait =1);

mesh3 Th3=buildlayers(Thcercle,coef=2, 4\*m, zbound=[zmin,zmax],  
labelmid=rmid,  
labelup = rup,  
labeldown = rdown);

plot (Th3);

I want define the region of points included in the 4 “small” cylinder (separatly) and the surface of external cilinder (i suppose it is the “labelmid”), where I will apply a dirichlet condition in my problem.

Anyone can help me, or give me some tips? I read the FF documentation but is not so clear.  
Thanks!

P.s. i upload also the original file if can help

[triga mesh 3D.edp](https://community.freefem.org/uploads/short-url/6DPkd85pIopjadpYlzxIsifURO2.edp) (1.4 KB)

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [November 21, 2021, 1:31pm UTC](https://community.freefem.org/t/define-different-regions-and-border-in-a-3d-mesh/1341/2 "2021-11-21T13:31:38Z")

</div>

the way to change the region number with buildmesh construction is

// to get the region number in 2d mesh  
int reg1 = Thcercle(cx1,cy1+r1\*0.999).region;  
int reg2 = Thcercle(cx2,cy2).region;  
int reg3 = Thcercle(cx3,cy3).region;  
int reg4 = Thcercle(cx4,cy4).region;  
int reg5 = Thcercle(cx5,cy5).region;  
// to change the region number in 3d mesh

int[int] regv=[reg1,1,reg2,2,reg3,3,reg4,4,reg5,5];  
cout \<\< " reg " \<\< reg1 \<\< " " \<\< reg2 \<\< " " \<\< reg3 \<\< " "\<\< reg4 \<\< " " \<\< reg5 \<\< endl;  
mesh3 Th3=buildlayers(Thcercle,coef=2, 4\*m, zbound=[zmin,zmax],  
labelmid=rmid,  
labelup = rup,  
labeldown = rdown,region=regv);

---

<div class="post-metadata">

**Author:** ![ruffi92](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/ruffi92/32/921_2.png) [@ruffi92](https://community.freefem.org/u/ruffi92)\
**Post date:** [November 21, 2021, 3:38pm UTC](https://community.freefem.org/t/define-different-regions-and-border-in-a-3d-mesh/1341/3 "2021-11-21T15:38:47Z")

</div>

thank you very very much for your respond!

I have few more question about this:

1. what is the “correct” definition of rmid, rup, rdown in this case? The one that i propose is ok?

2. the output of cout is " 4 3 2 1 0" so reg1 in 3d mesh is identified by “4”?

3. in my differential problem i write a dirichlet condition like “…+on (4 , u=1e-30)” but on the external surface i haven’t u=0. I write the wrong label?

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [November 26, 2021, 10:09pm UTC](https://community.freefem.org/t/define-different-regions-and-border-in-a-3d-mesh/1341/4 "2021-11-26T22:09:25Z")

</div>

1. we build a cylinder $\omega\times[0,1]$ before transformation with 3 type of boundary  
up part $\omega\times{1}$, down part $\omega\times{0}$ and the cylinder part call mid  
$\partial\omega\times[0,1]$. Where Omega is the 2d domain.

2. yes

3. in is case array run and down a wrong because you have a mapping between region number to label  
it depend of want you want  
// for label of top is 10  
int[int] rup=[reg1,10,reg2,10,reg3,10,reg4,10,reg5,10];  
// for label of bottom par is 20  
int[int] rdown=[reg1,20,reg2,20,reg3,20,reg4,20,reg5,20];

// le label of face of cycle will be 31,32,33,34,35 depending of the label of cercle 1,2,3,4,5  
int[int] rmid=[1,31,2,32,3,33,4,34,5,35];
