gradS, gradP and pie calculations added