# Force vertices coincidence at the interface of two meshes

**URL:** <https://community.freefem.org/t/force-vertices-coincidence-at-the-interface-of-two-meshes/1487>\
**Category:** General Discussion\
**Created:** [February 10, 2022, 10:10pm UTC](https://community.freefem.org/t/force-vertices-coincidence-at-the-interface-of-two-meshes/1487 "2022-02-10T22:10:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![christof](https://avatars.discourse-cdn.com/v4/letter/c/3da27b/32.png) [@christof](https://community.freefem.org/u/christof)\
**Post date:** [February 10, 2022, 10:10pm UTC](https://community.freefem.org/t/force-vertices-coincidence-at-the-interface-of-two-meshes/1487/1 "2022-02-10T22:10:56Z")

</div>

Hi,

I would like to force two glued meshes to have coincident vertices on their shared border, so that it is possible to save the mesh in a file.

For example, the example below:

> int n=8;  
> mesh Th1=square(n,n);  
> border B(t=1,2) { x=t; y=0; }  
> border R(t=0,1) { x=2; y=t; }  
> border U(t=-2,-1) { x=-t; y=1; }  
> border L(t=-1,0) { x=1; y=-t; }  
> mesh Th2=buildmesh(L(n)+B(n \* 1.5)+R(n \* 1.5)+U(n \* 1.5));  
> mesh Th=Th1+Th2;  
> plot(Th);  
> savemesh(Th,“th.mesh”);

fails on the savemesh command, because, I suppose, the vertices at the interface between the two meshes do not coincide. Is there a way to do this?

Many thanks

---

<div class="post-metadata">

**Author:** ![fivanci](https://avatars.discourse-cdn.com/v4/letter/f/e95f7d/32.png) [@fivanci](https://community.freefem.org/u/fivanci)\
**Post date:** [February 11, 2022, 2:29am UTC](https://community.freefem.org/t/force-vertices-coincidence-at-the-interface-of-two-meshes/1487/2 "2022-02-11T02:29:14Z")

</div>

> [@christof](#):
>
> Is there a way to do this?

There is. You can extract the nodes of the boundary of the mesh using `extractborder(...)` function from `load "Curvature"` module (it gives you an option which boundary to extract through boundary labels). And then, when using `buildmesh(...)` you can enforce the desired distribution of nodes, _a priori_ prescribed, by passing the option `fixedborder=true`.

```auto
load "Curvature"

int n=8;
mesh Th1=square(n,n); //plot(Th1,wait=1);

int[int] labs=[2];
real[int,int] nodesTh1(3,1);
extractborder(Th1,labs,nodesTh1);

border B(t=1,2) { x=t; y=0; }
border R(t=0,1) { x=2; y=t; }
border U(t=-2,-1) { x=-t; y=1; }
border L(t=0,nodesTh1.m-1) { P.x=nodesTh1(0,t); P.y=nodesTh1(1,t); label=2; }
mesh Th2=buildmesh( L(-(nodesTh1.m-1)) + B(n*1.5) + R(n*1.5) + U(n*1.5),fixedborder=true);
mesh Th=Th1+Th2; //plot(Th,wait=1);

savemesh(Th,"th.mesh");

```

Above, in `extractborder(Th1,labs,nodesTh1);`, node coordinates of boundary labeled `2` of mesh `Th1` are extracted into `nodesTh1(0,:)` and `nodesTh1(1,:)`, x and y coordinates, respectively. Also, orientation is preserved from `Th1` - bcs of that, when construction `Th2` you have to be careful with orientation (note, `L(-(nodesTh1.m-1))` → negative sign changes orientation).

if

---

<div class="post-metadata">

**Author:** ![christof](https://avatars.discourse-cdn.com/v4/letter/c/3da27b/32.png) [@christof](https://community.freefem.org/u/christof)\
**Post date:** [February 11, 2022, 12:14pm UTC](https://community.freefem.org/t/force-vertices-coincidence-at-the-interface-of-two-meshes/1487/3 "2022-02-11T12:14:39Z")

</div>

OK, perfect, thank you very much.

C
