Solution (source code)

= Solution

Assume a hydrostatic, vertically well-mixed, inviscid shallow layer, negligible ambient horizontal velocity, and uniform channel width. Volume, mass, and horizontal momentum balances are
$$
h_t+(hu)_x=w_e-w_d,
$$
$$
(\rho_1h)_t+(\rho_1hu)_x=\rho_2w_e-\rho_1w_d,
$$
$$
(\rho_1hu)_t+\left(\rho_1hu^2+\frac12g(\rho_1-\rho_2)h^2\right)_x=-\rho_1u\,w_d.
$$
Combining the first two gives
$$
h(\rho_{1t}+u\rho_{1x})=(\rho_2-\rho_1)w_e.
$$
Detrainment removes fluid with the layer's own density and velocity, so it cancels from the corresponding material density and velocity equations; entrainment dilutes and exerts a momentum load.