The fluid is incompressible and has no sources inside. This means that the continuity (mass conservation) equation is
$$
\text{div}\,\vec{v} = 0. \qquad (1)
$$
Now we follow the standard procedure and represent $\vec{v}$ as follows:
$$
\vec{v} = \text{rot}\,\vec{A}.
$$
The divergence of any curl is zero so equation (1) is satisfied by any smooth vector field $\vec{A}(\vec{r})$.
For 2-dimensional flow we can assume
$$
\vec{A} = \Bigl(0, 0, \psi(x,y)\Bigr)
$$
so that
$$
v_x = \frac{\partial \psi}{\partial y}; \quad v_y = -\frac{\partial \psi}{\partial x}. \qquad (2)
$$
In fluid dynamics $\psi(x,y)$ is called stream function because the lines of constant $\psi$ are the streamlines.
We have two known stream lines:
$$
y = h(x)
$$
and
$$
y = 0.
$$
Let's select the stream function as follows:
$$
\psi(x,y) = C\frac{y}{h(x)}. (3)
$$
For the upper streamline we have $\psi=C$ and for the lower line $\psi=0$. This is a strong assumption and the main point of the solution. The selection of $\psi$ is not definite here. Formula (3) is intuitive, it gives streamlines that are similar to $h(x)$ but coming more straight while approaching to the bottom.
Now we can use (2) and (3) to find $\vec{v}$:
$$
\vec{v}(x,y) = \left(\frac{C}{h(x)},\; Cy\frac{h'(x)}{h^2(x)}\right) \qquad (4)
$$
where $C$ is some constant determined by the boundary conditions.
The velocity field depends on the unknown function $h(x)$.
Finding $h(x)$
Function $h(x)$ can be found by applying the Bernoulli equation to the top streamline. Bernoulli equation for incompressible fluid is
$$
\frac{v^2\bigl(x, y(x)\bigr)}{2} + \frac{p\bigl(x, y(x)\bigr)}{\rho} + gy(x) = \text{const}
$$
where
$y(x)$ is the streamline,
$p(x,y)$ is the pressure,
$\rho$ is the density of the fluid,
$g$ is the gravitational acceleration.
The upper streamline $y(x)=h(x)$ is in the equilibrium with the atmosphere air. This means that the pressure of the fluid is equal to the atmosphere pressure:
$$
p\bigl(x, y(x)\bigr) = p_0.
$$
So
$$
\frac{v^2\bigl(x, h(x)\bigr)}{2} + gh(x) = \text{const} - \frac{p_0}{\rho} = D \qquad (5)
$$
Substitution of (4) into (5) gives the differential equation for $h(x)$:
$$
\frac{C^2}{2h^2}\left(1 + h'^2\right) + gh = D
$$
or
$$
\frac{dh}{dx} = \sqrt{\frac{2h^2}{C^2}(D-gh) - 1}
$$
$$
h(x_1) = h_1
$$
This can be solved numerically if we know $C$ and $D$.
Finding $C$ and $D$
The parameters $C$ and $D$ are determined by the boundary conditions. If we know the velocity at the point $(x_1, h_1)$ then
from (4):
$$
C = h_1 v_x(x_1, h_1)
$$
and from (5):
$$
D = \frac{v^2(x_1, h_1)}{2} + gh_1
$$
Conclusion
There are two weak points in this solution:
- the intuitive assumption (3);
- the undefined constants $C$ and $D$.
Some boundary conditions can violate (3) and/or make calculation of $C$ and $D$ very difficult.
Alternative
There is another way to select the stream function.
If we suppose the flow to be potential the velocity field will have the following form:
$$
\vec{v} = \nabla \varphi
$$
where $\varphi(x,y)$ is the potential of the velocity vector field.
Then in addition to (2) we will have:
$$
v_x = \frac{\partial \varphi}{\partial x}; \quad v_y = \frac{\partial \varphi}{\partial y}. \qquad (6)
$$
Now we can introduce the complex potential of the flow:
$$
W(x+iy) = \varphi(x,y) + i \psi(x,y)
$$
The formulas (2) and (6) together are exactly the Cauchy-Riemann conditions for the function $W(z)$. This means that $W(z)$ describes some conformal map.
If we find a conformal map $W(z)$ that turns some rectangle into the blue area in the picture in the question for any $h(x)$, then we find a potential flow (flow with zero vorticity) that solves the problem. Some manipulations will still be required to find $h(x)$.
In fact any $W(z)$ always turns 2-dimensional potential flow with
$$
\varphi(x,y) = x
$$
$$
\psi(x,y) = y
$$
and
$$
\vec{v} = (v_x, 0)
$$
into something more interesting and still fitting the hydrodynamics equations. This works only for potential flows that are not always a good approximation.
Finding of $W(z)$ in this case is a mathematical problem and perhaps should be discussed somewhere else.
The pressure on each side of the pipe is given by $P = \rho g h$ where $\rho$ is the density, $g$ is the acceleration due to gravity and $h$ is the depth of the pipe.
From the Euler equations of motion in 1D and steady state, we have:
$$ \frac{1}{2}\frac{d u^2}{d x} = - \frac{1}{\rho} \frac{dP}{dx}$$
If we make some more assumptions, namely that the pipe is full of seawater (which makes sense in the steady state because the water will flow from the sea to the lake) and that the pressure at the fresh water end is constant (so we ignore dilution/mixing, the sea water just instantly drops under the fresh), and we integrate from $x = 0$ at the sea end to $x = L$ at the fresh end:
$$ u^2 |_0^L = - 2\frac{1}{\rho} P|_0^L$$
and taking the velocity to be zero at $x = 0$ gives:
$$ u(L)^2 = -2\frac{1}{\rho_s}(P(L)-P(0))$$
$$ u(L)^2 = -2\frac{1}{\rho_s}(\rho_f g h - \rho_s g h)$$
Taking $\rho_s = 1020 \text{kg}/\text{m}^3$ and $\rho_f = 1000 \text{kg}/\text{m}^3$ with $g = 9.8 \text{m}/\text{s}^2$ yields:
$$ u(L)^2 = 0.0961h $$
or
$$ u(L) \approx 0.31h^{1/2}$$
Obviously this makes some pretty big assumptions. No viscosity, which is probably not that bad of an assumption unless your pipe is really deep, and the pressure on the fresh water end is constant implying the salt water just "disappears" by dropping very quickly out of the pipe under the fresh water.
Why does the length of the pipe matter
It doesn't actually. You'll notice $L$ doesn't appear anywhere in the expression. The velocity at the end of a mile long pipe or a 1 inch long pipe is the same and given by that expression.
What is the significance of $h^{1/2}$
Again, there really isn't any significance. The units of pressure/density are $\text{m}^2/\text{s}^2$ which is what RHS of $ u(L)^2 = 0.0961h $ is. So the units on the 0.0961 are $\text{m}/\text{s}^2$ and $h$ is $\text{m}$. So when you take the square root of both sides to get into $\text{m}/\text{s}$, you end up with the $h^{1/2}$.
So the significance is really just that there is a non-linear relationship between velocity and the depth of the pipe. If you put your pipe four times deeper, you'll only get twice the velocity.
Best Answer
I beg to differ with Chester Miller's answer.
You have not stated the cause of density variation. If it is a laboratory scale setup, density variation due to variation in pressure may be neglected (i.e. the fluid may be assumed to be incompressible). The density variation must then be due to some other factor, such as for example due to variation in salinity.
To get the appropriate form of the Bernoulli equation for your case, we must derive it from scratch, beginning with the Navier-Stokes equation. For an incompressible, inviscid, steady flow, the Navier-Stokes equation is: $$\mathbf{u}\cdot\nabla\mathbf{u}=-\frac{1}{\rho}\nabla p+\mathbf{g}$$ in which $\mathbf{u}$ is the velocity of the fluid (bold-face font is used to denote vectors), $p$ is pressure, $\rho$ is fluid density which varies with position in the fluid, $\mathbf{g}$ is the gravitational acceleration vector, and "$\cdot$" is the scalar dot-product.
Now we can write $\mathbf{u}\cdot\nabla\mathbf{u}=\nabla(u^2/2)-\mathbf{u}\times\mathbf{\omega}$, where $u=|\mathbf{u}|$ and $\omega=\nabla\times\mathbf{u}$ is the vorticity vector; this and subsequent results may be easily proved using indicial notation, which I leave to you (or refer Fluid Dynamics by Batchelor, Chapter 3). Further, $\mathbf{g}=\nabla(\mathbf{g}\cdot\mathbf{x})$, in which $\mathbf{x}$ is the position vector from some arbitrarily chosen origin. Substituting these into the previous equation and rearranging we get: $$\nabla\left( \frac{1}{2}u^2-\mathbf{g}\cdot\mathbf{x} \right)+\frac{1}{\rho}\nabla p=\mathbf{u}\times\mathbf{\omega}$$ Since $\rho$ varies with position it cannot simply be pulled inside the $\nabla$ operator.
There are two ways to simplify the equation above. Either you assume that the flow is irrotational, i.e. $\omega=0$ everywhere. Or you integrate above equation along a streamline. The former is the simplest assumption to make, but it is difficult to justify physically; even though it may have begun as irrotational flow because it was initially at rest say, it may not remain irrotational because it is not a barotropic fluid (Kelvin's circulation theorem does not apply). Therefore we do the next best thing, which is to integrate along a streamline.
A streamline is a curve which is tangent to fluid velocity everywhere. Pick a streamline which begins at the free surface and passes through the exit hole. Let $\mathbf{t}$ be a unit tangent vector to that streamline; then by definition of the streamline, $\mathbf{t}\times\mathbf{u}=0$ at every point on the streamline. Therefore $\mathbf{t}\cdot(\mathbf{u}\times\omega)=0$ at every point on the streamline. Forming the scalar product with $\mathbf{t}$ of the previous equation gives: $$\mathbf{t}\cdot\nabla\left( \frac{1}{2}u^2-\mathbf{g}\cdot\mathbf{x} \right)+\frac{1}{\rho}\mathbf{t}\cdot\nabla p=0\\ \frac{d}{ds}\left( \frac{1}{2}u^2-\mathbf{g}\cdot\mathbf{x} \right)+\frac{1}{\rho}\frac{dp}{ds}=0$$ in which $s$ is the parameter of the streamline-curve (for example, $s$ could be distance along the streamline), whose value varies monotonically from $s_1$ at the free surface to $s_2$ at the exit hole.
Next we integrate the equation above from $s_1$ to $s_2$. i.e. we apply the operator $\int_{s_1}^{s_2}ds$. First term is easy: $$\int_{s_1}^{s_2}ds\frac{d}{ds}\left( \frac{1}{2}u^2-\mathbf{g}\cdot\mathbf{x} \right)=\left[ \frac{1}{2}u^2-\mathbf{g}\cdot\mathbf{x} \right]_{s_1}^{s_2}\\ =\frac{1}{2}(u_2^2-u_1^2)+g(z_2-z_1)=\frac{u_2^2}{2}-gh$$ in which I have chosen Z-axis to be vertically upward so that $\mathbf{g}=-g\mathbf{e}_z$, $\mathbf{e}_z$ being the unit vector along Z-axis and $g=|\mathbf{g}|$; I have also assumed that the velocity at the free surface is negligible.
If we write the absolute pressure as $p=p_{atm}+p'$, in which $p_{atm}$ is the atmospheric pressure, then $dp/ds=dp'/ds$. Also $p'=0$ at the free-surface as well as at the exit hole, because pressure is atmospheric there (neglecting surface tension effects). Then the second term may be integrated by parts: $$\int_{s_1}^{s_2}ds\frac{1}{\rho}\frac{dp}{ds}=\int_{s_1}^{s_2}ds\frac{1}{\rho}\frac{dp'}{ds}\\ =\left[ \frac{p'}{\rho}\right]_{s_1}^{s_2}+\int_{s_1}^{s_2}ds\frac{p'}{\rho^2}\frac{d\rho}{ds}\\ =\int_{s_1}^{s_2}ds\frac{p'}{\rho^2}\frac{d\rho}{ds}$$
Thus the Bernoulli equation in your case, applied between free-surface (point 1) and exit-hole (point 2), is: $$\frac{u_2^2}{2}-gh+\int_{s_1}^{s_2}ds\frac{p'}{\rho^2}\frac{d\rho}{ds}=0$$ If density is constant along the streamline then $d\rho/ds=0$, and equation above reduces to the usual form $u_2=\sqrt{2gh}$. Otherwise we have: $$u_2=\sqrt{2}\sqrt{gh+\int_{s_2}^{s_1}ds\frac{p'}{\rho^2}\frac{d\rho}{ds}}$$ where the direction of integration is now from exit-hole to free-surface. We can write $d\rho/ds=(d\rho/dz)(dz/ds)$, in which $d\rho/dz$ is known and $dz/ds$ depends on the streamline chosen. If the fluid was initially at rest, then it must be stably stratified; further if the streamline descends monotonically (as in the figure above), then $d\rho/ds>0$ everywhere along the streamline and value of $d\rho/ds$ increases from exit-hole to free-surface. The gauge pressure $p'$ inside the integral is the troublesome term, because due to presence of flow along the streamline it differs from the hydrostatic value.
Addendum Since the fluid is stratified one may object that the Navier-Stokes equation we began with doesn't account for buoyancy force on the fluid particle. In a stably stratified fluid in equilibrium the constant-density surfaces are horizontal; this means that as long as constant-density surfaces remain horizontal, a fluid particle on that horizontal plane doesn't experience buoyancy force. Buoyancy force comes into play only when constant-density surfaces are tilted or distorted. Distortion will certainly be greatest in the flow region close to the exit-hole, reducing as we move away from the exit-hole. Therefore Navier-Stokes equation we began with is invalid in the region close to the exit-hole. Presumably this region is not big enough, and our equation holds approximately along the rest of the streamline away from the exit-hole. If this is the case, then our final result may yet be a good approximation.