Connectivity matrix in Finite Element Method in Triangular elements

Imagine a simple triangular base mesh in finite element method with an unknown number of elements (varying by the user). How can connectivity matrix be coded to be generated automatically?

• What do you mean by "triangular base mesh"? What do you mean by "generated automatically"? I suggest adding a picture. – Bill Greene Sep 8 '18 at 18:36
• automatically means mentioned matrix generated by the code – user1482636 Sep 8 '18 at 18:50
• It's a bit unclear what do you want to get automatically. With a properly generated mesh (say done by GMSH or any other meshing utility), you'll get the list of vertices and list of elements (say, triangles) that consist of those vertices. What connectivity and for what purpose do you want to get? – Anton Menshov Sep 8 '18 at 19:03
• like connect matrix in scicomp.stackexchange.com/questions/11495/… – user1482636 Sep 8 '18 at 19:03
• In triangular mesh each element has 3 vertices. so in the connectivity matrix, we should have the number of vertices as a row for each element – user1482636 Sep 8 '18 at 19:10

A proper generated finite-element mesh comprises both the mesh vertices, as well as the elements that consist of those vertices – thus, a connectivity matrix.

For example, see the basic GMSH geometry file that describes a 1-meter square in 2D centered at $(0,0)$.

Square.geo:

cl = 0.5;
Point(1) = {0.5,0.5,0.,cl};
Point(2) = {-0.5,0.5,0.,cl};
Point(3) = {-0.5,-0.5,0.,cl};
Point(4) = {0.5,-0.5,0.,cl};

Line(1) = {1,2};
Line(2) = {2,3};
Line(3) = {3,4};
Line(4) = {4,1};
Line Loop(1) = {1,2,3,4};
Surface(1) = {1};
Physical Surface(1) = {1};


This geometry description results in the following mesh (density of the mesh in this example is controlled by characteristic length cl). Notice, the mesh file has the following sections:

1. Header in $MeshFormat (mesh file version and other auxiliary info) 2. Mesh element vertices in $Nodes (id, $x$, $y$, $z$)
3. Triangles in $Elements (id, 4 numbers that do not mean a lot for this discussion, vert1, vert2, vert3). This is pretty much the connectivity matrix you are looking for. Square.msh: $MeshFormat
2.2 0 8
$EndMeshFormat$Nodes
13
1 0.5 0.5 0
2 -0.5 0.5 0
3 -0.5 -0.5 0
4 0.5 -0.5 0
5 1.376398994779038e-12 0.5 0
6 -0.5 1.376398994779038e-12 0
7 -1.376398994779038e-12 -0.5 0
8 0.5 -1.376398994779038e-12 0
9 0 0 0
10 -0.2499999999996558 0.2500000000003442 0
11 0.2500000000003441 0.2499999999996558 0
12 -0.2500000000003442 -0.2499999999996558 0
13 0.2499999999996559 -0.2500000000003442 0
$EndNodes$Elements
16
1 2 2 1 1 10 5 2
2 2 2 1 1 10 6 9
3 2 2 1 1 6 10 2
4 2 2 1 1 5 10 9
5 2 2 1 1 5 11 1
6 2 2 1 1 8 11 9
7 2 2 1 1 11 8 1
8 2 2 1 1 11 5 9
9 2 2 1 1 12 6 3
10 2 2 1 1 12 7 9
11 2 2 1 1 7 12 3
12 2 2 1 1 6 12 9
13 2 2 1 1 13 7 4
14 2 2 1 1 13 8 9
15 2 2 1 1 8 13 4
16 2 2 1 1 7 13 9
\$EndElements


So, a proper finite-element generation utility (GMSH here is just an example and there are many other very good alternatives) gives you the connectivity matrix; otherwise, your mesh is not properly defined anyway.

Now, the process of how to write a mesh-generating software yourself (which you should not do, unless you have very very good reasons) is out-of-topic for this discussion.

• Thanks, but as it possible please give me some sources about mesh generation algorithm, at least for uniform triangular ones – user1482636 Sep 9 '18 at 20:38