# Undesired elements inside the region during meshing

**URL:** https://community.freefem.org/t/undesired-elements-inside-the-region-during-meshing/3789
**Category:** General Discussion
**Created:** [March 1, 2025, 10:01pm UTC](https://community.freefem.org/t/undesired-elements-inside-the-region-during-meshing/3789 "2025-03-01T22:01:29Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![elluc20](https://avatars.discourse-cdn.com/v4/letter/e/e274bd/32.png) [@elluc20](https://community.freefem.org/u/elluc20)
#### Post date: [March 1, 2025, 10:01pm UTC](https://community.freefem.org/t/undesired-elements-inside-the-region-during-meshing/3789/1 "2025-03-01T22:01:29Z")

</div>

![foto 1](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/0/0b21f33b696f8a43a04c3e24642192e151ea2828.jpeg)

Dear all,  
I’m having trouble with meshing. I’m trying to mesh a region that has a hole inside, but instead, I’m getting elements in yellow within that region. I want no elements in that area. How can I fix this?

int nbseg = 80, n = 10;  
mesh Th;  
real r1=1, r2=r1/4., r3=r1/8, r4=r1/12,anchoaleta=(r3/10); // Tubes dimensions  
border circleO(t=-pi/2,pi/2){label=1;x=r1_cos(t); y=r1_sin(t);}  
border gamma3(t=(r1/2)-sqrt(r3^2-anchoaleta^2)-r3,-r1/2+sqrt(r3^2-anchoaleta^2)+r3){label=2;x=0;y=t;} // pared simetria al medio  
border gamma4(t=-(r1/2)-sqrt(r3^2-anchoaleta^2)-r3,-r1){label=2;x=0;y=t;} // pared superior  
border gamma5(t=r1,r1/2+sqrt(r3^2-anchoaleta^2)+r3){label=2;x=0;y=t;} // pared inferior

///////// aletas tubo derecho completo /////////

//aleta derecha  
border gammaTCD1(t=((r1/2)+sqrt(r3^2-anchoaleta^2)),((r1/2)+sqrt(r3^2-anchoaleta^2))+r3){label=4;x=t;y=anchoaleta;}  
border gammaTCD2(t=anchoaleta,-anchoaleta){label=4;x=(r1/2)+sqrt(r3^2-anchoaleta^2)+r3;y=t;}  
border gammaTCD3(t=((r1/2)+sqrt(r3^2-anchoaleta^2))+r3,(r1/2)+sqrt(r3^2-anchoaleta^2)){label=4;x=t;y=-anchoaleta;}  
//aleta izquierda  
border gammaTCI1(t=((r1/2)-sqrt(r3^2-anchoaleta^2))-r3,(r1/2)-sqrt(r3^2-anchoaleta^2)){label=4;x=t;y=anchoaleta;}  
border gammaTCI2(t=-anchoaleta,anchoaleta){label=4;x=(r1/2)-sqrt(r3^2-anchoaleta^2)-r3;y=t;}  
border gammaTCI3(t=(r1/2)-sqrt(r3^2-anchoaleta^2),(r1/2)-sqrt(r3^2-anchoaleta^2)-r3){label=4;x=t;y=-anchoaleta;}  
//aleta superior  
border gammaTCS1(t=(sqrt(r3^2-anchoaleta^2)),(sqrt(r3^2-anchoaleta^2))+r3){label=4;x=(r1/2)+anchoaleta;y=t;}  
border gammaTCS2(t=(r1/2)-anchoaleta,(r1/2)+anchoaleta){label=4;x=t;y=sqrt(r3^2-anchoaleta^2)+r3;}  
border gammaTCS3(t=sqrt(r3^2-anchoaleta^2),sqrt(r3^2-anchoaleta^2)+r3){label=4;x=(r1/2)-anchoaleta;y=t;}  
//aleta inferior  
border gammaTCB1(t=-(sqrt(r3^2-anchoaleta^2)),-((sqrt(r3^2-anchoaleta^2))+r3)){label=4;x=(r1/2)+anchoaleta;y=t;}  
border gammaTCB2(t=anchoaleta,-anchoaleta){label=4;x=(r1/2)+t;y=-sqrt(r3^2-anchoaleta^2)-r3;}  
border gammaTCB3(t=-(sqrt(r3^2-anchoaleta^2))±r3,-(sqrt(r3^2-anchoaleta^2))){label=4;x=(r1/2)-anchoaleta;y=t;}

////// aleta superior semi ///////

//aleta derecha  
border gammaTSD1(t=(sqrt(r3^2-anchoaleta^2)),(sqrt(r3^2-anchoaleta^2))+r3){label=2;x=t;y=(r1/2)+anchoaleta;}  
border gammaTSD2(t=anchoaleta,-anchoaleta){label=2;x=(sqrt(r3^2-anchoaleta^2)+r3);y=(r1/2)+t;}  
border gammaTSD3(t=(sqrt(r3^2-anchoaleta^2))+r3,(sqrt(r3^2-anchoaleta^2))){label=2;x=t;y=(r1/2)-anchoaleta;}  
//aleta superior  
border gammaTSS1(t=((sqrt(r3^2-anchoaleta^2))+r3),(sqrt(r3^2-anchoaleta^2))){label=2;x=anchoaleta;y=(r1/2)+t;}  
border gammaTSS2(t=0,anchoaleta){label=2;x=t;y=r1/2+sqrt(r3^2-anchoaleta^2)+r3;}  
//aleta inferior  
border gammaTSI1(t=-(sqrt(r3^2-anchoaleta^2)),-((sqrt(r3^2-anchoaleta^2))+r3)){label=2;x=anchoaleta;y=(r1/2)+t;}  
border gammaTSI2(t=anchoaleta,0){label=2;x=t;y=+(r1/2)-sqrt(r3^2-anchoaleta^2)-r3;}

///// aleta inferior semi ///////

// aleta derecha  
border gammaTID1(t=(sqrt(r3^2-anchoaleta^2)),((sqrt(r3^2-anchoaleta^2))+r3)){label=2;x=t;y=-(r1/2)+anchoaleta;}  
border gammaTID2(t=anchoaleta,-anchoaleta){label=2;x=(sqrt(r3^2-anchoaleta^2)+r3);y=-(r1/2)+t;}  
border gammaTID3(t=(sqrt(r3^2-anchoaleta^2))+r3,(sqrt(r3^2-anchoaleta^2))){label=2;x=t;y=-(r1/2)-anchoaleta;}  
// aleta superior  
border gammaTIS1(t=((sqrt(r3^2-anchoaleta^2))+r3),(sqrt(r3^2-anchoaleta^2))){label=2;x=anchoaleta;y=-(r1/2)+t;}  
border gammaTIS2(t=0,anchoaleta){label=2;x=t;y=-r1/2+sqrt(r3^2-anchoaleta^2)+r3;}  
//aleta inferior  
border gammaTII1(t=-(sqrt(r3^2-anchoaleta^2)),-((sqrt(r3^2-anchoaleta^2))+r3)){label=2;x=anchoaleta;y=-(r1/2)+t;}  
border gammaTII2(t=anchoaleta,0){label=2;x=t;y=-(r1/2)-sqrt(r3^2-anchoaleta^2)-r3;}

// bordes circulo completo  
border segcircint1(t=acos(anchoaleta/r3),asin(anchoaleta/r3)){label=4;x=r1/2.+r3_cos(t); y=r3_sin(t);} // primer cuadrante  
border segcircint2(t=pi-asin(anchoaleta/r3),pi-acos(anchoaleta/r3)){label=4;x=r1/2.+r3_cos(t); y=r3_sin(t);} // segundo cuadrante  
border segcircint3(t=pi+acos(anchoaleta/r3),pi-asin(-anchoaleta/r3)){label=4;x=r1/2.+r3_cos(t); y=r3_sin(t);} // // tercer cuadrante  
border segcircint4(t=2_pi+asin(-anchoaleta/r3),2_pi-acos(anchoaleta/r3)){label=4;x=r1/2.+r3_cos(t); y=r3_sin(t);} // cuarto cuadrante

//bordes ciruclo superior  
border segcircsup1(t=acos(anchoaleta/r3),asin(anchoaleta/r3)){label=3;x=+r3_cos(t); y=(r1/2)+r3_sin(t);}  
border segcircsup2(t=2_pi+asin(-anchoaleta/r3),2_pi-acos(anchoaleta/r3)){label=3;x=r3_cos(t); y=(r1/2)+r3_sin(t);}

//bordes ciculo inferior  
border segcircinf1(t=acos(anchoaleta/r3),asin(anchoaleta/r3)){label=3;x=+r3_cos(t); y=-(r1/2)+r3_sin(t);}  
border segcircinf2(t=2_pi+asin(-anchoaleta/r3),2_pi-acos(anchoaleta/r3)){label=3;x=r3_cos(t); y=-(r1/2)+r3_sin(t);}

// Construcción de la malla principal con exclusión de la región rosada  
Th = buildmesh(  
circleO(n_8) // Contorno exterior  
+ gamma3(n_3) + gamma4(n) + gamma5(n) // Bordes adicionales  
+ segcircsup1(n) + segcircsup2(n) // Segmentos superiores  
+ segcircinf1(n) + segcircinf2(n) // Segmentos inferiores  
+ gammaTSD1(n) + gammaTSD2(n/3) + gammaTSD3(n) // Aletas semiderecha  
+ gammaTID1(n) + gammaTID2(n/3) + gammaTID3(n) // Aletas semizquierda  
+ gammaTSS1(n) + gammaTSS2(n) // Aletas superiores semicirculares  
+ gammaTIS1(n) + gammaTIS2(n) // Aletas inferiores semicirculares  
+ gammaTSI1(n) + gammaTSI2(n) // Aletas inferiores laterales  
+ gammaTII1(n) + gammaTII2(n) // Aletas inferiores internas  
+ segcircint1(n) + segcircint2(n) + segcircint3(n) + segcircint4(n)  
+ gammaTCD1(n) + gammaTCD2(n/3) + gammaTCD3(n)  
+ gammaTCI1(n) + gammaTCI2(n/3) + gammaTCI3(n)  
+ gammaTCS1(n) + gammaTCS2(n/3) + gammaTCS3(n)  
+ gammaTCB1(n) + gammaTCB2(n/3) + gammaTCB3(n)  
);

plot(Th, wait=1);

---

<div class="post-metadata">

### Author: ![RdMl](https://avatars.discourse-cdn.com/v4/letter/r/a88e57/32.png) [@RdMl](https://community.freefem.org/u/RdMl)
#### Post date: [March 3, 2025, 8:59am UTC](https://community.freefem.org/t/undesired-elements-inside-the-region-during-meshing/3789/2 "2025-03-03T08:59:02Z")

</div>

May be you should use a negative number of 1D meshes on the part of the boundary of the hole region. As in the example “Heat echanger” in the FF++ manual (see p. 51:53).

---

<div class="post-metadata">

### Author: ![elluc20](https://avatars.discourse-cdn.com/v4/letter/e/e274bd/32.png) [@elluc20](https://community.freefem.org/u/elluc20)
#### Post date: [March 11, 2025, 6:30pm UTC](https://community.freefem.org/t/undesired-elements-inside-the-region-during-meshing/3789/3 "2025-03-11T18:30:38Z")

</div>

I tried this, but I’m still getting the same result.

 ![imagen](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/b/b8139d44940230fc05470b4d0ba618f7755371b9.png)

---

<div class="post-metadata">

### Author: ![julienG](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/julieng/32/222_2.png) [@julienG](https://community.freefem.org/u/julienG)
#### Post date: [March 12, 2025, 4:10am UTC](https://community.freefem.org/t/undesired-elements-inside-the-region-during-meshing/3789/4 "2025-03-12T04:10:10Z")

</div>

First you should make sure that all borders are properly oriented. For this take all you have inside `buildmesh`and `plot` it say

> plot(  
> circleO(n\*8) // Contorno exterior  
> …

Inspect allboundary orientation and make sure that they are all the same for the hole. This might be the reason that chanig inside these does not solves the problem.

Anyway the following might be a bit artificial, but this should solve your problem  
1 - Get you region number for example

> fespace Ph(th, P0); //constant discontinuous functions / element  
> Ph reg=region; //defined the P0 function associated to region number  
> plot(reg, fill=true, wait=true, value=true);

2 - `trunc` out this region… maybe something like this

> Th=trunc(Th, reg!=undesiredregion);

---

<div class="post-metadata">

### Author: ![RdMl](https://avatars.discourse-cdn.com/v4/letter/r/a88e57/32.png) [@RdMl](https://community.freefem.org/u/RdMl)
#### Post date: [March 12, 2025, 9:21am UTC](https://community.freefem.org/t/undesired-elements-inside-the-region-during-meshing/3789/5 "2025-03-12T09:21:33Z")

</div>

Soyez en bonne santé,

Me too I tried that, but I didn’t get the expected results.  
The mesh is not working as it should. Strange.  
We need to check all the border definitions. I don’t have time to do that.  
May be asking to FH his advice.

Que la paix soit avec vous,

R. Michel

---

<div class="post-metadata">

### Author: ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)
#### Post date: [March 12, 2025, 9:27pm UTC](https://community.freefem.org/t/undesired-elements-inside-the-region-during-meshing/3789/6 "2025-03-12T21:27:34Z")

</div>

Your border `gammaTCS1` is wrongly oriented. It has to be  
`border gammaTCS1(t=(sqrt(r3^2-anchoaleta^2))+r3,(sqrt(r3^2-anchoaleta^2))){label=4;x=(r1/2)+anchoaleta;y=t;}`

---

<div class="post-metadata">

### Author: ![elluc20](https://avatars.discourse-cdn.com/v4/letter/e/e274bd/32.png) [@elluc20](https://community.freefem.org/u/elluc20)
#### Post date: [March 13, 2025, 4:12am UTC](https://community.freefem.org/t/undesired-elements-inside-the-region-during-meshing/3789/7 "2025-03-13T04:12:51Z")

</div>

It works, thank you very much 😀

---

<div class="post-metadata">

### Author: ![RdMl](https://avatars.discourse-cdn.com/v4/letter/r/a88e57/32.png) [@RdMl](https://community.freefem.org/u/RdMl)
#### Post date: [March 13, 2025, 10:58am UTC](https://community.freefem.org/t/undesired-elements-inside-the-region-during-meshing/3789/8 "2025-03-13T10:58:10Z")

</div>

Bonjour,

Merci.

Mais je ne suis pas vraiment le destinataire de courriel.  
Le bon destinataire est un certain Luciano de la “liste FF++”.

C’est l’auteur du maillage en question. Je n’ai fait que répondre à sa question.

Il m’a contacté hier ou avant hier pour me dire que le changement de signe

du nombre de mailles 1D des parties du bord relatives aux trous de son maillage

ne fonctionnait pas. J’ai répondu à son courriel (mais via la liste, donc l’a-t-il reçu ?)  
pour lui dire que moi aussi j’avais constaté que cela ne fonctionnait pas et lui  
avais suggéré de contrôler ses objets de classe border. De mon coté, je n’avais pas

le temps de le faire. Vous avez eu le temps de le faire. Soyez-en remercier.

Luciano est-il au courant de votre solution ?

Je vous souhaite une bonne journée,

R. Michel

PS. Pouvez svp m’indiquer si vous avez reçu le présent courriel car je l’envoie

en réponse à un couriel visiblement généré par un intermédiaire à savoir

“FreeFEM” [incoming+d964bb577c0aaf351309223096f6f726@freefem.discoursemail.com](mailto:incoming+d964bb577c0aaf351309223096f6f726@freefem.discoursemail.com);
