# Edge to element

Hello everyone,

how do I create an edge to element matrix using FreeFem++?
So, basically, given the edge number, I would like to know the elements that share that edge. Is it possible?

yes,

the finite element P0edge build a edge, and

``````// the corresponding edge in the adjacent triangle

``````

yeah, i did that

``````//----------------Numbering edges-------------------
fespace L0(calP, P0edge);
int ndofL0K = L0.ndofK;

real[int, int] edgesinK(NbTriangles, ndofL0K);
for(int i=0; i<NbTriangles; i++){
for(int j=0; j<ndofL0K; j++){
edgesinK(i,j) = L0(i,j);
}
}
cout << edgesinK << "\n";
``````

but then I tried this and it’s not working

``````for(int i=0; i<L0.ndofK; i++){
for(int K=0; K<NbTriangles; K++){
// non adjacent triangle return the same
cout << K << "\n";
}
cout << K << "\n";
}

}
}
``````

Hello,

The problem is that the value of “i” is modified when you do `calP[K].adj(i)`.

Just copy the value of `i` in a new variable `j`.

``````for(int i=0; i<L0.ndofK; i++){
for(int K=0; K<NbTriangles; K++){
// non adjacent triangle return the same
int j = i;
cout << K << "\n";
}