[Gmsh] Adjacent elements in finite volume formulation

Jose Paulo Moitinho de Almeida moitinho at civil.ist.utl.pt
Mon Apr 1 11:20:34 CEST 2019


In my matlab code I have a class that reads a msh file and constructs a data 
structure that allows arbitrary queries for accessing all the topological 
information of arbitrary meshes.
Details at https://doi.org/10.1007/s00366-015-0395-0
For example
[ face_cells, face_edges, face_verts ] = prob.mesh.get_cev_f(face);
or
[ vert_elems, vert_faces, ~ ] = prob.mesh.get_cfe_v(vert);

I had thought about pythonising it and had this fundamental doubt whether to 
have a completely separated structure or to use gmsh internals. Any pointers/
suggestions?

Regards

ZP

On domingo, 31 de março de 2019 20:20:10 WEST Christophe Geuzaine wrote:
> > On 31 Mar 2019, at 12:10, Jeremy Theler <jeremy at seamplex.com> wrote:
> > 
> > Hi Christophe
> > 
> > Fair enough. The Python code is faster than I thought it would be (mine
> > is slightly faster, including the computation of the faces' outward
> > normals but I think because it is pure C).
> 
> Sure. Note that the Python version could also be made quite a bit faster -
> but here I just went for simplicity.
> > In any case, creating this snippet of code is beyond regular-users
> > scope. Thanks for adding it to the repository. Now any addition such as
> > handling other elements (i.e. hexa) and finding also lower-dimension
> > neighbors (i.e. boundary conditions) can be made by regular-users (i.e.
> > by me).
> > 
> > 
> > A follow up question: how would you find neighbors in prisms, where not
> > every face has the same number of nodes?
> 
> Just call (7 is prism; 3 or 4 will get you tri or quad faces):
> 
> ```
> tri_face_nodes = gmsh.model.mesh.getElementFaceNodes(7, 3)
> quad_face_nodes = gmsh.model.mesh.getElementFaceNodes(7, 4)
> ```
> 
> then the logic is the same.
> 
> Cheers,
> 
> Christophe
> 
> > Regards
> > --
> > jeremy
> > 
> > On Sat, 2019-03-30 at 14:37 +0100, Christophe Geuzaine wrote:
> >> 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.add("my test model");
> >> gmsh.model.occ.addBox(0,0,0, 1,1,1);
> >> 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:
> >>             txt[t].add(tt)
> >> 
> >> print("neighbors by face: ", txt)
> >> 
> >> gmsh.finalize()
> >> 
> >> ```
> >> 
> >> We could add this in the demos/api directory if you think it's
> >> useful.
> >> 
> >> Christophe
> >> 
> >>> 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?
> >>>> 
> >>>> Thanks in advance!
> >>>> _______________________________________________
> >>>> 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
> 
>> Prof. Christophe Geuzaine
> University of Liege, Electrical Engineering and Computer Science
> http://www.montefiore.ulg.ac.be/~geuzaine
> 
> 
> 
> 
> _______________________________________________
> gmsh mailing list
> gmsh at onelab.info
> http://onelab.info/mailman/listinfo/gmsh





More information about the gmsh mailing list