Cut a 2D domain or a 2D mesh with a curve


Hello all,

I am trying to make some perforations (circular) on an existing 2D meshes that I have previously built. For information, I can consider this mesh or only the triangular domain (without the elements inside).

For this, I have tried to make the summation of this mesh with a disc and then truncate the given mesh with an indicator function, but it does not work.

Is it possible to cut a mesh or a domain according to a curve for example ?

Basically I am looking for a function “MakeCut”, which for example works like this:
mesh TH=MakeCut(TH, x^2-y^2 < R^2) and returns the mesh TH cut by a circle.

Thank you for your help,

Best regards,

Loïc,

To day, they a no tools to do this,
but you can build the border of the intersection.
See exemple isoline.edp ie: FreeFem-sources/isoline.edp at master · FreeFem/FreeFem-sources · GitHub

This not exactly what you want but it will given a not to bad mesh.

Thank you for you reply,

In this example, we have:

border Curve1(t=0,1)
{ int c =1;
  int i0 = be[2*c], i1 = be[2*c+1]-1;
  P=Curve(xy,i0,i1,t);
  label=1;
}
plot(Curve1(100), wait=1);
mesh Th= buildmesh(Curve1(-100));
plot(Th,wait=1);

which gives this two figures :


However, I want to keep the rectangular shape and delete the circle instead.
How could I do that ?

Thank you in advance for your help,

Best regards,

Loïc,

an example:

Blockquote

border a(t=-2,2){x=t; y=-2;label=1;};
border b(t=-2,2){x=2; y=t;label=1;};
border c(t=2,-2){x=t; y=2;label=1;};
border d(t=2,-2){x=-2; y=t;label=1;};
border cc(t=2*pi,0){ x=cos(t); y=sin(t);label=2;}

int n = 20;
plot(a(2n)+b(2n)+c(2n)+d(2n)+cc(pin),wait=1,ps=“squarebb.eps”);
mesh th= buildmesh(a(2
n)+b(2n)+c(2n)+d(2n)+cc(pin));
plot(th,wait=1);

Blockquote

Hello,

Thank you for you reply,
Yes sure, I know this method, but I was looking for the same kind of thing for the isoline method that you proposed, since I want to consider more general case for example when the borders of the 2 meshes considered are crossing.

Thank you,

Best regards,

Loïc,

Question, Why you want to do this.

Because, in general the mesh created is no so pretty., This build mesh have some small element , bad angle, …

Yes, I see that.
I succeed to generate this kind of mesh with the isoline method:


But it gives bad angles as you say.

Originally I wanted to apply a kind of patch to an existing mesh to create a mesh with perforations. But I think this method is not suitable for my case.

I will find another solution to this (computing the intersection or use another tool for the mesh such as mmg).

Thank you,

Best regards,

Loïc,

  1. it is not so hard to add an angle criteria in isoline to and separate the isoline plugin by add
    un curer (border if the angle is not good, like corner).

=> no optimisation of the curve at this points
and change the array be in isoline

Thanks you for your reply,

Pierre Jolivet @prj proposes another method with the use of mmg2d to adapt the mesh to the isoline solution before truncating the mesh according to the isoline with FreeFEM. My new perforated mesh is given by :

>  ` savemesh(Th,"./mesh_temp/Th.mesh");
>   savesol("./mesh_temp/Th.sol",Th,iso,order=1);
>   exec("mmg2d_O3 ./mesh_temp/Th.mesh -ls -hmax 0.01 -hausd 0.001 -hmin 0.001");
>   Th=readmesh("./mesh_temp/Th.o.mesh");
>   Th=change(Th,rmInternalEdges=1);
>   Th=trunc(Th,(x-xgi)^2+(y-ygj)^2>R^2, label=9);}

It is work well,

Loïc,

I have found

No… please give credits where credits are due.

Yes sure, sorry, I have forgotten to mention it.
Effectively, Pierre Jolivet proposed this solution.

@prj is for Pierre Jolivet ?

Thanks,

Loïc,

No one in the FreeFEM community is named that… But yes, I’m the person that gave you this code.

Sorry for my mistake, I wanted to say Pierre .

Hello all,

Here is another solution using meshL :


load "msh3"

mesh Th=square(20,20); 
plot(Th,wait=1);

// Parametrization of the circles

int nc=3; // Number of circles
real[int] r=[0.1,0.2,0.1]; // radius of the circles

real[int] xc=[0.15,0.5,0.85]; // center of the circles
real[int] yc=[0.5,0.5,0.5];

int[int] reg=[1,2,3];
int[int] Nc(nc);
Nc=50;

// Border of the circles 

border circles(t=0,2*pi;i){
    x=xc[i]+r[i]*cos(t);
    y=yc[i]+r[i]*sin(t);
    region=reg[i];
}

// meshL

int[int] lsquare=[1,2,3,4];
meshL ThL=extract(Th,refedge=lsquare);

// plot(ThL,dim=2,wait=1);

meshL ThCirclesL=buildmeshL(circles(Nc));

// plot(ThCirclesL,dim=2,wait=1);

ThL=ThL+ThCirclesL;
plot(ThL,dim=2,wait=1);

Th=buildmesh(ThL);
plot(Th,wait=1);

// Truncation along the circles 

func int InCircleQ(real xx, real yy){
    int res=0;
    for(int i=0;i<nc;i++){
        if((xx-xc[i])^2+(yy-yc[i])^2<r[i]^2){
            res=1;
            break;
        }
    }
	return res;
}


Th = trunc(Th,!InCircleQ(x,y), split=1);

plot(Th,wait=1);

I think this solution works only with the FreeFem version 4.9 (and later) where the buildmesh function was generalized to meshL types of mesh.