import numpy as np
import matplotlib.pyplot as plt
%matplotlib notebook
Consider flow over an isolated obstacle in a channel, as in class. Assume that the obstacle is a triangle, with height off a flat channel of $h_m = 10\ \mathrm{m}$, and that the triangle's ramp has a slope of 1/100. Assume that the incoming two-d flow transport is a fixed $30\ \mathrm{m^2\,s^{-1}}$, that the flow is in steady state, and that the flow is controlled at the crest.
What is the thickness of the water column, $d_0$, far upstream of the obstacle? (OK to use a root finder and give a numeric answer)
# Soe variables:
hm = 10 # m
q = 30 # m^2/s
g = 9.8
dhdx = 0.01 # i.e the bump is 1000 m long, 10 m hight
If transcritical then $$ \frac{1}{2} F_0^2 + 1 -\frac{3}{2}F_0^{2/3} = \frac{h_m}{d_0}$$
or in terms of $q$ we get a cubic for $d_o$:
$$d_0^3 - \left(\frac{3}{2}\frac{q^{2/3}}{g^{1/3}} - h_m\right) d_0^2 + \frac{q^2}{2g} = 0 $$coef = [1., -3/2*q**(2/3)/g**(1/3) - hm, 0, q**2/2/g]
roots = np.roots(coef)
print(roots)
print(q**2/g/roots**3)
d0 = max(roots)
print('d0 = ',d0, 'm')
Note that there are two positive roots to this equation: one is for very thin very fast flow that is just transcritical, and one is for very thick slow flow. Lets choose the latter.
So $d_0 = 16.6 \ \mathrm{m}$
Knowing the height far upstream you can numerically integrate in x (or calculate the cubic at each point in x) to get the water thickness $d(x)$ as a function of $x$. Plot the water thickness as a function of $x$ from $x=-1000 m$ (upstream) to $x=0\ \mathrm{m}$ (the crest). Check that $F_m = 1$ in your calculation. For precision, make sure that you have a data point every 10 cm or so; include your code, and the expressions you used to get the interface heights. Make the plot as nice as possible (including the obstacle, helps.
Now lets integrate:
$$ \frac{\partial d}{\partial x} = \left(F^2 - 1 \right)^{-1}\frac{\partial h}{\partial x}$$dx = 0.01
x = np.linspace(-1000.,0., int(1000/dx))
# init array
d = 0. * x
Fsq = 0. * x
h = 0. * x
d[0] = d0
Fsq[0] = q**2 / g / d0**3
h[0] = 0
for i in range(1,len(x)):
d[i] = dhdx/(Fsq[i-1] - 1)*dx + d[i-1]
Fsq[i] = q**2 / g / d[i]**3
h[i] = dhdx * dx + h[i-1]
u = np.sqrt(Fsq*g*d)
print(h[-1])
um = (g*q)**(1/3)
print('u', u[-1], um)
dm = q / um
print('dm', d[-1], dm)
fig,ax = plt.subplots()
ax.plot(x, Fsq, label='$F^2$')
ax.plot(x, h, label='h')
ax.plot(x, h+d, label='h+d')
ax.set_xlabel('X [m]')
ax.set_ylabel('z [m]')
ax.legend()
print(Fsq[-1])
Knowing the water thickness as a function of $x$, use the Momentum Theorem to numerically demonstrate that the momentum balance is satisfied.
Evaluating the momentum theorem for this volume we get that the net flux of moentum is equal to the net forces on the volume:
$$ u_0^2d_0 + \frac{g}{2}d_0^2 - u_m^2 d_m - \frac{g}{2} d_m^2 - g \frac{dh}{dx}\int_0^L d \ \mathrm{dx} = 0$$where the last term is due to the form drag of the ramp.
print(u[-1]**2 * d[-1])
print(g/2*d[0]**2 )
print(g/2*d[-1]**2 )
print('LHS:')
print(u[0]**2 * d[0] + g/2 * d[0]**2 - u[-1]**2 * d[-1] - g/2 * d[-1]**2)
print('RHS:')
print(g*dhdx*np.trapz(d, x))
So the left hand and right hand sides are equal, so the momentum theorem is satisfied.