Accessing the divergence of the vector field

I can acces the scalar field pnew but I cannot access the divergence of the vector field unew by the following code.

pnew.vector()[i]
(div(unew)).vector()[i]

First one works but the second one doesn’t. I get the following error:
AttributeError: ‘Div’ object has no attribute ‘vector’

What should I use for the second one?

You need to project the divergence into a suitable function space. (like a DG-0 or DG-1 space).