Wegners method of flow equations offers a useful tool for diagonalizing a given Hamiltonian and is widely used in various branches of quantum physics. Here, generalizing this method, a condition is derived, under which the corresponding flow of a quantum state becomes geodesic in a submanifold of the projective Hilbert space, independently of specific initial conditions. This implies the geometric optimality of the present method as an algorithm of generating stationary states. The result is illustrated by analyzing some physical examples.