Calculating gradient from mesh

Hi, I m new to fenics, I wanted to know if it is possible to generate electric field (gradient from electric potential). I have the values for electric potential generated at each voxel or tetrahedron inside the mesh. I want to find the electric field at each tetrahedra. I am confused about how to do it as the tetrahedrons are not equal. I found the function hmin() which can be used in the case of uniform mesh which cannot be used here.

See:

This works for old fenics versions as well or just in dolfinx

In legacy DOLFIN you would have to project the quantity (grad(u)) into an appropriate function space instead of interpolating it as in DOLFINx. Please note that we advice all new users to use DOLFINx: The new DOLFINx solver is now recommended over DOLFIN