The file getfem/getfem_derivatives.h defines the following function to compute the gradient of a solution:
getfem::compute_gradient(mf1, mf2, U, V);
where mf1 is a variable of type mesh_fem and describes the finite element method on which the solution is defined, mf2 describes the finite element method to compute the gradient, U is a vector representing the solution and should be of size mf1.nb_dof(), V is the vector on which the gradient will be computed and should be of size N * mf2.nb_dof(), with N the dimension of the domain.