Creating an Element-Element Connectivity Array

So for certain features of the hydrodynamic solve, such as a Christensen Q, and ALE/SALE, we need some form of element-element connectivity array. Consider the following mesh fragment:

The aim of the connectivity array is to link cell 13 to its four orthogonal neighbours, 8, 12, 14 and 18. Specifically, however, we want an array of size [4,ncells] where the first index corresponds to the directions down, right, up, left in that order. I.e:

elelconn[1,13] = 12
elelconn[2,13] = 18
elelconn[3,13] = 14
elelconn[4,13] = 8

In order to calculate this array correctly, we first need to look at how GMSH generates the cell-node connectivity. Turns out we have control of this, via the Transfinite Surface input. We'll set up the input file so that it creates the following node ordering (in nodelist):

Here the green numbers show how the nodes are ordered (i.e. indices of nodelist), whilst the red numbers show (again) how we want the edges to be numbered (i.e. indices of elelconn. From this, we can clearly see that, for example, elelconn[1,:] should be set when node 1 matches node 4 of its neighbour, and node 2 matches node 3 of its neighbour, etc. This is easy enough to brute force, and since we are looking at small meshes, that's exactly what we'll do:


    sides = Dict(
        1 => ((1, 4), (2, 3)),
        2 => ((2, 1), (3, 4)),
        3 => ((4, 1), (3, 2)),
        4 => ((1, 2), (4, 3))
    )

    @time @inbounds for cell in 1:ncells
        @views n1 = nodelist[:, cell]
        @inbounds for cell2 in 1:ncells
            @views n2 = nodelist[:, cell2]

            for side in keys(sides)
                p11 = sides[side][1][1]
                p12 = sides[side][1][2]
                p21 = sides[side][2][1]
                p22 = sides[side][2][2]

                if x[n1[p11]] == x[n2[p12]] && x[n1[p21]] == x[n2[p22]]
                    if y[n1[p11]] == y[n2[p12]] && y[n1[p21]] == y[n2[p22]]
                        elelconn[side,cell] = cell2
                    end
                end
            end
        end
    end
 Note: This connectivity is global. I propose to use a separate array to keep track of ALE/SALE blocks, rather than rely on zeros in elelconn.

Comments

Popular posts from this blog

Creating a Julia Executable

Creating a Node-Node Connectivity Array