Solution (source code)

= Solution

Let $\boldsymbol U=(u,v)$, $\zeta=v_x-u_y$ and $D/Dt=\partial_t+\boldsymbol U\cdot\nabla$. The inviscid <shallow water equations> are
$$
\frac{D\boldsymbol U}{Dt}+f\hat{\boldsymbol z}\times\boldsymbol U=-g\nabla(h+H),\qquad \frac{Dh}{Dt}=-h\nabla\cdot\boldsymbol U.
$$
Taking the vertical curl of the momentum equation, with constant $f$, gives $D\zeta/Dt=-(f+\zeta)\nabla\cdot\boldsymbol U$. Combining this with the depth equation proves
$$
\boxed{P=\frac{f+\zeta}{h},\qquad \frac{DP}{Dt}=0.}
$$
Thus <shallow-water potential vorticity> is materially conserved: changes in <absolute vorticity> are exactly compensated by stretching or compression of the layer depth.

The relation to a <Bernoulli function> presupposes <steady flow>. In that case define $B=g(h+H)+\tfrac12|\boldsymbol U|^2$. The vector identity $(\boldsymbol U\cdot\nabla)\boldsymbol U=\nabla(\tfrac12|\boldsymbol U|^2)+\zeta\hat{\boldsymbol z}\times\boldsymbol U$ gives
$$
\nabla B=-(f+\zeta)\hat{\boldsymbol z}\times\boldsymbol U.
$$
Steady <volume conservation> allows a transport <stream function> with $h\boldsymbol U=(\psi_y,-\psi_x)$. Hence $\hat{\boldsymbol z}\times(h\boldsymbol U)=\nabla\psi$, so
$$
\nabla B=-P\nabla\psi,\qquad \boxed{\frac{dB}{d\psi}=-P.}
$$
In particular, $\boldsymbol U\cdot\nabla B=0$: the <Bernoulli function> is constant along each <streamline>. Where the flow permits a single-valued dependence on the <stream function>, the displayed derivative describes how that constant changes between neighbouring <streamlines>. For an unsteady flow, <shallow-water potential vorticity> remains conserved but the stated steady <Bernoulli function> relation does not generally hold.