# Strange error on FreeFem++

**URL:** <https://community.freefem.org/t/strange-error-on-freefem/2426>\
**Category:** General Discussion\
**Created:** [May 1, 2023, 8:10pm UTC](https://community.freefem.org/t/strange-error-on-freefem/2426 "2023-05-01T20:10:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![larismartins](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/larismartins/32/2712_2.png) [@larismartins](https://community.freefem.org/u/larismartins)\
**Post date:** [May 1, 2023, 8:10pm UTC](https://community.freefem.org/t/strange-error-on-freefem/2426/1 "2023-05-01T20:10:38Z")

</div>

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

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

```

with coarseMesh = 3  
it gives

```auto
  -- 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?

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [May 1, 2023, 9:11pm UTC](https://community.freefem.org/t/strange-error-on-freefem/2426/2 "2023-05-01T21:11:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [May 3, 2023, 9:39am UTC](https://community.freefem.org/t/strange-error-on-freefem/2426/3 "2023-05-03T09:39:39Z")

</div>

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 .

---

<div class="post-metadata">

**Author:** ![larismartins](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/larismartins/32/2712_2.png) [@larismartins](https://community.freefem.org/u/larismartins)\
**Post date:** [May 10, 2023, 12:19am UTC](https://community.freefem.org/t/strange-error-on-freefem/2426/4 "2023-05-10T00:19:38Z")

</div>

it’s from a local mesh

```auto
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;
}

```

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [May 10, 2023, 8:07am UTC](https://community.freefem.org/t/strange-error-on-freefem/2426/5 "2023-05-10T08:07:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Loic](https://avatars.discourse-cdn.com/v4/letter/l/e9c0ed/32.png) [@Loic](https://community.freefem.org/u/Loic)\
**Post date:** [May 10, 2023, 11:38am UTC](https://community.freefem.org/t/strange-error-on-freefem/2426/6 "2023-05-10T11:38:41Z")

</div>

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:

```auto
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,
