Add grid_shape pre/postcondition checks.

This PR adds the checks we want on `grid_shape`.

Closes #406