Writing deformation / gradient in paraview

Hello !

I want to visualise the gradient and deformation tensors in paraview. I manage to visualise the displacement field. However, the gradient and deformation don’t seem to be correct (I notice changes in displacement that are not reproduced in the gradient field)

This is how I create the functions:

#write displacement in Paraview
u_function.name = “Displacement”
xdmf.write_function(u_function,0)

Tensorspace = TensorFunctionSpace(domain, (“Lagrange”, 1))
g_function = Function(Tensorspace)

g_exp = Expression(grad(u_function), Tensorspace.element.interpolation_points())
g_function.interpolate(g_exp)

#write gradient in Paraview
g_function.name = “Gradient”
xdmf.write_function(g_function,0)

is there something I am missing in the interpolation ?

Thank you,

Assuming that your function u_function is a Lagrange function, the gradient of it is a DG-0 function, not a P1 function. Thus the interpolation of the gradient is not well defined. Please use a tensor DG-0 space.

Also note that without a minimal reproducible example it is hard to give you further guidance. Please see: Read before posting: How do I get my question answered?