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

How can I access the local grad of a function?

0 votes

Hello,

I would like to compute the grad of a piecewise linear Lagrange FE function uh on each cell
and to use those values for some calculations.

 W2  = VectorFunctionSpace(mesh, "DG", 0) 
 pgrad_u = project(grad(uh), W2)

How can I use the dofmap and the dof_cells to allocate the dofs on the cell and then the values of pgrad_u on that cell?

The following does not work:

 dm = [W2.sub(i).dofmap() for i in range(2)]
 for cell in cells(mesh):
      for dms_i in enumerate(dms):
           vdof1 = dms_i.cell_dofs(cell.index())

The error message is that

AttributeError: 'tuple' object has no attribute 'cell_dofs'

Can you please help me?

Thank you in advance,
Fotini

asked Sep 30, 2014 by fotini.karakatsani FEniCS Novice (500 points)

There's a bug in your example code:

  for dms_i in enumerate(dms):

Try this instead:

  for i, dms_i in enumerate(dms):

Or just:

  for dms_i in dms:
...