What's wrong with my code?

#1

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 < diameter1e-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) which has a few typos and is somewhat confusing.

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

#2

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.

(Simon Garnotel) #3

Hi,

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

In FreeFEM, meshes are build from borders like in mesh generation documentation, 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 or with:

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!

1 Like
#4

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.

(Simon Garnotel) #5

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

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

Thanks a lot for your feedback

1 Like
#6

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