Morse theory for compact sets bounded by hypersurfaces in euclidian space I am having trouble understanding precisely how some part of Morse Theory works.
More precisely, take $X$ to be a compact set of $\mathbb{R}^d$ such that $\partial X$ (topological boundary) is a hypersurface, and let $f: \mathbb{R}^d \to \mathbb{R}$ be a Morse function. Intuitively, I should be able to define the critical points of $f$ restricted to $X$ as the points of $\partial X$ where the gradient of $f$ is proportional to the normal vector to $\partial X$.
For example, one can think of a filled doughnut, whose boundary is a torus, and $f$ to be a height function.

Yet everything does not seem to work as smoothly as in basic Morse Theory (where $f : M \to \mathbb{R}$ is morse and $M$ a manifold), where one can simply follow the flow of the morse function when there's no critical point; or contract the paraboloid offered by the non-degenerate hessians around a critical point.
Do you get how this works ?
The only reference I could find about such a case was Morse & Cairns, Critical Point Theory (1969) which I have found very difficult to read for modern eyes.
Thank you !
 A: For manifolds with boundary Morse theory works analogously to the "no boundary" case.   As Kevin states, you also consider the critical points of the function restricted to the boundary.  But these have two types.
a) The gradient of $f$ (at a boundary point) is "inward pointing" in $M$
b) The gradient of $f$ is "outward pointing" in $M$.
If you build your cell structure by flowing along the negative of the gradient of $f$, by design on the boundary it will either need to be the flow of $-\nabla f_{|\partial}$ or $-\nabla f$ depending on whether or not $-\nabla f$ points out or in, respectively.  So your cells will correspond to the critical points of $f$ in the interior, and the "outward pointing" critical points of $f_{|\partial M}$ on the boundary.
In particular this only gives you a $C^0$ flow, or perhaps it is better described as a piecewise $C^k$ flow where $k$ is the degree of smoothness of your manifold and function, respectively.
There are a few references for this kind of material but the most comprehensive tend to be restricted to people's M.Sc or Ph.D thesis, i.e. I'm not aware of a good textbook reference for this.  Perhaps because it is a fairly straightforward adaptation of the standard Morse theory.
A standard exercise to get familiar with this theory is to observe that the Wirthinger presentation of knot exteriors comes from the above Morse decomposition, applied to the (compact) knot exterior, using the linear height function "distance from the diagram plane".
