# Mesh error when combine two regions

**URL:** <https://community.freefem.org/t/mesh-error-when-combine-two-regions/2335>\
**Category:** General Discussion\
**Created:** [March 15, 2023, 5:13pm UTC](https://community.freefem.org/t/mesh-error-when-combine-two-regions/2335 "2023-03-15T17:13:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![yongxing](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/yongxing/32/3632_2.png) [@yongxing](https://community.freefem.org/u/yongxing)\
**Post date:** [March 15, 2023, 5:13pm UTC](https://community.freefem.org/t/mesh-error-when-combine-two-regions/2335/1 "2023-03-15T17:13:48Z")

</div>

Can someone spot the error: there is no problem to generate Thf and Ths, but there is an error to combine these to regions which is weird:

Bug in mortar constrution : close to vertex 3  
current line = 7  
Assertion fail : (linkd[is] == -2)  
line :380, in file …/femlib/fem.cpp  
catch Err bamg  
Assertion fail : (linkd[is] == -2)  
line :380, in file …/femlib/fem.cpp  
err code 6 , mpirank 0

code:  
[testmesh.edp](https://community.freefem.org/uploads/short-url/3JZb3BqWLn8oMuYrNSfMZrtXtBt.edp) (1.1 KB)

```auto
int mh=5, m=20, lf=4;
real L=5.e-2, H=3.e-2, h=8.e-3, l=lf*H, L1 = (L-2.*h);
real HH=0.2e0, LL=0.5*HH;

// Fluid Region
border a1(t=-LL,LL) {x=t; y=-HH ;label=1;};
border a2(t=-HH,HH) {x=LL; y=t ;label=2;};
border a3(t=LL,-LL) {x=t; y=HH ;label=1;};
border a4(t=HH,-HH) {x=-LL; y=t ;label=3;};
func fluidbound = a1(m)+a2(2*m)+a3(m)+a4(2*m);
plot(fluidbound, dim=2, wait=1);

// Solid Region
border b1(t=-L1/2., L1/2.) {x=t; y=0. ;label=5;};
border b2(t=0,-l) {x=L1/2.; y=t ;label=5;};
border b3(t=L1/2., L1/2. + h) {x=t; y=-l ;label=5;};
border b4(t=-l, H) {x=L1/2.+h; y=t ;label=5;};
border b5(t=L/2.,-L/2.) {x=t; y=H ;label=5;};
border b6(t=H, -l) {x=-L/2; y=t;label=5;};
border b7(t=-L/2,-L1/2.) {x=t; y=-l;label=5;};
border b8(t=-l,0) {x=-L1/2.; y=t;label=5;};
border b9(t=-L1/2., L1/2.) {x=t; y=0;label=5;};
func solidbound = b1(2*mh)+b2(lf*mh)+b3(3)+b4((lf+1)*mh)+b5(2*mh)+b6((lf+1)*mh)+b7(3)+b8(lf*mh)+b9(2*mh);
plot(fluidbound + solidbound, dim=2, wait=1);

mesh Thf = buildmesh(fluidbound);
plot(Thf, wait=1);

mesh Ths = buildmesh(solidbound);
plot(Ths, wait=1);

mesh Th = buildmesh(fluidbound + solidbound);
plot(Th, wait=1);

```

---

<div class="post-metadata">

**Author:** ![cmd](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/cmd/32/67_2.png) [@cmd](https://community.freefem.org/u/cmd)\
**Post date:** [March 15, 2023, 5:55pm UTC](https://community.freefem.org/t/mesh-error-when-combine-two-regions/2335/2 "2023-03-15T17:55:40Z")

</div>

I think the orientation of your parameterized boundary is incorrect.

```auto
int mh=5, m=20, lf=4;
real L=5.e-2, H=3.e-2, h=8.e-3, l=lf*H, L1 = (L-2.*h);
real HH=0.2e0, LL=0.5*HH;

// Fluid Region
border a1(t=-LL,LL) {x=t; y=-HH ;label=1;};
border a2(t=-HH,HH) {x=LL; y=t ;label=2;};
border a3(t=LL,-LL) {x=t; y=HH ;label=1;};
border a4(t=HH,-HH) {x=-LL; y=t ;label=3;};
func fluidbound = a1(m)+a2(2*m)+a3(m)+a4(2*m);
plot(fluidbound, dim=2, wait=1);

// Solid Region
border b1(t=-L1/2., L1/2.) {x=t; y=0. ;label=5;};
border b2(t=0,-l) {x=L1/2.; y=t ;label=5;};
border b3(t=L1/2., L1/2. + h) {x=t; y=-l ;label=5;};
border b4(t=-l, H) {x=L1/2.+h; y=t ;label=5;};
border b5(t=L/2.,-L/2.) {x=t; y=H ;label=5;};
border b6(t=H, -l) {x=-L/2; y=t;label=5;};
border b7(t=-L/2,-L1/2.) {x=t; y=-l;label=5;};
border b8(t=-l,0) {x=-L1/2.; y=t;label=5;};
border b9(t=-L1/2., L1/2.) {x=t; y=0;label=5;};
func solidbound = b1(2*mh)+b2(lf*mh)+b3(3)+b4((lf+1)*mh)+b5(2*mh)+b6((lf+1)*mh)+b7(3)+b8(lf*mh)+b9(2*mh);
func solidbound2 = b1(-2*mh)+b2(-lf*mh)+b3(-3)+b4(-(lf+1)*mh)+b5(-2*mh)+b6(-(lf+1)*mh)+b7(-3)+b8(-lf*mh)+b9(-2*mh);
plot(fluidbound + solidbound, dim=2, wait=1);
mesh Thf = buildmesh(fluidbound);
plot(Thf, wait=1);
mesh Ths = buildmesh(solidbound);
plot(Ths, wait=1);
mesh Th = buildmesh(fluidbound + solidbound2);
plot(Th, wait=1);

```

---

<div class="post-metadata">

**Author:** ![yongxing](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/yongxing/32/3632_2.png) [@yongxing](https://community.freefem.org/u/yongxing)\
**Post date:** [March 15, 2023, 6:06pm UTC](https://community.freefem.org/t/mesh-error-when-combine-two-regions/2335/3 "2023-03-15T18:06:34Z")

</div>

Thank you @cmd , but I actually need the solid mesh instead of a hole… shouldn’t have been a problem ?

---

<div class="post-metadata">

**Author:** ![cmd](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/cmd/32/67_2.png) [@cmd](https://community.freefem.org/u/cmd)\
**Post date:** [March 15, 2023, 6:14pm UTC](https://community.freefem.org/t/mesh-error-when-combine-two-regions/2335/4 "2023-03-15T18:14:21Z")

</div>

Then just create the solid and fluid meshes separately and then add the mesh objects.

```auto
int mh=5, m=20, lf=4;
real L=5.e-2, H=3.e-2, h=8.e-3, l=lf*H, L1 = (L-2.*h);
real HH=0.2e0, LL=0.5*HH;

// Fluid Region
border a1(t=-LL,LL) {x=t; y=-HH ;label=1;};
border a2(t=-HH,HH) {x=LL; y=t ;label=2;};
border a3(t=LL,-LL) {x=t; y=HH ;label=1;};
border a4(t=HH,-HH) {x=-LL; y=t ;label=3;};
func fluidbound = a1(m)+a2(2*m)+a3(m)+a4(2*m);
plot(fluidbound, dim=2, wait=1);
// Solid Region
border b1(t=-L1/2., L1/2.) {x=t; y=0. ;label=5;};
border b2(t=0,-l) {x=L1/2.; y=t ;label=5;};
border b3(t=L1/2., L1/2. + h) {x=t; y=-l ;label=5;};
border b4(t=-l, H) {x=L1/2.+h; y=t ;label=5;};
border b5(t=L/2.,-L/2.) {x=t; y=H ;label=5;};
border b6(t=H, -l) {x=-L/2; y=t;label=5;};
border b7(t=-L/2,-L1/2.) {x=t; y=-l;label=5;};
border b8(t=-l,0) {x=-L1/2.; y=t;label=5;};
border b9(t=-L1/2., L1/2.) {x=t; y=0;label=5;};
func solidbound = b1(2*mh)+b2(lf*mh)+b3(3)+b4((lf+1)*mh)+b5(2*mh)+b6((lf+1)*mh)+b7(3)+b8(lf*mh)+b9(2*mh);
func solidbound2 = b1(-2*mh)+b2(-lf*mh)+b3(-3)+b4(-(lf+1)*mh)+b5(-2*mh)+b6(-(lf+1)*mh)+b7(-3)+b8(-lf*mh)+b9(-2*mh);
plot(fluidbound + solidbound, dim=2, wait=1);
mesh Thf = buildmesh(fluidbound);
plot(Thf, wait=1);
mesh Ths = buildmesh(solidbound);
plot(Ths, wait=1);
mesh Th = buildmesh(fluidbound + solidbound2);
plot(Th, wait=1);

mesh Thsum = Ths + Th;

plot(Thsum, wait=1);

```

---

<div class="post-metadata">

**Author:** ![yongxing](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/yongxing/32/3632_2.png) [@yongxing](https://community.freefem.org/u/yongxing)\
**Post date:** [March 15, 2023, 6:16pm UTC](https://community.freefem.org/t/mesh-error-when-combine-two-regions/2335/5 "2023-03-15T18:16:14Z")

</div>

Thank you very much! it works. I am used to _trunc ()_ …
