# What's wrong with my code?

**URL:** <https://community.freefem.org/t/whats-wrong-with-my-code/17>\
**Category:** General Discussion\
**Created:** [April 2, 2019, 10:01pm UTC](https://community.freefem.org/t/whats-wrong-with-my-code/17 "2019-04-02T22:01:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![LST229](https://avatars.discourse-cdn.com/v4/letter/l/7cd45c/32.png) [@LST229](https://community.freefem.org/u/LST229)\
**Post date:** [April 2, 2019, 10:01pm UTC](https://community.freefem.org/t/whats-wrong-with-my-code/17/1 "2019-04-02T22:01:13Z")

</div>

Sorry if this is not the right place to ask this but the following minimal code gets me an error:

```
real
MaxX = 10;
real
DiscretizationX = 0.5;
real
SideLength = 2. * MaxX;

real
MeshResolution = floor (SideLength / DiscretizationX + 0.5);

real[int]
BorderVertexesX (5);
real[int]
BorderVertexesY (5);

BorderVertexesX [0] = - MaxX;
BorderVertexesY [0] = MaxX;
BorderVertexesX [1] = - MaxX;
BorderVertexesY [1] = - MaxX;
BorderVertexesX [2] = MaxX;
BorderVertexesY [2] = - MaxX;
BorderVertexesX [3] = MaxX;
BorderVertexesY [3] = MaxX;
BorderVertexesX [4] = - MaxX;
BorderVertexesY [4] = MaxX;

border
SquareBorder (t = 0, 4)
{
 x = BorderVertexesX [t];
 y = BorderVertexesY [t];
 label = 1;
};

plot (SquareBorder (MeshResolution), wait = 1);

cout << "plot of border done" << endl;

mesh
DomainMesh = buildmesh (SquareBorder (MeshResolution));

```

The (part of the output and) error message is:  
plot of border done  
current line = 37  
Exec error : Error points border points to close \< diameter_1e-7  
– number :1  
Exec error : Error points border points to close \< diameter_1e-7  
– number :1  
err code 7 , mpirank 0

I’ve found only two similar questions on the internet, once was an issue with the orientation which is not the case here, another is a question on some forum with an identical error message but no answer.

The plot of the border seems fine.

I’m trying to use the indications from the documentation (at [https://doc.freefem.org/references/types.html#border](https://doc.freefem.org/references/types.html#border)) which has a few typos and is somewhat confusing.

The aim is to use more complicated geometry eventually (than the square).

---

<div class="post-metadata">

**Author:** ![LST229](https://avatars.discourse-cdn.com/v4/letter/l/7cd45c/32.png) [@LST229](https://community.freefem.org/u/LST229)\
**Post date:** [April 3, 2019, 2:31pm UTC](https://community.freefem.org/t/whats-wrong-with-my-code/17/2 "2019-04-03T14:31:05Z")

</div>

Turns out I misinterpreted the documentation. I thought there was a system that could just produce the border using its vertexes as input. Now that sounds ridiculous because I don’t see how Freefem++ would be able to make the difference with numerical function input and list of vertexes.

But the documentation makes it seem like the t should be an integer index in that example and not a real parameter. Not sure what is actually meant in this example.

---

<div class="post-metadata">

**Author:** ![simon.garnotel](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/simon.garnotel/32/11_2.png) [@simon.garnotel](https://community.freefem.org/u/simon.garnotel)\
**Post date:** [April 3, 2019, 2:58pm UTC](https://community.freefem.org/t/whats-wrong-with-my-code/17/3 "2019-04-03T14:58:26Z")

</div>

Hi,

This is the good place, you are just the first to use the new FreeFEM forum 🙂

In FreeFEM, meshes are build from borders like in [mesh generation documentation](https://doc.freefem.org/documentation/mesh-generation.html#border), using a parametric description of a curve.

The parameter `t`, which is a dummy variable (variable name is not important, see border like a function definition), has not a real type.

To build a square, you can use directy the [square](https://doc.freefem.org/documentation/mesh-generation.html#square) or with:

```auto
real MaxX = 10.;
real DiscretizationX = 0.5;
real SideLength = 2. * MaxX;
real MeshResolution = floor (SideLength / DiscretizationX + 0.5);

border b1(t=-MaxX, MaxX){x=t; y=-MaxX; label=1;}
border b2(t=-MaxX, MaxX){x=MaxX; y=t; label=1;}
border b3(t=MaxX, -MaxX){x=t; y=MaxX; label=1;}
border b4(t=MaxX, -MaxX){x=-MaxX; y=t; label=1;}

mesh Th = buildmesh(b1(MeshResolution) + b2(MeshResolution) + b3(MeshResolution) + b4(MeshResolution));
plot(Th);

```

I do not know exactly why your script failed, but I think non-smooth curve is not a good idea.

Hope this help, if you have other questions, do not hesitate!

---

<div class="post-metadata">

**Author:** ![LST229](https://avatars.discourse-cdn.com/v4/letter/l/7cd45c/32.png) [@LST229](https://community.freefem.org/u/LST229)\
**Post date:** [April 3, 2019, 7:49pm UTC](https://community.freefem.org/t/whats-wrong-with-my-code/17/4 "2019-04-03T19:49:54Z")

</div>

Thanks for your answer.

My mistake is to have interpreted the example given in the documentation:

```
border b(t=0, vectorX.n-1){x=vectorX[t]; P.x=vectorY[t];}

```

as a border defined uniquely by its vertexes. Turns out this doesn’t work like that and have to build all the parametrized curves.

Tbh I think this part of the documentation should be improved as there seems to be a typo there (shouldn’t this be P.y instead of P.x?). And that part isn’t very clear.

If you feed a sequence of points (in the way given by the example) to border it won’t interpolate them, it will just take the integer part of t use this as an index. Which is why this gives points to[o] close because they are repeated many times when the step wrt t is small.

---

<div class="post-metadata">

**Author:** ![simon.garnotel](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/simon.garnotel/32/11_2.png) [@simon.garnotel](https://community.freefem.org/u/simon.garnotel)\
**Post date:** [April 4, 2019, 12:09pm UTC](https://community.freefem.org/t/whats-wrong-with-my-code/17/5 "2019-04-04T12:09:52Z")

</div>

Exactly, I just fixed this typo. The correct instruction is:

```auto
border b(t=0, vectorX.n-1){P.x=vectorX[t]; P.y=vectorY[t];}

```

This part of the documentation is really new, so there is some mistakes in it. If you are interrested to improve it, you can do a PR on the [Github repository](https://github.com/FreeFem/FreeFem-doc)

Thanks a lot for your feedback

---

<div class="post-metadata">

**Author:** ![LST229](https://avatars.discourse-cdn.com/v4/letter/l/7cd45c/32.png) [@LST229](https://community.freefem.org/u/LST229)\
**Post date:** [April 5, 2019, 5:07pm UTC](https://community.freefem.org/t/whats-wrong-with-my-code/17/6 "2019-04-05T17:07:12Z")

</div>

I might consider proposing some improvements to the doc. I’ll see if I get the time. Thanks for proposing.
