# TetGen for domains with overlapping facets

**URL:** <https://community.freefem.org/t/tetgen-for-domains-with-overlapping-facets/989>\
**Category:** General Discussion\
**Created:** [May 21, 2021, 7:34am UTC](https://community.freefem.org/t/tetgen-for-domains-with-overlapping-facets/989 "2021-05-21T07:34:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fotios.kasolis](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fotios.kasolis/32/18_2.png) [@fotios.kasolis](https://community.freefem.org/u/fotios.kasolis)\
**Post date:** [May 21, 2021, 7:34am UTC](https://community.freefem.org/t/tetgen-for-domains-with-overlapping-facets/989/1 "2021-05-21T07:34:16Z")

</div>

Dear FreeFEM comminity,

Is there any example or does anybody know how to mesh, provided feasibility, a domain like the one in the attached code? The problem here is that the subdomain is not strictly contained in the bounding domain, but rather, they have common interfaces. Increasing the bounding box size works but is not an option. The code below works with binary 4.8 on MSW10.

Best Regards,  
/Fotios

```auto
load "msh3"
load "tetgen"

border a01(t = 0.5 , 1.0 ){x = t ; y = 0.0 ;}
border a02(t = 0.0*pi, 0.5*pi){x = 1.0*cos(t); y = 1.0*sin(t);}
border a03(t = 1.0 , 0.5 ){x = 0.0 ; y = t ;}
border a04(t = 0.0*pi, 0.5*pi){x = 0.5*sin(t); y = 0.5*cos(t);}

int n = 100;
mesh T2 = buildmesh(a01(n) + a02(n) + a03(n) + a04(n));
mesh3 T3 = buildlayers(T2, 20, zbound=[0.0, 1.0]);
mesh3 Tb = cube(20, 20, 20, [2.0*x, 2.0*y, -0.5+2.0*z]);

T3 = buildBdMesh(T3); meshS TS3 = T3.Gamma;
Tb = buildBdMesh(Tb); meshS TSb = Tb.Gamma;
meshS TSall = TS3 + TSb;

plot(TSall, wait=true);
//mesh3 Tall = tetg(TSall, switch="paAAYYQ");

```

---

<div class="post-metadata">

**Author:** ![fotios.kasolis](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fotios.kasolis/32/18_2.png) [@fotios.kasolis](https://community.freefem.org/u/fotios.kasolis)\
**Post date:** [May 21, 2021, 8:53am UTC](https://community.freefem.org/t/tetgen-for-domains-with-overlapping-facets/989/2 "2021-05-21T08:53:41Z")

</div>

A way for doing this, although I find it far from a good solution, follows; this approach uses `trunc` for removing the necessary parts from the surface mesh `TS3`.

```auto
real eps = 1.0e-2;
TS3 = trunc(TS3, x > eps);
TS3 = trunc(TS3, y > eps);

meshS TSall = TS3 + TSb;

mesh3 Tall = tetg(TSall);
plot(Tall, wait=true);

```
