Grad(u) to numpy array

Please specify what you mean by it doesn’t work for you? Does it throw an error?

Also please format your code using 3x` encapsulation, such that it is formatted properly.
Finally make the problem a minimal working code example, as described in:
https://fenicsproject.discourse.group/t/read-before-posting-how-do-i-get-my-question-answered/21/3
For your particular example, the following is a minimal working code example:

from dolfin import *
mesh = UnitSquareMesh(10, 10)
V = VectorFunctionSpace(mesh, "CG", 1)
u = project(Expression(("x[0]","x[1]"),degree=1), V)

# Note that the gradient is in a DG space of one degree lower than the original space
T = TensorFunctionSpace(mesh, "DG", 0)
gradu = project(grad(u), T)
print(gradu.vector().get_local())
2 Likes