I have question about L^2 projection in fenics… specifically if I have solution vector u to pde, I can get gradients by using commands

V_vec = VectorFunctionSpace(mesh, "CG",1)
gradu = project(grad(u),V_vec)

however, I have a doubt… when we make ‘grad(u)’, what function space does ‘grad(u)’ live in? Why is necessary to project onto space given by ‘V_vec = VectorFunctionSpace(mesh, “CG”,1)’?

If u is a scalar, is necessary the V_vec is a space of vectors. Apart from that, it’s up to you to choose "CG", 1, or any other space which you may deem appropriate.