Force vertices coincidence at the interface of two meshes

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

1 Like

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.

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

1 Like

OK, perfect, thank you very much.

C

1 Like