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

Accessing the cell index of a given dof

+2 votes

Hello,

I found that it is possible to access the degrees of freedom related to a given cell using:

V = FunctionSpace(mesh, 'DG', 1)
subdomains = MeshFunction('size_t', mesh, 2)

for cell_no in range(len(subdomains.array())):
    dofs = V.dofmap().cell_dofs(cell_no)
    print dofs

But I could not figure out how to find the cell associated to a degree of freedom.

Does anybody know how to do that?

Thanks a lot!
Vincent

asked Sep 15, 2014 by V_L FEniCS User (4,440 points)

1 Answer

+1 vote
 
Best answer

Hi, with DG spaces you could just transpose the mapping cell $\mapsto$ dofs

from dolfin import *

mesh = UnitSquareMesh(20, 20)
V = FunctionSpace(mesh, 'DG', 1)

dofmap = V.dofmap()
dof_to_cell = [cell for cell in range(mesh.num_cells())
               for dof in dofmap.cell_dofs(cell)]
print 'Dof 2 is in cell', dof_to_cell[2] 
answered Sep 16, 2014 by MiroK FEniCS Expert (80,920 points)
selected Sep 17, 2014 by V_L

Excellent, thanks a lot!!

...