[Gmsh] Adjacent elements in finite volume formulation

Christophe Geuzaine cgeuzaine at uliege.be
Sat Mar 30 14:37:58 CET 2019

```Hi guys,

I think I probably have said this before: each numerical method will have its own needs: you might want neighbouring elements connected by a node, an edge or a face; you might want a single layer or multiple layers; you might want to include elements of lower dimension (boundaries) or not; you might want to go through geometrical entities, or mesh partitions, or not... and so on... So it's really better to compute this in your code to suit your needs.

Here's a small example in Python, using the Gmsh API to compute neighbouring tetrahedra connected by a face (you can make this code more compact, but this is to illustrate how simple it is):

```
import gmsh

gmsh.initialize()

gmsh.model.occ.synchronize()
gmsh.model.mesh.generate(3)

# get tets and faces
tets, _ = gmsh.model.mesh.getElementsByType(4)
faces = gmsh.model.mesh.getElementFaceNodes(4, 3)

# compute face x tet incidence
fxt = {}
for i in range(0, len(faces), 3):
f = tuple(sorted(faces[i:i+3]))
t = tets[i/12]
if not f in fxt:
fxt[f] = [t]
else:
fxt[f].append(t)

# compute neighbors by face
txt = {}
for i in range(0, len(faces), 3):
f = tuple(sorted(faces[i:i+3]))
t = tets[i/12]
if not t in txt:
txt[t] = set()
for tt in fxt[f]:
if tt != t:

print("neighbors by face: ", txt)

gmsh.finalize()

```

We could add this in the demos/api directory if you think it's useful.

Christophe

-------------- next part --------------
A non-text attachment was scrubbed...
Name: neighbors.py
Type: text/x-python-script
Size: 777 bytes
Desc: not available
URL: <http://onelab.info/pipermail/gmsh/attachments/20190330/f7108e7b/attachment.py>
-------------- next part --------------

> On 30 Mar 2019, at 10:51, Jeremy Theler <jeremy at seamplex.com> wrote:
>
> Hey Yuri
>
> I asked the same question back in 2011:
>
> http://onelab.info/pipermail/gmsh/2011/006878.html
>
> All I got is a loose reference to Lohner's book:
>
> http://onelab.info/pipermail/gmsh/2011/006881.html
>
> Someone asked it again in 2012 with no response:
>
> http://onelab.info/pipermail/gmsh/2012/007480.html
>
> I went in again in 2013, again with no luck:
>
> http://onelab.info/pipermail/gmsh/2013/008183.html
>
> Something similar came back in 2014:
>
> http://onelab.info/pipermail/gmsh/2014/008808.html
>
> And again FVM:
>
> http://onelab.info/pipermail/gmsh/2014/008908.html
> http://onelab.info/pipermail/gmsh/2014/009237.html
>
> In 2017 I already mentioned that this was unsolved:
>
> http://onelab.info/pipermail/gmsh/2017/011248.html
>
> One more time in 2018:
>
> http://onelab.info/pipermail/gmsh/2018/012120.html
>
>
> So... is this enough to have something in Gmsh's core?
> I proposed to add an optional section like \$ElementNeighbour\$ or something like this, listing the tag of the neighbours each elements has (including surface elements for volumetric elements so boundary conditions in FEM can be more efficiently written). I have somewhere a tool that reads a .msh and adds such a section, if somebody is interested I can dig into my archives and prepare a repository.
>
> I bet the neighbour list can be generated in O(n) inside Gmsh, which should beat any complex O(n log n) or naive O(n^2) implementention outside Gmsh.
>
> Regards
> --
> jeremy theler
> www.seamplex.com
>
>
> On Fri, 2019-03-29 at 16:00 -0300, Yuri Barros wrote:
>> Hi all,
>>
>> I am trying to optimize my finite volume formulation and one thing that is taking too much computational time is to find adjacent cells. Is there any way I can extract from GMSH the adjacent elements of a given element in the local face order? Or is there any algorithm that people use routinely for this task?
>>
>> _______________________________________________
>> gmsh mailing list
>>
>> gmsh at onelab.info
>> http://onelab.info/mailman/listinfo/gmsh
> _______________________________________________
> gmsh mailing list
> gmsh at onelab.info
> http://onelab.info/mailman/listinfo/gmsh

?
Prof. Christophe Geuzaine
University of Liege, Electrical Engineering and Computer Science
http://www.montefiore.ulg.ac.be/~geuzaine

```