Strange error on FreeFem++

There is a strange behavior on FreeFem++, I’m running my code and for a mesh with h = 0.176777, that means

int globalH = 2^coarseMesh;
mesh calP = square(globalH,globalH);

with coarseMesh = 3
it gives

  -- Square mesh : nb vertices  =81 ,  nb triangles = 128 ,  nb boundary edges 32
  --  mesh:  Nb of Triangles =      1, Nb of Vertices 3
Segmentation fault (core dumped)

but for any other value of coarseMesh it runs without problems, I tried with 0, 1, 2, 4, 5 and 6 and it’s ok, but specifically for 3 it giver segmentarion fault.

Anyone has any idea what might be?

Can you post a complete example? I may not like whatever is the 1 triangle
mesh.
Running just what you posted worked but only made one mesh.

Just a small remark,

line
– Square mesh : nb vertices =81 , nb triangles = 128 , nb boundary edges 32
come from
mesh calP = square(globalH,globalH);
but the line
– mesh: Nb of Triangles = 1, Nb of Vertices 3
come from with script line ???

the only output is in function :

const Fem2D::Mesh bamg2msh( bamg::Triangles tTh,bool renumbering)

so we need a part of you code if you want idea .

it’s from a local mesh

for(int K = 0; K < NbTriangles; K++){

 real coordX0, coordX1, coordX2;
 real coordY0, coordY1, coordY2;

 for(int i = 0; i< NbVertices; i++){
   if(elemNodesGlobal(K,0) == i){
    coordX0 = calP(i).x;
    coordY0 = calP(i).y;
   }
   if(elemNodesGlobal(K,1) == i){
    coordX1 = calP(i).x;
    coordY1 = calP(i).y;
   }
   if(elemNodesGlobal(K,2) == i){
    coordX2 = calP(i).x;
    coordY2 = calP(i).y;
   }
 }


 real[int, int] nodes = [[coordX0, coordY0], [coordX1,coordY1],
                          [coordX2, coordY2]];
 
 //cout << nodes << "\n";

 border f0(t=0,1){P.x=nodes(2,0)*t + nodes(1,0)*(1-t);P.y=nodes(2,1)*t + nodes(1,1)*(1-t); label=11;};
 border f1(t=0,1){P.x=nodes(0,0)*t + nodes(2,0)*(1-t);P.y=nodes(0,1)*t + nodes(2,1)*(1-t); label=22;};
 border f2(t=0,1){P.x=nodes(1,0)*t + nodes(0,0)*(1-t);P.y=nodes(1,1)*t + nodes(0,1)*(1-t); label=33;};
 
 Th[K] = buildmesh(f0(1) + f1(1) + f2(1));
 Th[K] = trunc(Th[K], abs(u0 -K) < 1e-5, split=2^subMesh);

 int NbTrianglesLocal = Th[K].nt;
}

What is u0?
I guess if you could attach the complete file that may help.
Certainly the trunc would be suspicious.

Hi,

Why do you extract all the vertices to rebuild after the triangle K, instead of extract directly the the triangle K from the global mesh using the function trunc ?

You can do something like this:

mesh calP = square(globalH,globalH);
fespace Tri(calP, P0);
Tri ChiK; 
for(int k = 0; k < NbTriangles; k++){
    ChiK[][k]=1;    // P0 function used to mark the element i
    Th[k]=trunc(calP, ChiK>0.1, split=2^subMesh);      // a mesh made of only one triangle with  refinement 
    ChiK[][k]=0; 
}

Best regards,

Loïc,