Fixed gradient descent to take into account of periodic boundaries