Neighborhood information in Julia mesh Libraries

I have a mesh in msh format from Gmsh. I am importing it to Julia via Gmsh.jl. I need information about the neighbours of each cell in the grid. However none of the Julia libraries seem to provide that information. I have looked into Mesh.jl, Gridap.jl and MeshIO.jl. Does anyone know a library in julia that list the neighbors of all the cells?

I know it is not that difficult to write from the info Gmsh provides, however this is such a basic necessity for FVM and FEM methods to calculate flux that I would guess that such a function should exist.

MeshCore.jl

We do provide this as basic functionality. Take a look at the topological relations:

https://juliageometry.github.io/Meshes.jl/stable/meshes.html#Relations

Or if you just need the adjacency matrix you can use the adjacencymatrix function implemented in terms of these relations:

MWE:

julia> using Meshes

julia> grid = CartesianGrid(10,10)
10×10 CartesianGrid{2,Float64}
  minimum: Point(0.0, 0.0)
  maximum: Point(10.0, 10.0)
  spacing: (1.0, 1.0)

julia> adjacencymatrix(grid)
100×100 SparseArrays.SparseMatrixCSC{Int64, Int64} with 360 stored entries:
⠪⣢⡀⠀⠑⢄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠈⠪⡢⡀⠀⠘⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠑⢄⠀⠈⠪⡢⡀⠀⠉⢆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠈⠒⢄⠀⠈⠺⡢⡀⠀⠑⢢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠣⢄⠀⠈⠠⡦⡀⠀⠑⠤⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠱⣀⠀⠈⠪⣢⡀⠀⠘⢄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠑⡄⠀⠈⠠⡢⡀⠀⠈⢆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠒⢄⠀⠈⠺⡢⡀⠀⠑⢢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠢⢄⠀⠈⠊⡤⡀⠀⠑⠤⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠱⣀⠀⠈⠪⣢⡀⠀⠑⢄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⡄⠀⠈⠊⡠⡀⠀⠘⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠑⢄⠀⠈⠫⡢⡀⠀⠉⢆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠒⢄⠀⠈⠚⡠⡀⠀⠑⠢⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠣⢄⠀⠈⠪⡦⡀⠀⠑⠤⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠱⡀⠀⠈⠪⠂⡀⠀⠘⢄⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠑⡄⠀⠈⠫⡢⡀⠀⠉⢆⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠒⢄⠀⠈⠺⠂⡀⠀⠑⢢⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠣⢄⠀⠈⠪⡦⡀⠀⠑⠤⡀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠱⣀⠀⠈⠪⡢⡀⠀⠑⢄
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⡄⠀⠈⠪⡢⡀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠑⢄⠀⠈⠫⡢
 
1 Like

I apologise for not reading the documentation well enough. However, I must admit it’s not that obvious to someone who is not really familiar with the package why this functionality must be under Relations and not under Neighbors.

Be that as it may, what I wanted to know more about, is the interoperability. Is there a way to import a mesh to Mesh.jl. I did it via

connec = connect.(connec, Ngon)
mesh = SimpleMesh(points, connec)

And that mesh it seems is of a different type than Mesh so the adjacencymatrix(mesh) doesn’t work for a SimpleMesh. Is there a different way to import or convert to Mesh type or any information regarding how to access the information inside Adjacency{D}(t) would be really helpful.

Thank you!

The SimpleMesh constructor has an option to build topological relations. If you activate this option the adjacencymatrix should work.

Here is the docstring:

https://juliageometry.github.io/Meshes.jl/stable/meshes.html#Meshes.SimpleMesh

The option I mentioned is relations=true

Yes, I tried that. It seems that function is incomplete in some sense. It gets stuck here.

Oh sorry, we did not implement this case yet. Feel free to try to implement it yourself in terms of the relations already defined or if you are familiar with the half-edge topology data structure.

@mm-crj can you open an issue with a MWE, a small mesh where the adjacency matrix is not implemented? We can try to address the issue over the week.

I will try to create a minimum working example. I think what doesn’t work is the adjacency of the cells/elements for a half edge topology. Although the implementation seems doable(as I already have a half working example of my own), I am not sure if I can afford the time to learn the data structures.

1 Like

The functionality is now available in the master branch of Meshes.jl, i.e., the adjacencymatrix function now works with half-edge topologies and general 2-manifold meshes.

Thank you for the quick fix!