This paper addresses structures of state space in quasiperiodically forced dynamical systems. We develop a theory of ergodic partition of state space in a class of measurepreserving and dissipative flows, which is a natural extension of the existing theory for measure-preserving maps. The ergodic partition result is based on eigenspace at eigenvalue 0 of the associated Koopman operator, which is realized via time-averages of observables, and provides a constructive way to visualize a low-dimensional slice through a high-dimensional invariant set. We apply the result to the systems with a finite number of attractors and show that the time-average of a continuous observable is well-defined and reveals the invariant sets, namely, a finite number of basins of attraction. We provide a characterization of invariant sets in the quasiperiodically forced systems. A theorem on uniform boundedness of the invariant sets is proved. The series of analytical results enables numerical analysis of invariant sets in the quasiperiodically forced systems based on the ergodic partition and time-averages. Using this, we analyze a nonlinear model of complex power grids that represents the short-term swing instability, named the coherent swing instability. We show that our analytical results can be used to understand stability regions in such complex systems.