Mesh connectivity details

I want to be able to:

  • Give point coordinates and as a result get the finite element (or at least its index).
  • Give mesh vertice and as result get list of element indexes, containing this vertice
  • Give the final element index as return the list of vertices.

So ultimately I am looking for something like whoInElement function but not only for the boundary elements as done in the example:

120     int NbBoundaryElements = Th.nbe;
121     for (int k = 0; k < NbBoundaryElements; k++)
122         cout << k << " : " << Th.be(k)[0] << " " << Th.be(k)[1]
123              << " , label " << Th.be(k).label
124              << ", triangle " << int(Th.be(k).Element)
125              << " " << Th.be(k).whoinElement << endl;

Example

Assume a simple square mesh. For each computational point, I must be able to determine the corresponding finite element and vice-versa, for each element I must be able to know which points are within or at least the mesh vertices.

You want for each vertices of the mesh the list of triangle contening this vertex:

// you can do that in few line of code:

mesh Th=square(4,4);

int[int] headv(Th.nv), next(Th.nt*3);

headv=-1; //
for(int k =0;k< Th.nt; ++k)
for(int i =0;i< 3; ++i)
{ int v = Th[k][i]; // vertex number
next[3k+i] = headv[v];
headv[v]= 3
k+i;
}
// show the list of triangle of vertex v
for(int v=0; v<Th.nv;++v)
{ cout << v << " : ";
for(int p=headv[v]; p >=0; p=next[p])
{
int k = p/3, i = p%3;
assert( Th[k][i]==v); // check …
cout << k << " " ;
}
d a acout << endl;
}

you can have of explanation in file:

section 9.7 page 111 (sorry in french).

1 Like