This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Local/global ordering of cell edges and faces (after grid/mesh import)

0 votes

I am trying to understand how grid edges/faces are numbered internally (in order to set boundary conditions on the correct local external edges/faces with the xml domains/mesh_value_collection property). To test I have created a simple 2d xml test grid with six nodes and four triangles

<dolfin>
  <mesh celltype="triangle" dim="2">
    <vertices size="6">
      <vertex index="0" x="0.0" y="0.0" z="0.0"/>
      <vertex index="1" x="1.0" y="0.0" z="0.0"/>
      <vertex index="2" x="0.0" y="1.0" z="0.0"/>
      <vertex index="3" x="1.0" y="1.0" z="0.0"/>
      <vertex index="4" x="0.5" y="0.0" z="0.0"/>
      <vertex index="5" x="0.5" y="1.0" z="0.0"/>
    </vertices>
    <cells size="4">
      <cell index="0" v0="0" v1="5" v2="2"/>
      <cell index="1" v0="0" v1="4" v2="5"/>
      <cell index="2" v0="4" v1="3" v2="5"/>
      <cell index="3" v0="4" v1="1" v2="3"/>
    </cells>
  </mesh>
</dolfin>

Grid http://imgur.com/a/35pFw

3---6---4
|\  |\  |
|1\2|3\4|
|  \|  \|
1---5---2    

And after importing the grid into fenics and inspecting it with

from fenics import *

mesh = Mesh("test.xml")

print "\n cell connectivity:\n"
delements = dict((cell.index(), cell.entities(0)) for cell in cells(mesh))
for element in range(mesh.num_cells()):
  print "   " + repr(element+1) + " : " + str(delements[element]+1)

  print "\n cell edges:\n"
  dfacets = dict((facet.index(), facet.entities(0)) for facet in facets(mesh))
  for facet in range(len(dfacets)):
    print "   " + repr(facet+1) + " : " + str(dfacets[facet]+1)
    print "\n"

    for cell in cells(mesh):
      print "    cell : " + repr(cell.index()+1)
      dfacetsi = dict((faceti.index(), faceti.entities(0)) for faceti in facets(cell))
      for faceti in range(len(dfacetsi)):
        key = dfacetsi.keys()[faceti]
        print "   " + repr(key+1) + " : " + str(dfacetsi[key]+1)

results in

cell connectivity:

1 : [1 3 6]
2 : [1 5 6]
3 : [4 5 6]
4 : [2 4 5]

global edges [vertices]:

1 : [1 3]
2 : [1 5]
3 : [1 6]
4 : [2 4]
5 : [2 5]
6 : [3 6]
7 : [4 5]
8 : [4 6]
9 : [5 6]

this is all fine since I understand that the vertices are ordered with increasing vertex number. However, I cannot find the logic in how the edges are ordered on each cell

local cell and global edges [vertices]:

cell : 1
  local edge 1: global edge 1 : [1 3]
  local edge 2: global edge 3 : [1 6]
  local edge 3: global edge 6 : [3 6]
cell : 2
  local edge 1: global edge 9 : [5 6]
  local edge 2: global edge 2 : [1 5]
  local edge 3: global edge 3 : [1 6]
cell : 3
  local edge 1: global edge 9 : [5 6]
  local edge 2: global edge 7 : [4 5]
  local edge 3: global edge 8 : [4 6]
cell : 4
  local edge 1: global edge 4 : [2 4]
  local edge 2: global edge 5 : [2 5]
  local edge 3: global edge 7 : [4 5]

From reading the Fenics/Dolfin docs and manual I see that local edge 1 should be correlated with local vertices 2 and 3 (edge 2 with vertices 1 and 3 etc.). This does not seem to be the case here since for example cell 1 should have global edge ordering 6-3-1 not 1-3-6. Furthermore, for cells 2 and 3 the edges do neither seem to be ordered with increasing global edge numbering or respect the local edge 1 -> vertices2/3 relation at all.

Is there any clear reference where one can see how the local edges/faces will be ordered (after xml grid import)?

asked Jun 11, 2017 by markusj FEniCS Novice (150 points)
edited Jun 11, 2017 by markusj

Would these links be helpful?
https://fenicsproject.org/qa/12520/efficient-preserve-boundary-numbering-submeshes-generated
https://fenicsproject.org/qa/13906/implementation-a-modified-dg-jump-condition-with-ode

You can label these as physical/facet regions in GMSH and handle them in aggregate based on their labels and convert them to .xml files with dolfin-convert(). Using the ds(n) measure where n is the boundary label you can assign the appropriate boundary conditions.

Thanks for looking into this. I am not using Gmsh though but importing from my own grid format so knowing how fenics orders edges/faces would be useful.

Gotcha--I'm not sure I know enough yet to help beyond that.

1 Answer

0 votes

"Is there any clear reference where one can see how the local edges/faces will be ordered (after xml grid import)?"

--> "UFC Specification and User Manual 1.1" (just google or google scholar the pdf)
--> Chapter 5: Numbering of mesh entities

The ordering of on the fly created meshes (e.g. mesh = UnitCubemesh(3, 3, 3)) or imported meshes (e.g. mesh = Mesh('exported_UCMesh.xml')) is identical (at least for my tests). Local to global ordering always follows the ufl rules, also if you use mpi and distribute your mesh over several processes.

answered Jun 14, 2017 by RR FEniCS User (3,330 points)
...