Indices of cells and facets in parallel

Hello,

When I access facets and cells in parallel, their indices are not global but the one in each process. How can I access the global index?

The code I run is:

from dolfin import *

parameters['ghost_mode'] = 'shared_facets'

N = 2
mesh = UnitSquareMesh(N,N)

for c in cells(mesh):
    for f in facets(c):
        print(c.index(), f.index())

Here is the ouput in serial:

0 4
0 2
0 0
1 7
1 2
1 1
2 6
2 5
2 3
3 10
3 5
3 4
4 11
4 9
4 7
5 14
5 9
5 8
6 13
6 12
6 10
7 15
7 12
7 11
And here is the output with mpirun -n 2 python3.8 test_parallel.py:
0 3
0 1
0 0
0 3
0 1
0 0
1 4
1 4
1 1
1 2
1 1
1 2
2 5
2 6
2 5
2 6
2 4
2 4
3 8
3 8
3 6
3 7
3 6
3 7

I use dolfin 2019.1.0 on ubuntu.

Maybe this post will be helpful, although it is given in dolfinx. Gather solutions in parallel in FEniCSX - #2 by dokken

How about:

from dolfin import *

parameters['ghost_mode'] = 'shared_facets'

N = 2
mesh = UnitSquareMesh(N, N)

tdim = mesh.topology().dim()
mesh.init(tdim, tdim - 1)
c_to_f = mesh.topology()(tdim, tdim-1)
for c in cells(mesh):
    facets = c_to_f(c.index())
  
    if MPI.comm_world.size != 1:
        facets = [Facet(mesh, facet).global_index() for facet in facets]
    print(MPI.comm_world.rank, c.global_index(), facets)
1 Like

That seems to work. I did not know about the global_index function.