# Mesh from vector

I have the following code, what am I doing wrong?

``````//------------------Global Mesh---------------------
mesh calP = square(2,2);

int NbTriangles = calP.nt; //number of triangles
int NbVertices = calP.nv; //number of vertices

//-------------------Mesh info---------------------
//-------------------vector: global vertices coord
real[int, int] vertCoordGlobal(NbVertices,2);
for (int i = 0; i < NbVertices; i++){
vertCoordGlobal(i,0) = calP(i).x;
vertCoordGlobal(i,1) = calP(i).y;
}
cout << vertCoordGlobal <<"\n";

//-------------------------vector: nodes in elem K
real[int,int] elemNodesGlobal(NbTriangles,3);
for (int i = 0; i < 3; i++){
for(int j = 0; j < NbTriangles; j++)
elemNodesGlobal(j,i) = int(calP[j][i]);
}
cout << elemNodesGlobal <<"\n";

//-----------------Local Meshes-------------------
mesh[int] Th(NbTriangles);

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

/*cout << coordX0 << " " << coordX1 << " " << coordX2 << "\n";
cout << coordY0 << " " << coordY1 << " " << coordY2 << "\n";
cout << "\n"; */

real[int, int] nodes = [[coordX0, coordY0], [coordX1,coordY1],
[coordX2, coordY2], [coordX0, coordY0]];
border f0(t=0,1){P.x=nodes(t,0);P.y=nodes(t,1); label=0;};
border f1(t=1,2){P.x=nodes(t,0);P.y=nodes(t,1); label=1;};
border f2(t=2,3){P.x=nodes(t,0);P.y=nodes(t,1); label=2;};

Th[K] = buildmesh(f0(2) + f1(2) + f2(2));
}

``````

I’m getting the following error

``````  current line = 53
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 8 ,  mpirank 0

``````

I think in the lines

``````border f0(t=0,1){P.x=nodes(t,0);P.y=nodes(t,1); label=0;};
border f1(t=1,2){P.x=nodes(t,0);P.y=nodes(t,1); label=1;};
border f2(t=2,3){P.x=nodes(t,0);P.y=nodes(t,1); label=2;};
``````

need to be changed to the following:

``````border f0(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=0;};
border f1(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=0;};
border f2(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=0;};
``````

`t` is essentially a real parameter, you cannot use it to index arrays and perform automatic interpolation.