Get all connected neighbors of each vertex

Jun 27, 2015 at 1:19 PM
Hey there,
I would like to create a adjacency matrix out of the delauney mesh.
For that I need to know all connected neighbors from each vertex.
Is there a method for that or what would be the best approach doing that?

Thanks in advance!

GeoGecco
Coordinator
Jun 27, 2015 at 1:52 PM
Just use the AdjacencyMatrix class in the TriangleNet.Tools namespace. I use it for the Cuthill-McKee renumbering.
Jun 27, 2015 at 2:06 PM
okay great, I did this now: AdjacencyMatrix A = new AdjacencyMatrix(mesh);
How do I get the actual matrix to calculate with. I would like to calculate the laplacian matrix or even set the weights of the adjacency in relation to the vertex distances.
For Matrix calculation I use MathNet Numerics
Coordinator
Jun 27, 2015 at 2:59 PM
void MeshAdjacency(Mesh mesh)
{
    var a = new TriangleNet.Tools.AdjacencyMatrix(mesh);

    var vertices = mesh.Vertices.ToArray();

    var ap = a.AdjacencyRow; // Row pointers
    var ai = a.Adjacency; // Adjacency indices

    int n = vertices.Length;

    for (int i = 0; i < n; i++)
    {
        var v0 = vertices[i]; // Vertex i

        Console.Write("Vertex {0} is adjacent to:", v0.ID);

        for (int j = ap[i]; j < ap[i + 1]; j++)
        {
            var v1 = vertices[ai[j - 1]];

            Console.Write(" {0}", v1.ID);
        }

        Console.WriteLine();
    }
}
Be aware, that any vertex is considered adjacent to itself.

If you are doing finite element analysis, you should consider assembling the matrix element-wise, and not by looping over the nodes.
Marked as answer by GeoGecco on 6/27/2015 at 7:03 AM
Jun 27, 2015 at 3:03 PM
yeah I noticed that in the AdjacencyMatrix class.
Thanks alot and great work!
Jun 28, 2015 at 8:51 AM
well, maybe I have one further question =)
Have you ever used the Math.Net Numerics Library for Matrix calculations?

I now have the Adjacency Matrix wich is like 5100x5100 in size and the calculation of the eigenvectors takes centuries...
I already tried defining the matrix as a sparse matrix but it still keeps hours to compute them.
When I use the same procedure in matlab I get the answer within seconds.

Any suggetions on big matrices?
Coordinator
Jun 28, 2015 at 9:46 AM
Edited Jun 28, 2015 at 9:49 AM
That's because MathNet doesn't implement sparse eigensolvers. I think throwing an exception would be the right thing to do, but MathNet just falls back to the dense algorithm (silently, so the user just wonders why it takes hours ...)

I'm not aware of any sparse eigensolvers for .Net, but I've successfully used ARPACK before (building a native DLL and then PInvoke into the native code). I also started to work on a port of LOBPCG, but it's not finished yet.

If you are interested, please contact me via Codeplex (to get your email address).