When does gradient flow not converge?
I've been thinking about gradient flows in the context of Morse theory, where we take a differentiable-enough function $f$ on some space (for now let's say a compact Riemannian manifold $M$) and use the trajectories of the gradient flow $x'(t) = - \operatorname{grad} f(x(t))$ to analyse the space. In particular the (un)stable manifolds $$W^\pm(p) = \{ x \in M | x \to p \textrm{ under gradient flow as } t \to \pm \infty\}$$of critical points $p$ must fill up the whole space, which means that the gradient flow from each point must converge to a critical point of $f$.
Most references (I've been using Jost's Riemannian Geometry and Geometric Analysis) simply claim that when $f$ is Morse (has non-degenerate Hessian at all critical points) the gradient flow always converges and then move on, without any discussion of what can go wrong in the degenerate cases. For the purposes of Morse theory this is no problem (since there are a wealth of Morse functions anyway), but I'm curious about what the counterexamples look like.
I have no trouble proving that the flow converges in the Morse case, but I've had trouble finding an example of a function and an initial point for which the flow does not converge. In such a case the flow would necessarily be asymptotic to some subset of the critical set of $f$, just not necessarily to a single critical point. I discussed this with someone a while ago and was told that the flow would always converge in the real-analytic category, so any local examples would be given by non-analytic $f$. It was suggested to me that a function whose graph over a flat subset looked like an infinitely long "groove" cut out of a bump (something like with the edges of the groove smoothed out) would do the job (with the flow proceeding down the groove forever); but upon further thought it seems such a function would fail to be differentiable at the accumulation circle. (Edit: in retrospect, I think this idea does work - if the depth of the groove decayed fast enough, such a function can be differentiable, just not analytic.)
Does anyone know any non-trivial (there are the obvious examples of unbounded functions on non-compact manifolds) examples of how the a trajectory of gradient flow can fail to converge? I'm particularly interested in the simple case of compact manifolds, but anything is welcome. Necessary conditions (or sufficient conditions less restrictive than Morse) for convergence might also be interesting.
This is an adaptation (and slight correction) of the example of non-convergent geodesic heat flow found in Section 2 of http://www.math.msu.edu/~parker/ChoiParkerGeodesics.pdf.
All the details of interest take place on a closed cylinder $\left[0,\frac{1}{2}\right]\times S^{1}$, but we can use a bump function to embed the example nicely in a (compact) torus. Let $M=\mathbb{T}^{2}=\left(\mathbb{R}/2\pi\mathbb{Z}\right)^{2}$ with coordinates $u,v$ coming from the fundamental domain $[-\pi,\pi)^{2}$. Let $\eta$ be a bump function that is $1$ in $\left[-1/2,1/2\right]$ and $0$ outside $\left[-1,1\right]$. We will consider the function $$ \phi\left(u,v\right)=\begin{cases} \eta\left(u\right)e^{-1/u}\left(1+\sin\left(\frac{1}{u}-v\right)\right) & \textrm{if }u\in(0,\pi)\\ 0 & \textrm{if }u\in\left[-\pi,0\right] \end{cases} $$ which one can check is smooth on the torus. We are hoping that we can make the curve $v=\frac{1}{u}$ for $u\in\left(0,\frac{1}{2}\right)$ into a gradient flow trajectory. In this range of $u$ we can use the coordinates $\left(z,v\right)$ for $z=\frac{1}{u}-v$; so we want to find a smooth metric such that the curve $\left\{ z=0\right\} $ is a gradient flow trajectory of $\phi$. Note that in these coordinates $\phi$ takes the simple form $\phi\left(z,v\right)=1+e^{-z-v}\left(1+\sin z\right)$. Thus we have $$ d\phi=-e^{-z-v}\left(1+\sin z\right)dv+e^{-z-v}\left(\cos z-\sin z-1\right)dz; $$ so when $z=0$ we have $d\phi=-e^{-v}dv$. Thus a metric that has the form $g=f^{2}dz^{2}+dv^{2}$ ($f$ a positive smooth function) in this region would suffice, with gradient $\nabla\phi=-e^{-v}\partial_{v}$ giving non-convergent solutions for all time of the form $\left(u,v\right)\left(t\right)=\left(\frac{1}{\ln\left(c+t\right)},\ln\left(c+t\right)\right)$. In the global coordinates such a metric would have the form
$$ g=u^{-4}f^{2}du^{2}+2u^{-2}f^{2}dudv+\left(1+f^{2}\right)dv^{2} $$ in the region $u\in\left(0,\frac{1}{2}\right)$. Choosing $f=u^{2}$ we have $g=du^{2}+2u^{2}dudv+\left(1+u^{4}\right)dv^{2}$ in this region, which we can extend to a smooth non-degenerate metric on the whole torus by interpolating between it and the flat metric with $\eta$: $$ g:=du^{2}+2\eta\left(u\right)u^{2}dudv+\left(1+\eta\left(u\right)u^{4}\right)dv^{2}. $$ Since $\eta$ is $1$ on the domain of interest this does not change the gradient flow trajectory; so we have a smooth function on a compact manifold with a gradient flow trajectory $\left(u,v\right)\left(t\right)=\left(\frac{1}{\ln\left(c+t\right)},\ln\left(c+t\right)\right)$ ($c$ large enough that $1/\ln(c) < 1/2$), which has every point on the circle $\left\{ u=0\right\} $ as an accumulation point.