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

Bug in shared_entities for mixed function space?

0 votes

This is a simplification of the question I posted here. I thought it deserved its own post since I'm feeling more sure that this is some sort of bug. The printout of the small code attached is:

1 0 8
1 3 7
1 5 11
0 1 5
0 2 8
0 4 12.

Shouldn't the global indices of the shared dofs of processor 0 match those of processor 1?

from dolfin import *
import numpy as np

comm = mpi_comm_world()
mpirank = MPI.rank(comm)

mesh = UnitSquareMesh(2, 2)
Vr = FunctionSpace(mesh, "CG", 1)
Vi = FunctionSpace(mesh, "CG", 1)
V = Vr * Vi

meshtopo = mesh.topology()
dofmap = V.dofmap()

v2d = dofmap.dofs(mesh, 0)
v2dg = np.array([dofmap.local_to_global_index(i) for i in v2d])
shared_entities = meshtopo.shared_entities(0)

for k, n in shared_entities.items():
    print mpirank, k, v2dg[k]
asked Jul 4, 2016 by brk888 FEniCS Novice (990 points)

1 Answer

0 votes

The line

shared_entities = meshtopo.shared_entities(0)

only gives you the shared vertex indices, not the local dof indices on the shared vertices. In order to get the intended output, you have to get the local dof indices before mapping them to global dof indices.

answered Jul 4, 2016 by Magne Nordaas FEniCS Expert (13,820 points)

Thank you for your response. I think I have performed the map correctly. v2dg contains global dof indices in local vertex ordering so that v2dg[k] where k is a vertex index gives a global dof index. Another way to perform this test that gives the same output without adding the complexity of the v2dg map is the following:

from dolfin import *
import numpy as np

comm = mpi_comm_world()
mpirank = MPI.rank(comm)

mesh = UnitSquareMesh(2, 2)
Vr = FunctionSpace(mesh, "CG", 1)
Vi = FunctionSpace(mesh, "CG", 1)
V = Vr * Vi

meshtopo = mesh.topology()
dofmap = V.dofmap()

v2d = dofmap.dofs(mesh, 0)
shared_entities = meshtopo.shared_entities(0)

for k, n in shared_entities.items():
    print mpirank, v2d[k], dofmap.local_to_global_index(v2d[k])

You are incorrectly assuming that the local vertex ordering coincides with the local dof ordering. This is not the case - in fact you have two dofs per vertex.

edit: Try the following changes

v2d = dofmap.dofs(mesh, 0).reshape(dofmap.local_dimension("all")/2, 2)
for k, n in shared_entities.items():
    print mpirank, v2d[k], map(dofmap.local_to_global_index, v2d[k])

Ah, OK. So each k, k+1 entry in the dofmap for a mixed function space corresponds to a single vertex and not each k, k+N!?

...