Getting Electric field of a mesh in order as a pvd file

Hi I am using the old version of legacy dolfin. I have a vector field in a vector function space. I did V = VectorFunctionSpace(self.geometry.mesh,‘DG’,0)
self.phi = Function(self.geometry.funcspace[‘scalar’])
grad_phi = project(-grad(self.phi), V,solver_type=“cg”, preconditioner_type=“amg”)
grad_x,grad_y,grad_z = grad_phi.split(deepcopy=True)
vtkfile = File(‘electric_field_gradphi.pvd’)
vtkfile << grad_phi
to get the pvd file for the field but I am not getting the electric field in order, the electric field is random, which I am guessing is due to the projection. I wanted to know how I can get the electric field in order of the mesh so that when I extract the pvd file. I could get the vector field in order when doing the following
E = Function(V)
and then Iterating through each cell in the mesh and mid_pt = cell.midpoint()
vector_mpt = E(mid_pt)
How can I get the same into a PVD file?

Without a minimal reproducible example and properly formatted code, Ref
Block code formatting at Discourse Guide: Code Formatting - Meta - Stonehearth Discourse