Change memory allocation in gradient and energy arrays. Non-working version.