grid_to_index-methods function

Generic function to convert N-dimensional grid coordinates to 1D indices